Ticket #3171: t3171_clear_muc_messages_v4_16789.patch

File t3171_clear_muc_messages_v4_16789.patch, 3.9 KB (added by elexis, 9 years ago)

Cleaned code by using erase-remove idiom.

  • 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
     
    701700            case "join":
    702701                if (nick == g_Name)
    703702                {
    704703                    // We just joined, we need to get the full player list
    705704                    [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;
    710705                }
    711                 else if (g_joined)
     706                else
    712707                {
    713708                    var [name, status, rating] = formatPlayerListEntry(nick, presence, "-");
    714709                    playerList.push(name);
    715710                    presenceList.push(status);
    716711                    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
     498    this->ClearMucMessages();
     499
    497500    JSContext* cx = scriptInterface.GetContext();
    498501    JSAutoRequest rq(cx);
    499502   
    500503    scriptInterface.Eval("([])", ret);
    501504
     
    619622        scriptInterface.SetProperty(ret, "datetime", message.datetime);
    620623
    621624    m_GuiMessageQueue.pop_front();
    622625}
    623626
     627bool isMucMessage(XmppClient::GUIMessage message)
     628{
     629  return message.type == L"muc";
     630}
     631
     632/**
     633 * Remove all muc updates from the message queue.
     634 */
     635void XmppClient::ClearMucMessages()
     636{
     637    m_GuiMessageQueue.erase(std::remove_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(), isMucMessage), m_GuiMessageQueue.end());
     638}
     639
    624640/**
    625641 * Send a standard MUC textual message.
    626642 */
    627643void XmppClient::SendMUCMessage(const std::string& message)
    628644{
  • 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