summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/dispatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Discord/src/dispatch.cpp')
-rw-r--r--protocols/Discord/src/dispatch.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 80239a9b5e..74672391ca 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -26,6 +26,10 @@ struct CDiscordCommand
}
static handlers[] = // these structures must me sorted alphabetically
{
+ { L"CHANNEL_CREATE", &CDiscordProto::OnChannelCreated },
+ { L"CHANNEL_DELETE", &CDiscordProto::OnChannelDeleted },
+
+ { L"MESSAGE_ACK", &CDiscordProto::OnCommandMessageAck },
{ L"MESSAGE_CREATE", &CDiscordProto::OnCommandMessage },
{ L"MESSAGE_UPDATE", &CDiscordProto::OnCommandMessage },
@@ -54,6 +58,27 @@ GatewayHandlerFunc CDiscordProto::GetHandler(const wchar_t *pwszCommand)
}
//////////////////////////////////////////////////////////////////////////////////////
+// channel operations
+
+void CDiscordProto::OnChannelCreated(const JSONNode &pRoot)
+{
+ CDiscordUser *pUser = PrepareUser(pRoot["user"]);
+ if (pUser != NULL) {
+ pUser->channelId = _wtoi64(pRoot["id"].as_mstring());
+ setId(pUser->hContact, DB_KEY_CHANNELID, pUser->channelId);
+ }
+}
+
+void CDiscordProto::OnChannelDeleted(const JSONNode &pRoot)
+{
+ CDiscordUser *pUser = FindUserByChannel(pRoot["channel_id"]);
+ if (pUser != NULL) {
+ pUser->channelId = 0;
+ delSetting(pUser->hContact, DB_KEY_CHANNELID);
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
// reading a new message
void CDiscordProto::OnCommandFriendAdded(const JSONNode &pRoot)
@@ -91,18 +116,17 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
return;
}
- CDiscordUser *pUser = PrepareUser(pRoot["author"]);
+ // try to find a sender by his channel
SnowFlake channelId = _wtoi64(pRoot["channel_id"].as_mstring());
+ CDiscordUser *pUser = FindUserByChannel(channelId);
+ if (pUser == NULL) {
+ debugLogA("skipping message with unknown channel id=%lld", channelId);
+ return;
+ }
- // if a message has myself as an author, find the author via channel id
- if (pUser->id == 0) {
- pUser = FindUserByChannel(channelId);
- if (pUser == NULL) {
- debugLogA("skipping message with unknown channel id=%lld", channelId);
- return;
- }
+ // if a message has myself as an author, add some flags
+ if (_wtoi64(pRoot["author"]["id"].as_mstring()) == m_ownId)
recv.flags = PREF_CREATEREAD | PREF_SENT;
- }
CMStringW wszText = pRoot["content"].as_mstring();
@@ -129,6 +153,16 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
//////////////////////////////////////////////////////////////////////////////////////
// someone changed its status
+void CDiscordProto::OnCommandMessageAck(const JSONNode &pRoot)
+{
+ CDiscordUser *pUser = FindUserByChannel(pRoot["channel_id"]);
+ if (pUser != NULL)
+ pUser->lastMessageId = _wtoi64(pRoot["message_id"].as_mstring());
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+// someone changed its status
+
void CDiscordProto::OnCommandPresence(const JSONNode &pRoot)
{
CDiscordUser *pUser = PrepareUser(pRoot["user"]);