Ticket #3386: t3386_clear_muc_messages_v1.patch

File t3386_clear_muc_messages_v1.patch, 10.1 KB (added by elexis, 9 years ago)

Needs testing, but should be equivalent to the muc-message-clearing patches in #3171 which were tested extensively in real situations with a18.

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

     
    172172    var playersBox = Engine.GetGUIObjectByName("playersBox");
    173173    var playerList = [];
    174174    var presenceList = [];
    175175    var nickList = [];
    176176    var ratingList = [];
    177     var cleanPlayerList = Engine.GetPlayerList();
     177    var cleanPlayerList = Engine.GetPlayerList(true);
    178178    // Sort the player list, ignoring case.
    179179    cleanPlayerList.sort(function(a,b)
    180180    {
    181181        switch (g_PlayerListSortBy)
    182182        {
  • binaries/data/mods/public/gui/lobby/lobby.xml

     
    233233
    234234            <object name="chatPanel" size="0 49% 100% 100%" type="image" sprite="ModernDarkBoxGold">
    235235                <object name="chatText" size="0 0 100% 94%" type="text" style="ChatPanel" font="sans-13"/>
    236236                <object name="chatInput" size="0 94% 100% 100%" type="input" style="ModernInput" font="sans-13">
    237237                    <action on="Press">submitChatInput();</action>
    238                     <action on="Tab">autoCompleteNick("chatInput", Engine.GetPlayerList());</action>
     238                    <action on="Tab">autoCompleteNick("chatInput", Engine.GetPlayerList(false));</action>
    239239                </object>
    240240            </object>
    241241        </object>
    242242
    243243        <!-- START Window for leaderboard stats -->
  • source/lobby/IXmppClient.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
     
    4646    virtual void SetPresence(const std::string& presence) = 0;
    4747    virtual void GetPresence(const std::string& nickname, std::string& presence) = 0;
    4848    virtual void GetRole(const std::string& nickname, std::string& role) = 0;
    4949    virtual void GetSubject(std::string& subject) = 0;
    5050
    51     virtual void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret) = 0;
     51    virtual void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret, bool clearPresenceUpdates) = 0;
    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;
  • source/lobby/XmppClient.cpp

     
    492492/**
    493493 * Handle requests from the GUI for the list of players.
    494494 *
    495495 * @return A JS array containing all known players and their presences
    496496 */
    497 void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
     497void XmppClient::GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret, bool clearPresenceUpdates)
    498498{
     499    if (clearPresenceUpdates)
     500    {
     501        m_GuiMessageQueue.erase(
     502            std::remove_if(m_GuiMessageQueue.begin(), m_GuiMessageQueue.end(),
     503                [](XmppClient::GUIMessage& message)
     504                {
     505                    return message.type == L"muc" && message.level != L"subject";
     506                }
     507        ), m_GuiMessageQueue.end());
     508    }
     509
    499510    JSContext* cx = scriptInterface.GetContext();
    500511    JSAutoRequest rq(cx);
    501512
    502513    scriptInterface.Eval("([])", ret);
    503514
  • source/lobby/XmppClient.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
     
    1616 */
    1717
    1818#ifndef XXXMPPCLIENT_H
    1919#define XXXMPPCLIENT_H
    2020
    21 #include "IXmppClient.h"
     21#include <deque>
    2222
     23#include "IXmppClient.h"
    2324#include "glooxwrapper/glooxwrapper.h"
    24 
    25 //game - script
    26 #include <deque>
    2725#include "scriptinterface/ScriptVal.h"
    2826
    29 //Game - script
    3027class ScriptInterface;
    3128
    3229namespace glooxwrapper
    3330{
    3431    class Client;
     
    3633}
    3734
    3835class XmppClient : public IXmppClient, public glooxwrapper::ConnectionListener, public glooxwrapper::MUCRoomHandler, public glooxwrapper::IqHandler, public glooxwrapper::RegistrationHandler, public glooxwrapper::MessageHandler
    3936{
    4037    NONCOPYABLE(XmppClient);
     38
    4139private:
    4240    //Components
    4341    glooxwrapper::Client* m_client;
    4442    glooxwrapper::MUCRoom* m_mucRoom;
    4543    glooxwrapper::Registration* m_registration;
     44
    4645    //Account infos
    4746    std::string m_username;
    4847    std::string m_password;
    4948    std::string m_nick;
    5049    std::string m_xpartamuppId;
     50
    5151    // State
    5252    bool m_initialLoadComplete = false;
     53
    5354public:
    5455    //Basic
    5556    XmppClient(const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize = 0, const bool regOpt = false);
    5657    virtual ~XmppClient();
    5758
     
    7475    void SetPresence(const std::string& presence);
    7576    void GetPresence(const std::string& nickname, std::string& presence);
    7677    void GetRole(const std::string& nickname, std::string& role);
    7778    void GetSubject(std::string& subject);
    7879
    79     void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
     80    void GUIGetPlayerList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret, bool clearPresenceUpdates);
    8081    void GUIGetGameList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
    8182    void GUIGetBoardList(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
    8283    void GUIGetProfile(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
     84
    8385    //Script
    8486    ScriptInterface& GetScriptInterface();
    8587
    8688protected:
    8789    /* Xmpp handlers */
     
    120122
    121123    // Helpers
    122124    void GetPresenceString(const gloox::Presence::PresenceType p, std::string& presence) const;
    123125    void GetRoleString(const gloox::MUCRoomRole r, std::string& role) const;
    124126    std::string StanzaErrorToString(gloox::StanzaError err);
     127
    125128public:
    126129    /* Messages */
    127130    struct GUIMessage
    128131    {
    129132        std::wstring type;
  • source/lobby/scripting/JSInterface_Lobby.cpp

     
    4444    scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::SendGetProfile>("SendGetProfile");
    4545    scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame");
    4646    scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport");
    4747    scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame");
    4848    scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
    49     scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList");
     49    scriptInterface.RegisterFunction<JS::Value, bool, &JSI_Lobby::GetPlayerList>("GetPlayerList");
    5050    scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetGameList>("GetGameList");
    5151    scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetBoardList>("GetBoardList");
    5252    scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetProfile>("GetProfile");
    5353    scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::LobbyGuiPollMessage>("LobbyGuiPollMessage");
    5454    scriptInterface.RegisterFunction<void, std::wstring, &JSI_Lobby::LobbySendMessage>("LobbySendMessage");
     
    173173    if (!g_XmppClient)
    174174        return;
    175175    g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players));
    176176}
    177177
    178 JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate)
     178JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate, bool clearPresenceUpdates)
    179179{
    180180    if (!g_XmppClient)
    181181        return JS::UndefinedValue();
    182182
    183183    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
    184184    JSAutoRequest rq(cx);
    185185       
    186186    JS::RootedValue playerList(cx);
    187     g_XmppClient->GUIGetPlayerList(*(pCxPrivate->pScriptInterface), &playerList);
     187    g_XmppClient->GUIGetPlayerList(*(pCxPrivate->pScriptInterface), &playerList, clearPresenceUpdates);
    188188
    189189    return playerList;
    190190}
    191191
    192192JS::Value JSI_Lobby::GetGameList(ScriptInterface::CxPrivate* pCxPrivate)
  • source/lobby/scripting/JSInterface_Lobby.h

     
    4242    void SendGetProfile(ScriptInterface::CxPrivate* pCxPrivate, std::wstring player);
    4343    void SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data);
    4444    void SendRegisterGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data);
    4545    void SendUnregisterGame(ScriptInterface::CxPrivate* pCxPrivate);
    4646    void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring nbp, std::wstring players);
    47     JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate);
     47    JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate, bool clearPresenceUpdates);
    4848    JS::Value GetGameList(ScriptInterface::CxPrivate* pCxPrivate);
    4949    JS::Value GetBoardList(ScriptInterface::CxPrivate* pCxPrivate);
    5050    JS::Value GetProfile(ScriptInterface::CxPrivate* pCxPrivate);
    5151    JS::Value LobbyGuiPollMessage(ScriptInterface::CxPrivate* pCxPrivate);
    5252    void LobbySendMessage(ScriptInterface::CxPrivate* pCxPrivate, std::wstring message);