summaryrefslogtreecommitdiff
path: root/protocols/Discord/src/utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-01-07 22:57:57 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-01-07 22:57:57 +0300
commitf1a204292b895a94f142c32b2f3dc69fcc053e67 (patch)
tree465127e97ce90f457c90b8cfc78ae8f0e00b5064 /protocols/Discord/src/utils.cpp
parente012650957335d5f4295441debf849b3b9b2f4ef (diff)
first version of Discord that sends messages, catches presence packets and displays typing notification
version bump
Diffstat (limited to 'protocols/Discord/src/utils.cpp')
-rw-r--r--protocols/Discord/src/utils.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index ce000c0989..ae610b8d21 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -70,6 +70,15 @@ time_t StringToDate(const CMStringW &str)
/////////////////////////////////////////////////////////////////////////////////////////
+static LONG volatile g_counter = 1;
+
+int SerialNext()
+{
+ return InterlockedIncrement(&g_counter);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
SnowFlake CDiscordProto::getId(const char *szSetting)
{
DBVARIANT dbv;
@@ -106,6 +115,8 @@ void CDiscordProto::setId(MCONTACT hContact, const char *szSetting, SnowFlake iV
/////////////////////////////////////////////////////////////////////////////////////////
+static CDiscordUser *g_myUser = new CDiscordUser(0);
+
CDiscordUser* CDiscordProto::FindUser(SnowFlake id)
{
return arUsers.find((CDiscordUser*)&id);
@@ -122,9 +133,23 @@ CDiscordUser* CDiscordProto::FindUser(const wchar_t *pwszUsername, int iDiscrimi
return NULL;
}
+CDiscordUser* CDiscordProto::FindUserByChannel(SnowFlake channelId)
+{
+ for (int i = 0; i < arUsers.getCount(); i++) {
+ CDiscordUser &p = arUsers[i];
+ if (p.channelId == channelId)
+ return &p;
+ }
+
+ return NULL;
+}
+
CDiscordUser* CDiscordProto::PrepareUser(const JSONNode &user)
{
SnowFlake id = _wtoi64(user["id"].as_mstring());
+ if (id == m_ownId)
+ return g_myUser;
+
int iDiscriminator = _wtoi(user["discriminator"].as_mstring());
CMStringW avatar = user["avatar"].as_mstring();
CMStringW username = user["username"].as_mstring();