From 8b6645306a3228f345972af12a0852afb37491a8 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Fri, 25 Aug 2017 23:19:13 +0000 Subject: [PATCH] Update user chip if a user has been updated --- .../titanembeds/blueprints/gateway/gateway.py | 17 +++++++++++++++-- webapp/titanembeds/static/js/embed.js | 5 +++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/webapp/titanembeds/blueprints/gateway/gateway.py b/webapp/titanembeds/blueprints/gateway/gateway.py index 0461938..946483e 100644 --- a/webapp/titanembeds/blueprints/gateway/gateway.py +++ b/webapp/titanembeds/blueprints/gateway/gateway.py @@ -1,6 +1,6 @@ from titanembeds.utils import socketio, guild_accepts_visitors, get_client_ipaddr from titanembeds.userbookkeeping import check_user_in_guild, get_guild_channels, update_user_status -from titanembeds.database import db, GuildMembers +from titanembeds.database import db, GuildMembers, get_guild_member from flask_socketio import Namespace, emit, disconnect, join_room, leave_room import functools from flask import request, session @@ -78,4 +78,17 @@ class Gateway(Namespace): join_room("CHANNEL_"+chan["channel"]["id"]) else: leave_room("CHANNEL_"+chan["channel"]["id"]) - emit("channel_list", channels) \ No newline at end of file + emit("channel_list", channels) + + def on_current_user_info(self, data): + guild_id = data["guild_id"] + if "user_keys" in session and not session["unauthenticated"]: + dbMember = get_guild_member(guild_id, session["user_id"]) + usr = { + 'avatar': session["avatar"], + 'username': dbMember.username, + 'nickname': dbMember.nickname, + 'discriminator': dbMember.discriminator, + 'user_id': session['user_id'], + } + emit("current_user_info", usr) \ No newline at end of file diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 5f152a2..cd0644e 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -1052,6 +1052,7 @@ socket.on("GUILD_MEMBER_UPDATE", function (usr) { update_socket_channels(); + socket.emit("current_user_info", {"guild_id": guild_id}); for (var i = 0; i < discord_users_list.length; i++) { if (usr.id == discord_users_list[i].id) { discord_users_list.splice(i, 1); @@ -1116,6 +1117,10 @@ } } }); + + socket.on("current_user_info", function (usr) { + update_embed_userchip(true, usr.avatar, usr.username, usr.nickname, usr.userid, usr.discriminator); + }); } function update_socket_channels() {