summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-26 19:57:16 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-26 19:57:16 +0300
commit58f6699f46e31048a0ec475a41d472b2120a78c7 (patch)
treea368fd83b2a830398a5780ce13dae34fa69d2647
parent0f00ad85feaa2fdef2c38f385cfe6ae5e46b8b05 (diff)
more fixes related to #1827 - now the core checks unique user ids itself
-rw-r--r--include/m_chat_int.h21
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp24
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h2
-rw-r--r--src/mir_app/src/chat_manager.cpp33
4 files changed, 35 insertions, 45 deletions
diff --git a/include/m_chat_int.h b/include/m_chat_int.h
index fa292f4d13..586972536e 100644
--- a/include/m_chat_int.h
+++ b/include/m_chat_int.h
@@ -85,8 +85,8 @@ class CChatRoomDlg;
struct USERINFO : public MZeroedObject, public MNonCopyable
{
- wchar_t* pszNick;
wchar_t* pszUID;
+ wchar_t* pszNick;
WORD Status;
int iStatusEx;
WORD ContactStatus;
@@ -97,15 +97,15 @@ struct MIR_APP_EXPORT GCModuleInfoBase : public MZeroedObject, public MNonCopyab
GCModuleInfoBase();
~GCModuleInfoBase();
- char *pszModule;
- wchar_t *ptszModDispName;
- char *pszHeader;
+ char* pszModule;
+ wchar_t* ptszModDispName;
+ char* pszHeader;
- bool bBold, bItalics, bUnderline;
- bool bColor, bBkgColor;
- bool bChanMgr, bAckMsg;
+ bool bBold, bItalics, bUnderline;
+ bool bColor, bBkgColor;
+ bool bChanMgr, bAckMsg;
- int iMaxText;
+ int iMaxText;
};
struct COMMANDINFO
@@ -180,6 +180,7 @@ struct MIR_APP_EXPORT GCSessionInfoBase : public MZeroedObject, public MNonCopya
MODULEINFO *pMI;
GCSessionInfoBase *pParent;
+ LIST<USERINFO> arKeys;
OBJLIST<USERINFO> arUsers;
wchar_t pszLogFileName[MAX_PATH];
@@ -191,6 +192,10 @@ struct MIR_APP_EXPORT GCSessionInfoBase : public MZeroedObject, public MNonCopya
__forceinline OBJLIST<USERINFO>& getUserList()
{ return (pParent != nullptr) ? pParent->arUsers : arUsers;
}
+
+ __forceinline LIST<USERINFO>& getKeyList()
+ { return (pParent != nullptr) ? pParent->arKeys : arKeys;
+ }
};
struct GCLogStreamDataBase
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index 44ee84166b..7965447c9b 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -389,8 +389,7 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p)
CMStringA username(UrlToSkypename(member["userLink"].as_string().c_str()));
std::string role = member["role"].as_string();
- if (!IsChatContact(chatId, username))
- AddChatContact(chatId, username, username, role.c_str(), true);
+ AddChatContact(chatId, username, username, role.c_str(), true);
}
PushRequest(new GetHistoryRequest(chatId, 15, true, 0, li), &CSkypeProto::OnGetServerHistory);
}
@@ -412,24 +411,6 @@ void CSkypeProto::ChangeChatTopic(const char *chat_id, const char *topic, const
Chat_Event(&gce);
}
-bool CSkypeProto::IsChatContact(const char *chat_id, const char *id)
-{
- ptrA users(GetChatUsers(chat_id));
- return (users != NULL && strstr(users, id) != nullptr);
-}
-
-char* CSkypeProto::GetChatUsers(const char *chat_id)
-{
- Utf2T id(chat_id);
-
- GC_INFO gci = { 0 };
- gci.Flags = GCF_USERS;
- gci.pszModule = m_szModuleName;
- gci.pszID = id;
- Chat_GetInfo(&gci);
- return gci.pszUsers;
-}
-
char* CSkypeProto::GetChatContactNick(const char *chat_id, const char *id, const char *name)
{
// Check if there is custom nick for this chat contact
@@ -465,9 +446,6 @@ char* CSkypeProto::GetChatContactNick(const char *chat_id, const char *id, const
void CSkypeProto::AddChatContact(const char *chat_id, const char *id, const char *name, const char *role, bool isChange)
{
- if (IsChatContact(chat_id, id))
- return;
-
ptrA szNick(GetChatContactNick(chat_id, id, name));
GCEVENT gce = { m_szModuleName, chat_id, GC_EVENT_JOIN };
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index 3ca8336a1b..cdf53ac492 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -325,8 +325,6 @@ private:
void OnChatEvent(const JSONNode &node);
void OnSendChatMessage(const char *chat_id, const wchar_t *tszMessage);
- char* GetChatUsers(const char *chat_id);
- bool IsChatContact(const char *chat_id, const char *id);
void AddMessageToChat(const char *chat_id, const char *from, const char *content, bool isAction, int emoteOffset, time_t timestamp, bool isLoading = false);
void AddChatContact(const char *chat_id, const char *id, const char *name, const char *role, bool isChange = false);
void RemoveChatContact(const char *chat_id, const char *id, const char *name, bool isKick = false, const char *initiator = "");
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp
index ce741b594f..221db7e042 100644
--- a/src/mir_app/src/chat_manager.cpp
+++ b/src/mir_app/src/chat_manager.cpp
@@ -26,6 +26,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define WINDOWS_COMMANDS_MAX 30
+static int CompareKeys(const USERINFO *u1, const USERINFO *u2)
+{
+ return mir_wstrcmp(u1->pszUID, u2->pszUID);
+}
+
static int CompareUser(const USERINFO *u1, const USERINFO *u2)
{
return g_chatApi.UM_CompareItem(u1, u2);
@@ -72,6 +77,7 @@ static SESSION_INFO* GetActiveSession(void)
// Keeps track of all sessions and its windows
GCSessionInfoBase::GCSessionInfoBase() :
+ arKeys(10, CompareKeys),
arUsers(10, CompareUser)
{}
@@ -671,11 +677,9 @@ static USERINFO* UM_FindUser(SESSION_INFO *si, const wchar_t *pszUID)
if (!si || !pszUID)
return nullptr;
- for (auto &ui : si->getUserList())
- if (!mir_wstrcmpi(ui->pszUID, pszUID))
- return ui;
-
- return nullptr;
+ USERINFO tmp;
+ tmp.pszUID = (wchar_t*)pszUID;
+ return si->getKeyList().find(&tmp);
}
static int compareStub(const void *p1, const void *p2)
@@ -694,15 +698,20 @@ bool UM_SortUser(SESSION_INFO *si, const wchar_t *pszUID)
USERINFO* UM_AddUser(SESSION_INFO *si, const wchar_t *pszUID, const wchar_t *pszNick, WORD wStatus)
{
- if (si == nullptr || pszNick == nullptr)
+ if (pszNick == nullptr)
return nullptr;
- USERINFO *node = new USERINFO();
- node->pszUID = mir_wstrdup(pszUID);
- node->pszNick = mir_wstrdup(pszNick);
- node->Status = wStatus;
- si->getUserList().insert(node);
- return node;
+ auto *pUser = UM_FindUser(si, pszUID);
+ if (pUser)
+ return pUser;
+
+ pUser = new USERINFO();
+ pUser->pszUID = mir_wstrdup(pszUID);
+ pUser->pszNick = mir_wstrdup(pszNick);
+ pUser->Status = wStatus;
+ si->getKeyList().insert(pUser);
+ si->getUserList().insert(pUser);
+ return pUser;
}
static int UM_CompareItem(const USERINFO *u1, const USERINFO *u2)