From 899221e2d058f5afe30bb2ecdbf168c8ad3c15a6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 27 Jan 2023 19:48:42 +0300 Subject: Group chats: all old APIs with lookup by module+session removed --- protocols/Twitter/src/chat.cpp | 26 ++++++++++++-------------- protocols/Twitter/src/connection.cpp | 4 ++-- protocols/Twitter/src/contacts.cpp | 4 ++-- protocols/Twitter/src/proto.cpp | 5 ++--- protocols/Twitter/src/proto.h | 4 +--- 5 files changed, 19 insertions(+), 24 deletions(-) (limited to 'protocols/Twitter/src') diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index 40b344ada0..6a6ba4c214 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -26,7 +26,7 @@ void CTwitterProto::UpdateChat(const twitter_user &update) CMStringA chatText = update.status.text.c_str(); chatText.Replace("%", "%%"); - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_si, GC_EVENT_MESSAGE }; gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.bIsMe = (update.username.c_str() == m_szUserName); gce.pszUID.a = update.username.c_str(); @@ -75,7 +75,7 @@ int CTwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) // TODO: remove nick? void CTwitterProto::AddChatContact(const char *name, const char *nick) { - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_JOIN }; + GCEVENT gce = { m_si, GC_EVENT_JOIN }; gce.dwFlags = GCEF_UTF8; gce.time = uint32_t(time(0)); gce.pszNick.a = nick ? nick : name; @@ -86,7 +86,7 @@ void CTwitterProto::AddChatContact(const char *name, const char *nick) void CTwitterProto::DeleteChatContact(const char *name) { - GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_PART }; + GCEVENT gce = { m_si, GC_EVENT_PART }; gce.dwFlags = GCEF_UTF8; gce.time = uint32_t(time(0)); gce.pszUID.a = gce.pszNick.a = name; @@ -96,12 +96,12 @@ void CTwitterProto::DeleteChatContact(const char *name) INT_PTR CTwitterProto::OnJoinChat(WPARAM, LPARAM suppress) { // ***** Create the group chat session - SESSION_INFO *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, m_tszUserName, m_tszUserName); - if (!si || m_iStatus != ID_STATUS_ONLINE) + m_si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, m_tszUserName, m_tszUserName); + if (!m_si || m_iStatus != ID_STATUS_ONLINE) return 0; // ***** Create a group - Chat_AddGroup(si, TranslateT("Normal")); + Chat_AddGroup(m_si, TranslateT("Normal")); // ***** Hook events HookProtoEvent(ME_GC_EVENT, &CTwitterProto::OnChatOutgoing); @@ -110,16 +110,14 @@ INT_PTR CTwitterProto::OnJoinChat(WPARAM, LPARAM suppress) if (!suppress) SetChatStatus(m_iStatus); - in_chat_ = true; return 0; } INT_PTR CTwitterProto::OnLeaveChat(WPARAM, LPARAM) { - in_chat_ = false; - - Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); - Chat_Terminate(m_szModuleName, m_tszUserName); + Chat_Control(m_si, SESSION_OFFLINE); + Chat_Terminate(m_si); + m_si = nullptr; return 0; } @@ -138,8 +136,8 @@ void CTwitterProto::SetChatStatus(int status) // For some reason, I have to send an INITDONE message, even if I'm not actually // initializing the room... - Chat_Control(m_szModuleName, m_tszUserName, SESSION_INITDONE); - Chat_Control(m_szModuleName, m_tszUserName, SESSION_ONLINE); + Chat_Control(m_si, SESSION_INITDONE); + Chat_Control(m_si, SESSION_ONLINE); } - else Chat_Control(m_szModuleName, m_tszUserName, SESSION_OFFLINE); + else Chat_Control(m_si, SESSION_OFFLINE); } diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index 5e8b88d830..50d9fd6ad0 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -64,7 +64,7 @@ void CTwitterProto::SignOn(void*) } if (NegotiateConnection()) // Could this be? The legendary Go Time?? { - if (!in_chat_ && getByte(TWITTER_KEY_CHATFEED)) + if (!m_si && getByte(TWITTER_KEY_CHATFEED)) OnJoinChat(0, true); setAllContactStatuses(ID_STATUS_ONLINE); @@ -508,7 +508,7 @@ void CTwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg) } for (auto &u : messages.rev_iter()) { - if (!pre_read && in_chat_) + if (!pre_read && m_si) UpdateChat(*u); if (u->username == m_szUserName.c_str()) diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp index d17263cccf..dc3b2668ee 100644 --- a/protocols/Twitter/src/contacts.cpp +++ b/protocols/Twitter/src/contacts.cpp @@ -165,7 +165,7 @@ int CTwitterProto::OnContactDeleted(WPARAM wParam, LPARAM) DBVARIANT dbv; if (!getString(hContact, TWITTER_KEY_UN, &dbv)) { - if (in_chat_) + if (m_si) DeleteChatContact(dbv.pszVal); mir_cslock s(twitter_lock_); @@ -242,7 +242,7 @@ MCONTACT CTwitterProto::AddToClientList(const char *name, const char *status) if (hContact) return hContact; - if (in_chat_) + if (m_si) AddChatContact(name); // If not, make a new contact! diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index ab569e9d5b..3bdb0ee542 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -25,7 +25,6 @@ static volatile LONG g_msgid = 1; CTwitterProto::CTwitterProto(const char *proto_name, const wchar_t *username) : PROTO(proto_name, username), - m_szChatId(mir_utf8encodeW(username)), m_arChatMarks(10, NumericKeySortT) { CreateProtoService(PS_CREATEACCMGRUI, &CTwitterProto::SvcCreateAccMgrUI); @@ -346,11 +345,11 @@ void CTwitterProto::SendTweetWorker(void *p) void CTwitterProto::UpdateSettings() { if (getByte(TWITTER_KEY_CHATFEED)) { - if (!in_chat_) + if (!m_si) OnJoinChat(0, 0); } else { - if (in_chat_) + if (m_si) OnLeaveChat(0, 0); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact;) { diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 69fca0130a..6868386c29 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -58,7 +58,7 @@ struct CChatMark class CTwitterProto : public PROTO { - ptrA m_szChatId; + SESSION_INFO *m_si; http::response request_token(); http::response request_access_tokens(); @@ -99,8 +99,6 @@ class CTwitterProto : public PROTO twitter_id since_id_; twitter_id dm_since_id_; - bool in_chat_; - int disconnectionCount; // OAuthWebRequest used for all OAuth related queries -- cgit v1.2.3