diff options
author | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-01-27 19:48:42 +0300 |
commit | 899221e2d058f5afe30bb2ecdbf168c8ad3c15a6 (patch) | |
tree | ea2346678575a4fc5fdd9575b6a9174bd30c70dc /protocols/VKontakte/src/vk_chats.cpp | |
parent | c736d08681747a9453bd4c266f6dd54d8cbd79eb (diff) |
Group chats: all old APIs with lookup by module+session removed
Diffstat (limited to 'protocols/VKontakte/src/vk_chats.cpp')
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index 1af5f49964..f4c9dd1353 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -35,7 +35,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte if (iChatId == 0)
return nullptr;
-
const JSONNode& jnConversation = jnItem ? jnItem["conversation"] : nullNode;
const JSONNode& jnLastMessage = jnItem ? jnItem["last_message"] : nullNode;
const JSONNode& jnChatSettings = jnConversation ? jnConversation["chat_settings"] : nullNode;
@@ -53,7 +52,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte if (hChatContact && getBool(hChatContact, "kicked"))
return nullptr;
-
CVkChatInfo* vkChatInfo = m_chats.find((CVkChatInfo*)&iChatId);
if (vkChatInfo != nullptr)
return vkChatInfo;
@@ -68,8 +66,6 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte CMStringW sid;
sid.Format(L"%d", iChatId);
- vkChatInfo->m_wszId = mir_wstrdup(sid);
-
SESSION_INFO* si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, sid, wszTitle);
if (si == nullptr) {
@@ -77,7 +73,7 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte return nullptr;
}
- vkChatInfo->m_hContact = si->hContact;
+ vkChatInfo->m_si = si;
setWString(si->hContact, "Nick", wszTitle);
m_chats.insert(vkChatInfo);
@@ -97,8 +93,8 @@ CVkChatInfo* CVkProto::AppendConversationChat(int iChatId, const JSONNode& jnIte return nullptr;
}
- Chat_Control(m_szModuleName, sid, (m_vkOptions.bHideChats) ? WINDOW_HIDDEN : SESSION_INITDONE);
- Chat_Control(m_szModuleName, sid, SESSION_ONLINE);
+ Chat_Control(si, (m_vkOptions.bHideChats) ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
RetrieveChatInfo(vkChatInfo);
@@ -139,7 +135,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe SetChatTitle(cc, jnInfo["title"].as_mstring());
if (jnInfo["left"].as_bool() || jnInfo["kicked"].as_bool()) {
- setByte(cc->m_hContact, "kicked", jnInfo["kicked"].as_bool());
+ setByte(cc->m_si->hContact, "kicked", jnInfo["kicked"].as_bool());
LeaveChat(cc->m_iChatId);
return;
}
@@ -178,7 +174,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe bNew = cu->m_bUnknown;
cu->m_bDel = false;
- CMStringW wszNick(ptrW(db_get_wsa(cc->m_hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
+ CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
if (wszNick.IsEmpty())
wszNick = bIsGroup ?
jnUser["name"].as_mstring() :
@@ -189,8 +185,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe cu->m_bUnknown = false;
if (bNew) {
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_JOIN };
- gce.pszID.w = cc->m_wszId;
+ GCEVENT gce = { cc->m_si, GC_EVENT_JOIN };
gce.bIsMe = uid == m_myUserId;
gce.pszUID.w = wszId;
gce.pszNick.w = wszNick;
@@ -208,8 +203,7 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe _itow(cu->m_uid, wszId, 10);
CMStringW wszNick(FORMAT, L"%s (%s)", cu->m_wszNick.get(), UserProfileUrl(cu->m_uid).c_str());
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_PART };
- gce.pszID.w = cc->m_wszId;
+ GCEVENT gce = { cc->m_si, GC_EVENT_PART };
gce.pszUID.w = wszId;
gce.dwFlags = GCEF_NOTNOTIFY;
gce.time = time(0);
@@ -267,9 +261,9 @@ void CVkProto::SetChatTitle(CVkChatInfo *cc, LPCWSTR wszTopic) return;
cc->m_wszTopic = mir_wstrdup(wszTopic);
- setWString(cc->m_hContact, "Nick", wszTopic);
+ setWString(cc->m_si->hContact, "Nick", wszTopic);
- Chat_ChangeSessionName(m_szModuleName, cc->m_wszId, wszTopic);
+ Chat_ChangeSessionName(cc->m_si, wszTopic);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -423,7 +417,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG uid, int msgTime, LPCWSTR CVkChatUser *cu = cc->m_users.find((CVkChatUser*)&uid);
if (cu == nullptr) {
cc->m_users.insert(cu = new CVkChatUser(uid));
- CMStringW wszNick(ptrW(db_get_wsa(cc->m_hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
+ CMStringW wszNick(ptrW(db_get_wsa(cc->m_si->hContact, m_szModuleName, CMStringA(FORMAT, "nick%d", cu->m_uid))));
cu->m_wszNick = mir_wstrdup(wszNick.IsEmpty() ? (hContact ? ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")) : TranslateT("Unknown")) : wszNick);
cu->m_bUnknown = true;
}
@@ -431,8 +425,7 @@ void CVkProto::AppendChatMessage(CVkChatInfo *cc, LONG uid, int msgTime, LPCWSTR wchar_t wszId[20];
_itow(uid, wszId, 10);
- GCEVENT gce = { m_szModuleName, 0, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE };
- gce.pszID.w = cc->m_wszId;
+ GCEVENT gce = { cc->m_si, bIsAction ? GC_EVENT_ACTION : GC_EVENT_MESSAGE };
gce.bIsMe = (uid == m_myUserId);
gce.pszUID.w = wszId;
gce.time = msgTime;
@@ -462,7 +455,7 @@ CVkChatInfo* CVkProto::GetChatByContact(MCONTACT hContact) CVkChatInfo* CVkProto::GetChatById(LPCWSTR pwszId)
{
for (auto &it : m_chats)
- if (!mir_wstrcmp(it->m_wszId, pwszId))
+ if (!mir_wstrcmp(it->m_si->ptszID, pwszId))
return it;
return nullptr;
@@ -474,7 +467,7 @@ void CVkProto::SetChatStatus(MCONTACT hContact, int iStatus) {
CVkChatInfo *cc = GetChatByContact(hContact);
if (cc != nullptr)
- Chat_Control(m_szModuleName, cc->m_wszId, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE);
+ Chat_Control(cc->m_si, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -498,7 +491,7 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam) ptrW pwszBuf(mir_wstrdup(gch->ptszText));
rtrimw(pwszBuf);
Chat_UnescapeTags(pwszBuf);
- SendMsg(cc->m_hContact, 0, T2Utf(pwszBuf));
+ SendMsg(cc->m_si->hContact, 0, T2Utf(pwszBuf));
}
break;
@@ -648,14 +641,14 @@ void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat) return;
if (close_window)
- Chat_Terminate(m_szModuleName, cc->m_wszId);
+ Chat_Terminate(m_szModuleName, cc->m_si->ptszID);
else
- Chat_Control(m_szModuleName, cc->m_wszId, SESSION_OFFLINE);
+ Chat_Control(cc->m_si, SESSION_OFFLINE);
if (delete_chat)
- DeleteContact(cc->m_hContact);
+ DeleteContact(cc->m_si->hContact);
else
- setByte(cc->m_hContact, "off", (int)true);
+ setByte(cc->m_si->hContact, "off", (int)true);
m_chats.remove(cc);
}
@@ -688,7 +681,7 @@ void CVkProto::KickFromChat(int chat_id, LONG user_id, const JSONNode &jnMsg, co AppendChatConversationMessage(chat_id, jnMsg, jnFUsers, false);
MsgPopup(hContact, msg, TranslateT("Chat"));
- setByte(cc->m_hContact, "kicked", 1);
+ setByte(cc->m_si->hContact, "kicked", 1);
LeaveChat(chat_id);
}
@@ -776,8 +769,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) wchar_t wszId[20];
_itow(cu->m_uid, wszId, 10);
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_NICK };
- gce.pszID.w = cc->m_wszId;
+ GCEVENT gce = { cc->m_si, GC_EVENT_NICK };
gce.pszNick.w = mir_wstrdup(cu->m_wszNick);
gce.bIsMe = (cu->m_uid == m_myUserId);
gce.pszUID.w = wszId;
@@ -787,7 +779,7 @@ void CVkProto::NickMenuHook(CVkChatInfo *cc, GCHOOK *gch) Chat_Event(&gce);
cu->m_wszNick = mir_wstrdup(wszNewNick);
- setWString(cc->m_hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick);
+ setWString(cc->m_si->hContact, CMStringA(FORMAT, "nick%d", cu->m_uid), wszNewNick);
}
break;
|