mirror of https://gitlab.com/litecord/litecord.git
users: decouple main dispatch to mass_user_update
this should solve problems with people getting nitro and others being able to see their flag status. who knows what happens inside the offical client. - users.billing_job: use mass_user_update
This commit is contained in:
parent
2a00f8c31f
commit
b92d1302e7
|
|
@ -14,6 +14,8 @@ from litecord.snowflake import snowflake_datetime
|
||||||
from litecord.types import MINUTES, HOURS
|
from litecord.types import MINUTES, HOURS
|
||||||
from litecord.enums import UserFlags
|
from litecord.enums import UserFlags
|
||||||
|
|
||||||
|
from litecord.blueprints.users import mass_user_update
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
|
|
||||||
# how many days until a payment needs
|
# how many days until a payment needs
|
||||||
|
|
@ -130,10 +132,8 @@ async def _process_subscription(app, subscription_id: int):
|
||||||
WHERE id = $3
|
WHERE id = $3
|
||||||
""", first_payment_ts, new_flags, user_id)
|
""", first_payment_ts, new_flags, user_id)
|
||||||
|
|
||||||
user_object = await app.storage.get_user(user_id, secure=True)
|
# dispatch updated user to all possible clients
|
||||||
|
await mass_user_update(user_id, app)
|
||||||
# dispatch updated user to all clients
|
|
||||||
await app.dispatcher.dispatch_user(user_id, 'USER_UPDATE', user_object)
|
|
||||||
|
|
||||||
|
|
||||||
async def payment_job(app):
|
async def payment_job(app):
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,49 @@ from litecord.permissions import base_permissions
|
||||||
bp = Blueprint('user', __name__)
|
bp = Blueprint('user', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def mass_user_update(user_id, app_=None):
|
||||||
|
"""Dispatch USER_UPDATE in a mass way."""
|
||||||
|
if app_ is None:
|
||||||
|
app_ = app
|
||||||
|
|
||||||
|
# by using dispatch_with_filter
|
||||||
|
# we're guaranteeing all shards will get
|
||||||
|
# a USER_UPDATE once and not any others.
|
||||||
|
|
||||||
|
session_ids = []
|
||||||
|
|
||||||
|
public_user = await app_.storage.get_user(user_id)
|
||||||
|
private_user = await app_.storage.get_user(user_id, secure=True)
|
||||||
|
|
||||||
|
session_ids.extend(
|
||||||
|
await app_.dispatcher.dispatch_user(
|
||||||
|
user_id, 'USER_UPDATE', private_user)
|
||||||
|
)
|
||||||
|
|
||||||
|
guild_ids = await app_.user_storage.get_user_guilds(user_id)
|
||||||
|
friend_ids = await app_.user_storage.get_friend_ids(user_id)
|
||||||
|
|
||||||
|
session_ids.extend(
|
||||||
|
await app_.dispatcher.dispatch_many_filter_list(
|
||||||
|
'guild', guild_ids, session_ids,
|
||||||
|
'USER_UPDATE', public_user
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
session_ids.extend(
|
||||||
|
await app_.dispatcher.dispatch_many_filter_list(
|
||||||
|
'friend', friend_ids, session_ids,
|
||||||
|
'USER_UPDATE', public_user
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await app_.dispatcher.dispatch_many(
|
||||||
|
'lazy_guild', guild_ids, 'update_user', user_id
|
||||||
|
)
|
||||||
|
|
||||||
|
return private_user
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/@me', methods=['GET'])
|
@bp.route('/@me', methods=['GET'])
|
||||||
async def get_me():
|
async def get_me():
|
||||||
"""Get the current user's information."""
|
"""Get the current user's information."""
|
||||||
|
|
@ -215,39 +258,7 @@ async def patch_me():
|
||||||
|
|
||||||
user.pop('password_hash')
|
user.pop('password_hash')
|
||||||
|
|
||||||
public_user = await app.storage.get_user(user_id)
|
private_user = await mass_user_update(user_id, app)
|
||||||
private_user = await app.storage.get_user(user_id, secure=True)
|
|
||||||
session_ids = []
|
|
||||||
|
|
||||||
# by using dispatch_with_filter
|
|
||||||
# we're guaranteeing all shards will get
|
|
||||||
# a USER_UPDATE once and not any others.
|
|
||||||
session_ids.extend(
|
|
||||||
await app.dispatcher.dispatch_user(
|
|
||||||
user_id, 'USER_UPDATE', private_user)
|
|
||||||
)
|
|
||||||
|
|
||||||
guild_ids = await app.user_storage.get_user_guilds(user_id)
|
|
||||||
friend_ids = await app.user_storage.get_friend_ids(user_id)
|
|
||||||
|
|
||||||
session_ids.extend(
|
|
||||||
await app.dispatcher.dispatch_many_filter_list(
|
|
||||||
'guild', guild_ids, session_ids,
|
|
||||||
'USER_UPDATE', public_user
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
session_ids.extend(
|
|
||||||
await app.dispatcher.dispatch_many_filter_list(
|
|
||||||
'friend', friend_ids, session_ids,
|
|
||||||
'USER_UPDATE', public_user
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
await app.dispatcher.dispatch_many(
|
|
||||||
'lazy_guild', guild_ids, 'update_user', user_id
|
|
||||||
)
|
|
||||||
|
|
||||||
return jsonify(private_user)
|
return jsonify(private_user)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue