diff options
author | George Hazan <ghazan@miranda.im> | 2018-04-22 00:55:51 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-04-22 00:57:16 +0300 |
commit | d28931ebdfc4ff561d05ab000aee4cbb5ac24d62 (patch) | |
tree | e5cfd83eb231df123a3d744106a4e9b521fba409 /protocols/Discord | |
parent | 921f870dd0feec3230a8634abbd85c556e9f3d22 (diff) |
OnEvent(EV_PROTO_ONCONTACTDELETED) => PROTO_INTERFACE::OnContactDeleted
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/proto.cpp | 102 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 14 |
2 files changed, 56 insertions, 60 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 003079a283..ec9faa0690 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -92,6 +92,49 @@ CDiscordProto::~CDiscordProto() ::CloseHandle(m_evRequestsQueue); } +///////////////////////////////////////////////////////////////////////////////////////// + +void CDiscordProto::OnModulesLoaded() +{ + // Fill users list + for (auto &hContact : AccContacts()) { + CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); + pNew->hContact = hContact; + pNew->channelId = getId(hContact, DB_KEY_CHANNELID); + pNew->lastMsg.id = getId(hContact, DB_KEY_LASTMSGID); + pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); + pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); + arUsers.insert(pNew); + } + + GCREGISTER gcr = {}; + gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR; + gcr.ptszDispName = m_tszUserName; + gcr.pszModule = m_szModuleName; + Chat_Register(&gcr); + + // Clist + Clist_GroupCreate(0, m_wszDefaultGroup); + + HookProtoEvent(ME_GC_EVENT, &CDiscordProto::GroupchatEventHook); + HookProtoEvent(ME_GC_BUILDMENU, &CDiscordProto::GroupchatMenuHook); + + InitMenus(); +} + +void CDiscordProto::OnShutdown() +{ + debugLogA("CDiscordProto::OnPreShutdown"); + + m_bTerminated = true; + SetEvent(m_evRequestsQueue); + + if (m_hGatewayConnection) + Netlib_Shutdown(m_hGatewayConnection); +} + +///////////////////////////////////////////////////////////////////////////////////////// + INT_PTR CDiscordProto::GetCaps(int type, MCONTACT) { switch (type) { @@ -422,19 +465,17 @@ int CDiscordProto::OnDbEventRead(WPARAM, LPARAM hDbEvent) ///////////////////////////////////////////////////////////////////////////////////////// -int CDiscordProto::OnDeleteContact(MCONTACT hContact) +void CDiscordProto::OnContactDeleted(MCONTACT hContact) { CDiscordUser *pUser = FindUser(getId(hContact, DB_KEY_ID)); if (pUser == nullptr || !m_bOnline) - return 0; + return; if (pUser->channelId) Push(new AsyncHttpRequest(this, REQUEST_DELETE, CMStringA(FORMAT, "/channels/%lld", pUser->channelId), nullptr)); if (pUser->id) RemoveFriend(pUser->id); - - return 0; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -546,56 +587,3 @@ HANDLE CDiscordProto::SendFile(MCONTACT hContact, const wchar_t *szDescription, ForkThread(&CDiscordProto::SendFileThread, param); return param; } - -///////////////////////////////////////////////////////////////////////////////////////// - -void CDiscordProto::OnModulesLoaded() -{ - // Fill users list - for (auto &hContact : AccContacts()) { - CDiscordUser *pNew = new CDiscordUser(getId(hContact, DB_KEY_ID)); - pNew->hContact = hContact; - pNew->channelId = getId(hContact, DB_KEY_CHANNELID); - pNew->lastMsg.id = getId(hContact, DB_KEY_LASTMSGID); - pNew->wszUsername = ptrW(getWStringA(hContact, DB_KEY_NICK)); - pNew->iDiscriminator = getDword(hContact, DB_KEY_DISCR); - arUsers.insert(pNew); - } - - GCREGISTER gcr = {}; - gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR; - gcr.ptszDispName = m_tszUserName; - gcr.pszModule = m_szModuleName; - Chat_Register(&gcr); - - // Clist - Clist_GroupCreate(0, m_wszDefaultGroup); - - HookProtoEvent(ME_GC_EVENT, &CDiscordProto::GroupchatEventHook); - HookProtoEvent(ME_GC_BUILDMENU, &CDiscordProto::GroupchatMenuHook); - - InitMenus(); -} - -void CDiscordProto::OnShutdown() -{ - debugLogA("CDiscordProto::OnPreShutdown"); - - m_bTerminated = true; - SetEvent(m_evRequestsQueue); - - if (m_hGatewayConnection) - Netlib_Shutdown(m_hGatewayConnection); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int CDiscordProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM) -{ - switch (event) { - case EV_PROTO_ONCONTACTDELETED: - return OnDeleteContact((MCONTACT)wParam); - } - - return 1; -} diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 0b095d70da..8723c072d5 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -257,7 +257,9 @@ public: CDiscordProto(const char*,const wchar_t*); ~CDiscordProto(); + ////////////////////////////////////////////////////////////////////////////////////// // PROTO_INTERFACE + INT_PTR GetCaps(int, MCONTACT = 0) override; HWND CreateExtendedSearchUI(HWND owner) override; @@ -279,12 +281,14 @@ public: int UserIsTyping(MCONTACT hContact, int type) override; int SetStatus(int iNewStatus) override; - int OnEvent(PROTOEVENTTYPE, WPARAM, LPARAM) override; + void OnContactDeleted(MCONTACT) override; void OnModulesLoaded() override; void OnShutdown() override; + ////////////////////////////////////////////////////////////////////////////////////// // Services + INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM); INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM); @@ -292,11 +296,15 @@ public: INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM); INT_PTR __cdecl SetMyAvatar(WPARAM, LPARAM); + ////////////////////////////////////////////////////////////////////////////////////// // Events + int __cdecl OnOptionsInit(WPARAM, LPARAM); int __cdecl OnDbEventRead(WPARAM, LPARAM); + ////////////////////////////////////////////////////////////////////////////////////// // dispatch commands + void OnCommandChannelCreated(const JSONNode&); void OnCommandChannelDeleted(const JSONNode&); void OnCommandChannelUpdated(const JSONNode&); @@ -321,8 +329,6 @@ public: void OnLoggedIn(); void OnLoggedOut(); - int OnDeleteContact(MCONTACT hContact); - void OnReceiveCreateChannel(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveFile(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnReceiveGateway(NETLIBHTTPREQUEST*, AsyncHttpRequest*); @@ -339,7 +345,9 @@ public: bool RetrieveAvatar(MCONTACT hContact); void OnReceiveAvatar(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + ////////////////////////////////////////////////////////////////////////////////////// // Misc + void SetServerStatus(int iStatus); void RemoveFriend(SnowFlake id); |