summaryrefslogtreecommitdiff
path: root/protocols/Discord/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-16 15:17:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-16 15:17:47 +0300
commitc00f494c8165b9f2d9facc6488173502b19ca696 (patch)
treec9b16d5341ed4336f7797333e12c926fe5e73211 /protocols/Discord/src
parentd50c14d30197fcf8d31e875d5c936a0890200be4 (diff)
- added reaction to remote contact removal;
- now we remove a channel & friendship on local contact removal
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r--protocols/Discord/src/dispatch.cpp18
-rw-r--r--protocols/Discord/src/proto.cpp32
-rw-r--r--protocols/Discord/src/proto.h5
3 files changed, 51 insertions, 4 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 8d314e0836..ef8cb223f7 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -33,6 +33,8 @@ static handlers[] = // these structures must me sorted alphabetically
{ L"READY", &CDiscordProto::OnCommandReady },
+ { L"RELATIONSHIP_REMOVE", &CDiscordProto::OnCommandFriendRemoved },
+
{ L"TYPING_START", &CDiscordProto::OnCommandTyping },
{ L"USER_UPDATE", &CDiscordProto::OnCommandUserUpdate },
@@ -53,6 +55,22 @@ GatewayHandlerFunc CDiscordProto::GetHandler(const wchar_t *pwszCommand)
//////////////////////////////////////////////////////////////////////////////////////
// reading a new message
+void CDiscordProto::OnCommandFriendRemoved(const JSONNode &pRoot)
+{
+ SnowFlake id = _wtoi64(pRoot["id"].as_mstring());
+ CDiscordUser *pUser = FindUser(id);
+ if (pUser != NULL) {
+ if (pUser->hContact) {
+ if (pUser->bIsPrivate)
+ db_delete_contact(pUser->hContact);
+ }
+ arUsers.remove(pUser);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// reading a new message
+
void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
{
PROTORECVEVENT recv = {};
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 427fba67d2..31a12fbdac 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -357,6 +357,24 @@ int CDiscordProto::OnDbEventRead(WPARAM, LPARAM hDbEvent)
/////////////////////////////////////////////////////////////////////////////////////////
+int CDiscordProto::OnDeleteContact(MCONTACT hContact)
+{
+ CDiscordUser *pUser = FindUser(getId(hContact, DB_KEY_ID));
+ if (pUser == NULL || !m_bOnline)
+ return 0;
+
+ if (pUser->channelId)
+ Push(new AsyncHttpRequest(this, REQUEST_DELETE, CMStringA(FORMAT, "/channels/%lld", pUser->channelId), NULL));
+
+ if (pUser->id)
+ Push(new AsyncHttpRequest(this, REQUEST_DELETE, CMStringA(FORMAT, "/users/@me/relationships/%lld", pUser->id), NULL));
+
+ return 0;
+}
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
int CDiscordProto::OnModulesLoaded(WPARAM, LPARAM)
{
return 0;
@@ -379,9 +397,17 @@ int CDiscordProto::OnPreShutdown(WPARAM, LPARAM)
int CDiscordProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam)
{
switch (event) {
- case EV_PROTO_ONLOAD: return OnModulesLoaded(wParam, lParam);
- case EV_PROTO_ONEXIT: return OnPreShutdown(wParam, lParam);
- case EV_PROTO_ONOPTIONS: return OnOptionsInit(wParam, lParam);
+ case EV_PROTO_ONLOAD:
+ return OnModulesLoaded(wParam, lParam);
+
+ case EV_PROTO_ONEXIT:
+ return OnPreShutdown(wParam, lParam);
+
+ case EV_PROTO_ONOPTIONS:
+ return OnOptionsInit(wParam, lParam);
+
+ 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 2ac14310b8..051095d8e8 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -225,8 +225,9 @@ public:
int __cdecl OnPreShutdown(WPARAM, LPARAM);
int __cdecl OnOptionsInit(WPARAM, LPARAM);
int __cdecl OnDbEventRead(WPARAM, LPARAM);
-
+
// dispatch commands
+ void OnCommandFriendRemoved(const JSONNode&);
void OnCommandMessage(const JSONNode&);
void OnCommandPresence(const JSONNode&);
void OnCommandReady(const JSONNode&);
@@ -235,6 +236,8 @@ public:
void OnLoggedIn();
void OnLoggedOut();
+
+ int OnDeleteContact(MCONTACT hContact);
void OnReceiveAuth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveChannels(NETLIBHTTPREQUEST*, AsyncHttpRequest*);