Index: ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js +++ ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js @@ -111,20 +111,19 @@ var g_Kicked = false; /** - * Notifications sent by XmppClient.cpp + * Processing of notifications sent by XmppClient.cpp. + * + * @returns true if the playerlist GUI must be updated. */ var g_NetMessageTypes = { "system": { // Three cases are handled in prelobby.js - "registered": msg => { - }, - "connected": msg => { - }, + "registered": msg => false, + "connected": msg => false, "disconnected": msg => { updateGameList(); updateLeaderboard(); - updatePlayerList(); Engine.GetGUIObjectByName("chatInput").hidden = true; @@ -138,6 +137,7 @@ "time": msg.time, "text": translate("Disconnected.") + " " + msg.text }); + return true; }, "error": msg => { addChatMessage({ @@ -145,11 +145,13 @@ "time": msg.time, "text": msg.text }); + return false; } }, "chat": { "subject": msg => { updateSubject(msg.text); + return false; }, "join": msg => { addChatMessage({ @@ -159,6 +161,7 @@ "time": msg.time, "isSpecial": true }); + return true; }, "leave": msg => { addChatMessage({ @@ -171,9 +174,10 @@ if (msg.text == g_Username) Engine.DisconnectXmppClient(); + + return true; }, - "presence": msg => { - }, + "presence": msg => true, "role": msg => { Engine.GetGUIObjectByName("chatInput").hidden = Engine.LobbyGetPlayerRole(g_Username) == "visitor"; @@ -204,6 +208,8 @@ if (g_SelectedPlayer == msg.text) updateUserRoleText(g_SelectedPlayer); + + return false; }, "nick": msg => { addChatMessage({ @@ -214,12 +220,15 @@ "time": msg.time, "isSpecial": true }); + return true; }, "kicked": msg => { handleKick(false, msg.text, msg.data || "", msg.time); + return true; }, "banned": msg => { handleKick(true, msg.text, msg.data || "", msg.time); + return true; }, "room-message": msg => { addChatMessage({ @@ -227,6 +236,7 @@ "text": escapeText(msg.text), "time": msg.time }); + return false; }, "private-message": msg => { // Announcements and the Message of the Day are sent by the server directly @@ -246,13 +256,25 @@ "time": msg.time, "private" : true }); + return false; } }, "game": { - "gamelist": msg => updateGameList(), - "profile": msg => updateProfile(), - "leaderboard": msg => updateLeaderboard(), - "ratinglist": msg => updatePlayerList() + "gamelist": msg => { + updateGameList(); + return false; + }, + "profile": msg => { + updateProfile(); + return false; + }, + "leaderboard": msg => { + updateLeaderboard(); + return false; + }, + "ratinglist": msg => { + return true; + } } }; @@ -1137,6 +1159,8 @@ { updateTimers(); + let updateList = false; + while (true) { let msg = Engine.LobbyGuiPollMessage(); @@ -1153,13 +1177,15 @@ warn("Unrecognised message level: " + msg.level); continue; } - g_NetMessageTypes[msg.type][msg.level](msg); - // To improve performance, only update the playerlist GUI when - // the last update in the current stack is processed - if (msg.type == "chat" && Engine.LobbyGetMucMessageCount() == 0) - updatePlayerList(); + if (g_NetMessageTypes[msg.type][msg.level](msg)) + updateList = true; } + + // To improve performance, only update the playerlist GUI when + // the last update in the current stack is processed + if (updateList) + updatePlayerList(); } /** Index: ps/trunk/source/lobby/IXmppClient.h =================================================================== --- ps/trunk/source/lobby/IXmppClient.h +++ ps/trunk/source/lobby/IXmppClient.h @@ -50,7 +50,6 @@ virtual void GetSubject(std::string& subject) = 0; virtual void GUIGetPlayerList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; virtual void ClearPresenceUpdates() = 0; - virtual int GetMucMessageCount() = 0; virtual void GUIGetGameList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; virtual void GUIGetBoardList(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; virtual void GUIGetProfile(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0; Index: ps/trunk/source/lobby/XmppClient.h =================================================================== --- ps/trunk/source/lobby/XmppClient.h +++ ps/trunk/source/lobby/XmppClient.h @@ -146,7 +146,6 @@ void GuiPollMessage(const ScriptInterface& scriptInterface, JS::MutableHandleValue ret); void SendMUCMessage(const std::string& message); void ClearPresenceUpdates(); - int GetMucMessageCount(); protected: void PushGuiMessage(XmppClient::GUIMessage message); void CreateGUIMessage(const std::string& type, const std::string& level, const std::string& text = "", const std::string& data = ""); Index: ps/trunk/source/lobby/XmppClient.cpp =================================================================== --- ps/trunk/source/lobby/XmppClient.cpp +++ ps/trunk/source/lobby/XmppClient.cpp @@ -614,18 +614,6 @@ } /** - * Used in order to update the GUI only once when multiple updates are queued. - */ -int XmppClient::GetMucMessageCount() -{ - return std::count_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(), - [](XmppClient::GUIMessage& message) - { - return message.type == L"chat"; - }); -} - -/** * Handle a room message. */ void XmppClient::handleMUCMessage(glooxwrapper::MUCRoom*, const glooxwrapper::Message& msg, bool priv) Index: ps/trunk/source/lobby/scripting/JSInterface_Lobby.h =================================================================== --- ps/trunk/source/lobby/scripting/JSInterface_Lobby.h +++ ps/trunk/source/lobby/scripting/JSInterface_Lobby.h @@ -44,7 +44,6 @@ void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players); JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate); void LobbyClearPresenceUpdates(ScriptInterface::CxPrivate* pCxPrivate); - int LobbyGetMucMessageCount(ScriptInterface::CxPrivate* pCxPrivate); JS::Value GetGameList(ScriptInterface::CxPrivate* pCxPrivate); JS::Value GetBoardList(ScriptInterface::CxPrivate* pCxPrivate); JS::Value GetProfile(ScriptInterface::CxPrivate* pCxPrivate); Index: ps/trunk/source/lobby/scripting/JSInterface_Lobby.cpp =================================================================== --- ps/trunk/source/lobby/scripting/JSInterface_Lobby.cpp +++ ps/trunk/source/lobby/scripting/JSInterface_Lobby.cpp @@ -47,7 +47,6 @@ scriptInterface.RegisterFunction("SendChangeStateGame"); scriptInterface.RegisterFunction("GetPlayerList"); scriptInterface.RegisterFunction("LobbyClearPresenceUpdates"); - scriptInterface.RegisterFunction("LobbyGetMucMessageCount"); scriptInterface.RegisterFunction("GetGameList"); scriptInterface.RegisterFunction("GetBoardList"); scriptInterface.RegisterFunction("GetProfile"); @@ -184,11 +183,6 @@ g_XmppClient->ClearPresenceUpdates(); } -int JSI_Lobby::LobbyGetMucMessageCount(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) -{ - return g_XmppClient ? g_XmppClient->GetMucMessageCount() : 0; -} - JS::Value JSI_Lobby::GetGameList(ScriptInterface::CxPrivate* pCxPrivate) { if (!g_XmppClient)