summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/dispatch.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-02-15 20:22:29 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-02-15 20:22:29 +0300
commitad212509efd1de495c7a4ad08504bc062bfe8e2a (patch)
tree47cbe3a37747cf2dd107878ff85082d368d7521b /protocols/Discord/src/dispatch.cpp
parentacd9edbd6413e9ff25378bd4e2cbc515d2a620f7 (diff)
Discord: groupchat history support
version bump
Diffstat (limited to 'protocols/Discord/src/dispatch.cpp')
-rw-r--r--protocols/Discord/src/dispatch.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 615cb6d3de..e43b70d0fc 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -210,6 +210,9 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
setId(si->hContact, DB_KEY_OWNERID, ownerId);
BuildStatusList(guildId, wszChannelId);
+ Chat_Control(m_szModuleName, wszChannelId, WINDOW_HIDDEN);
+ Chat_Control(m_szModuleName, wszChannelId, SESSION_ONLINE);
+
if (!wszTopic.IsEmpty()) {
Chat_SetStatusbarText(m_szModuleName, wszChannelId, wszTopic);
@@ -226,6 +229,7 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
pUser = new CDiscordUser(channelId);
pUser->bIsPrivate = false;
pUser->hContact = si->hContact;
+ pUser->id = channelId;
pUser->channelId = channelId;
arUsers.insert(pUser);
}
@@ -234,7 +238,12 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
pUser->lastMessageId = ::getId(pch["last_message_id"]);
pUser->lastReadId = sttGetLastRead(readState, wszChannelId);
+ setId(pUser->hContact, DB_KEY_ID, channelId);
setId(pUser->hContact, DB_KEY_CHANNELID, channelId);
+
+ SnowFlake oldMsgId = getId(pUser->hContact, DB_KEY_LASTMSGID);
+ if (oldMsgId != 0 && pUser->lastMessageId > oldMsgId)
+ RetrieveHistory(pUser->hContact, MSG_AFTER, oldMsgId, 99);
}
}
@@ -256,9 +265,14 @@ void CDiscordProto::OnCommandGuildSync(const JSONNode &pRoot)
if (pUser.guildId != guildId)
continue;
+ SESSION_INFO *si = pci->SM_FindSession(pUser.wszUsername, m_szModuleName);
+ if (si == NULL)
+ continue;
+
GCDEST gcd = { m_szModuleName, pUser.wszUsername, GC_EVENT_JOIN };
GCEVENT gce = { &gcd };
gce.time = time(0);
+ gce.dwFlags = GCEF_SILENT;
for (auto it = pMembers.begin(); it != pMembers.end(); ++it) {
const JSONNode &m = *it;
@@ -295,10 +309,6 @@ void CDiscordProto::OnCommandGuildSync(const JSONNode &pRoot)
}
Chat_SetStatusEx(m_szModuleName, pUser.wszUsername, flags, wszUserId);
}
-
- // okay, users added & topic set, now we can move a room online
- Chat_Control(m_szModuleName, pUser.wszUsername, WINDOW_HIDDEN);
- Chat_Control(m_szModuleName, pUser.wszUsername, SESSION_ONLINE);
}
}
@@ -447,10 +457,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
recv.szMessage = buf;
recv.lParam = (LPARAM)wszMessageId.c_str();
ProtoChainRecvMsg(pUser->hContact, &recv);
-
- SnowFlake lastId = getId(pUser->hContact, DB_KEY_LASTMSGID); // as stored in a database
- if (lastId < messageId)
- setId(pUser->hContact, DB_KEY_LASTMSGID, messageId);
}
else {
debugLogA("store a message into the group channel id %lld", channelId);
@@ -472,6 +478,10 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
gce.bIsMe = _wtoi64(wszUserId) == m_ownId;
Chat_Event(&gce);
}
+
+ SnowFlake lastId = getId(pUser->hContact, DB_KEY_LASTMSGID); // as stored in a database
+ if (lastId < messageId)
+ setId(pUser->hContact, DB_KEY_LASTMSGID, messageId);
}
/////////////////////////////////////////////////////////////////////////////////////////