Ticket #3171: t3171_clear_muc_messages_v2_a18.patch

File t3171_clear_muc_messages_v2_a18.patch, 2.6 KB (added by elexis, 9 years ago)

Same patch but compatible to a18. Having a playerlist that works also has the advantage that it is alphabetically sorted, so that you can find a specific player easier.

  • 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
     
    618621   
    619622    m_GuiMessageQueue.pop_front();
    620623}
    621624
    622625/**
     626 * Remove all muc updates from the message queue.
     627 */
     628void XmppClient::ClearMucMessages()
     629{
     630    // TODO: use mutex lock here?
     631    bool clean;
     632    do
     633    {
     634        clean = true;
     635        for (std::deque<GUIMessage>::iterator it = m_GuiMessageQueue.begin(); it!=m_GuiMessageQueue.end(); ++it)
     636        {
     637            GUIMessage message = *it;
     638            if (message.type == L"muc")
     639            {
     640                m_GuiMessageQueue.erase(it);
     641                clean = false;
     642                break;
     643            }
     644        }
     645    } while (!clean);
     646}
     647
     648/**
    623649 * Send a standard MUC textual message.
    624650 */
    625651void XmppClient::SendMUCMessage(const std::string& message)
    626652{
    627653    m_mucRoom->send(message);
  • source/lobby/XmppClient.h

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