mirror of https://gitlab.com/litecord/litecord.git
blueprints.users: dispatch USER_UPDATE to guilds and friends
- dispatcher: add EventDispatcher.dispatch_many
This commit is contained in:
parent
a62bc5af46
commit
3d96ccda35
|
|
@ -189,10 +189,23 @@ async def patch_me():
|
|||
WHERE id = $2
|
||||
""", new_hash, user_id)
|
||||
|
||||
# TODO: dispatch USER_UPDATE to guilds and users
|
||||
user.pop('password_hash')
|
||||
await app.dispatcher.dispatch_user(
|
||||
user_id, 'USER_UPDATE', user)
|
||||
|
||||
public_user = await app.storage.get_user(user_id)
|
||||
|
||||
guild_ids = await app.storage.get_user_guilds(user_id)
|
||||
friend_ids = await app.storage.get_friend_ids(user_id)
|
||||
|
||||
await app.dispatcher.dispatch_many(
|
||||
'guild', guild_ids, 'USER_UPDATE', public_user
|
||||
)
|
||||
|
||||
await app.dispatcher.dispatch_many(
|
||||
'friend', friend_ids, 'USER_UPDATE', public_user
|
||||
)
|
||||
|
||||
return jsonify(user)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import collections
|
||||
from typing import Any
|
||||
from typing import List, Any
|
||||
|
||||
from logbook import Logger
|
||||
|
||||
|
|
@ -62,6 +62,14 @@ class EventDispatcher:
|
|||
key = backend.KEY_TYPE(key)
|
||||
return await backend.dispatch(key, *args, **kwargs)
|
||||
|
||||
async def dispatch_many(self, backend_str: str,
|
||||
keys: List[Any], *args, **kwargs):
|
||||
"""Dispatch to multiple keys in a single backend."""
|
||||
log.info('MULTI DISPATCH: {!r}, {} keys',
|
||||
backend_str, len(keys))
|
||||
for key in keys:
|
||||
await self.dispatch(backend_str, key, *args, **kwargs)
|
||||
|
||||
async def reset(self, backend_str: str, key: Any):
|
||||
"""Reset the bucket in the given backend."""
|
||||
backend = self.backends[backend_str]
|
||||
|
|
|
|||
Loading…
Reference in New Issue