Ticket #3171: t3171_clear_muc_messages_v6_16795.patch

File t3171_clear_muc_messages_v6_16795.patch, 4.5 KB (added by elexis, 9 years ago)

Moved the g_joined variable and functionality from JS to C++, so that its value is saved properly instead of being reset when returning from the gamesetup. Cleans code that way too.

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

     
    1212var g_mapSizes = {};
    1313const g_mapTypesText = [translateWithContext("map", "Skirmish"), translateWithContext("map", "Random"), translate("Scenario")];
    1414const g_mapTypes = ["skirmish", "random", "scenario"];
    1515var g_userRating = ""; // Rating of user, defaults to Unrated
    1616var g_modPrefix = "@";
    17 var g_joined = false;
    1817// Block spammers for 30 seconds.
    1918var SPAM_BLOCK_LENGTH = 30;
    2019
    2120////////////////////////////////////////////////////////////////////////////////////////////////
    2221
     
    697696            var ratingList = playersBox.list_rating;
    698697            var nickIndex = nickList.indexOf(nick);
    699698            switch(message.level)
    700699            {
    701700            case "join":
    702                 if (nick == g_Name)
    703                 {
    704                     // We just joined, we need to get the full player list
    705                     [playerList, presenceList, nickList, ratingList] = updatePlayerList();
    706                     // Don't display any joins until our join request bounces back
    707                     // Our join message should be the last one as we just got added to the stack
    708                     g_joined = true;
    709                     break;
    710                 }
    711                 else if (g_joined)
    712                 {
    713                     var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
    714                     playerList.push(name);
    715                     presenceList.push(status);
    716                     nickList.push(nick);
    717                     ratingList.push(String(rating));
    718                     Engine.SendGetRatingList();
    719                     addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { nick: nick }), "key": g_specialKey });
    720                 }
     701                var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
     702                playerList.push(name);
     703                presenceList.push(status);
     704                nickList.push(nick);
     705                ratingList.push(String(rating));
     706                Engine.SendGetRatingList();
     707                addChatMessage({ "text": "/special " + sprintf(translate("%(nick)s has joined."), { nick: nick }), "key": g_specialKey });
    721708                break;
    722709            case "leave":
    723710                if (nickIndex == -1) // Left, but not present (TODO: warn about this?)
    724711                    break;
    725712                playerList.splice(nickIndex, 1);
  • source/lobby/XmppClient.cpp

     
    7777
    7878    m_xpartamuppId = sXpartamupp + "@" + sServer + "/CC";
    7979    glooxwrapper::JID clientJid(sUsername + "@" + sServer + "/0ad");
    8080    glooxwrapper::JID roomJid(sRoom + "@conference." + sServer + "/" + sNick);
    8181
     82    m_bouncedBack = false;
     83
    8284    // If we are connecting, use the full jid and a password
    8385    // If we are registering, only use the server name
    8486    if(!regOpt)
    8587        m_client = new glooxwrapper::Client(clientJid, sPassword);
    8688    else
     
    492494 *
    493495 * @return A JS array containing all known players and their presences
    494496 */
    495497void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
    496498{
     499    // Clear outdated presence updates
     500    std::remove_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(),
     501        [](XmppClient::GUIMessage& message)
     502        {
     503            return message.type == L"muc";
     504        }
     505    );
     506
    497507    JSContext* cx = scriptInterface.GetContext();
    498508    JSAutoRequest rq(cx);
    499509   
    500510    scriptInterface.Eval("([])", ret);
    501511
     
    800810        m_PlayerMap.erase(nick);
    801811    }
    802812    else
    803813    {
    804814        if (m_PlayerMap.find(nick) == m_PlayerMap.end())
    805             CreateSimpleMessage("muc", nick, "join");
     815        {
     816            if (nick == m_mucRoom->nick().to_string())
     817                m_bouncedBack = true;
     818
     819            // Don't display any joins until our join request bounces back
     820            if (m_bouncedBack)
     821                CreateSimpleMessage("muc", nick, "join");
     822        }
    806823        else
    807824            CreateSimpleMessage("muc", nick, "presence");
    808825
    809826        DbgXMPP(nick << " is in the room, presence : " << (int)presenceType);
    810827        m_PlayerMap[nick].resize(3);
  • source/lobby/XmppClient.h

     
    138138    protected:
    139139    void PushGuiMessage(XmppClient::GUIMessage message);
    140140    void CreateSimpleMessage(const std::string& type, const std::string& text, const std::string& level = "standard", const std::string& data = "");
    141141
    142142private:
     143    // Whether or not we have successfully joined the lobby
     144    bool m_bouncedBack;
    143145    /// Map of players
    144146    std::map<std::string, std::vector<std::string> > m_PlayerMap;
    145147    /// List of games
    146148    std::vector<const glooxwrapper::Tag*> m_GameList;
    147149    /// List of rankings