Ticket #3171: t3171_clear_muc_messages_v3_r16728.patch

File t3171_clear_muc_messages_v3_r16728.patch, 4.0 KB (added by elexis, 9 years ago)

Removes the g_joined variable which is not needed anymore with this patch. The removal of this variable also fixes #3287 then.

  • binaries/data/mods/public/gui/lobby/lobby.js

     
    88var g_mapSizes = {};
    99const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    1010const g_mapTypes = ["skirmish", "random", "scenario"];
    1111var g_userRating = ""; // Rating of user, defaults to Unrated
    1212var g_modPrefix = "@";
    13 var g_joined = false;
    1413// Block spammers for 30 seconds.
    1514var SPAM_BLOCK_LENGTH = 30;
    1615
    1716////////////////////////////////////////////////////////////////////////////////////////////////
    1817
     
    634633            case "join":
    635634                if (nick == g_Name)
    636635                {
    637636                    // We just joined, we need to get the full player list
    638637                    [playerList, presenceList, nickList, ratingList] = updatePlayerList();
    639                     // Don't display any joins until our join request bounces back
    640                     // Our join message should be the last one as we just got added to the stack
    641                     g_joined = true;
    642                     break;
    643638                }
    644                 else if (g_joined)
     639                else
    645640                {
    646641                    var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
    647642                    playerList.push(name);
    648643                    presenceList.push(status);
    649644                    nickList.push(nick);
  • source/lobby/IXmppClient.h

     
    5252    virtual void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
    5353    virtual void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
    5454    virtual void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
    5555
    5656    virtual void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
     57    virtual void ClearMucMessages() = 0;
    5758    virtual void SendMUCMessage(const std::string& message) = 0;
    5859};
    5960
    6061extern IXmppClient *g_XmppClient;
    6162extern bool g_rankedGame;
  • source/lobby/XmppClient.cpp

     
    492492 *
    493493 * @return A JS array containing all known players and their presences
    494494 */
    495495void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
    496496{
     497    // Clear outdated presence updates, see #3171
     498    this->ClearMucMessages();
     499
    497500    JSContext* cx = scriptInterface.GetContext();
    498501    JSAutoRequest rq(cx);
    499502   
    500503    scriptInterface.Eval("([])", ret);
    501504
     
    620623
    621624    m_GuiMessageQueue.pop_front();
    622625}
    623626
    624627/**
     628 * Remove all muc updates from the message queue.
     629 */
     630void XmppClient::ClearMucMessages()
     631{
     632    // TODO: use mutex lock here?
     633    bool clean;
     634    do
     635    {
     636        clean = true;
     637        for (std::deque<GUIMessage>::iterator it = m_GuiMessageQueue.begin(); it!=m_GuiMessageQueue.end(); ++it)
     638        {
     639            GUIMessage message = *it;
     640            if (message.type == L"muc")
     641            {
     642                m_GuiMessageQueue.erase(it);
     643                clean = false;
     644                break;
     645            }
     646        }
     647    } while (!clean);
     648}
     649
     650/**
    625651 * Send a standard MUC textual message.
    626652 */
    627653void XmppClient::SendMUCMessage(const std::string& message)
    628654{
    629655    m_mucRoom->send(message);
  • source/lobby/XmppClient.h

     
    132132        std::wstring from;
    133133        std::wstring message;
    134134        std::string datetime;
    135135    };
    136136    void GuiPollMessage(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
     137    void ClearMucMessages();
    137138    void SendMUCMessage(const std::string& message);
    138139    protected:
    139140    void PushGuiMessage(XmppClient::GUIMessage message);
    140141    void CreateSimpleMessage(const std::string& type, const std::string& text, const std::string& level = "standard", const std::string& data = "");
    141142