diff options
author | George Hazan <ghazan@miranda.im> | 2016-12-29 18:53:03 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2016-12-29 18:53:03 +0300 |
commit | 50e87bcbf1b3a716f155e504a09df1c0ff1a66f5 (patch) | |
tree | 671924fd03f4f0a3a5da0af7cd4fe4cc841d54ad | |
parent | 95ee503b0f0a4cb434de65f2d9d7375356e39d74 (diff) |
support for the SnowFlake type for Miranda
-rw-r--r-- | protocols/Discord/src/proto.h | 10 | ||||
-rw-r--r-- | protocols/Discord/src/server.cpp | 4 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 32 |
3 files changed, 45 insertions, 1 deletions
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index ffa99f8268..fe525284f3 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -1,4 +1,6 @@ +typedef __int64 SnowFlake; + class CDiscordProto; typedef void (CDiscordProto::*HttpCallback)(NETLIBHTTPREQUEST*, struct AsyncHttpRequest*); @@ -88,6 +90,14 @@ class CDiscordProto : public PROTO<CDiscordProto> CMOption<wchar_t*> m_wszEmail; // my own email CMOption<wchar_t*> m_wszDefaultGroup; // clist group to store contacts + SnowFlake m_ownId; + + SnowFlake getId(const char *szName); + SnowFlake getId(MCONTACT hContact, const char *szName); + + void setId(const char *szName, SnowFlake iValue); + void setId(MCONTACT hContact, const char *szName, SnowFlake iValue); + public: CDiscordProto(const char*,const wchar_t*); ~CDiscordProto(); diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index d0550dccbb..8f8f551890 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -35,9 +35,11 @@ void CDiscordProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest* return; } + m_ownId = _wtoi64(root->at("id").as_mstring()); + setId("id", m_ownId); + setWString("Username", root->at("username").as_mstring()); setByte("MfaEnabled", root->at("mfa_enabled").as_bool()); - setWString("id", root->at("id").as_mstring()); setWString("AvatarHash", root->at("avatar").as_mstring()); setDword("Discriminator", root->at("discriminator").as_int()); setWString("Email", root->at("email").as_mstring()); diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index 52eecea527..4d69a6f40f 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -43,3 +43,35 @@ JSONNode& operator<<(JSONNode &json, const WCHAR_PARAM ¶m) json.push_back(JSONNode(param.szName, ptrA(mir_utf8encodeW(param.wszValue)).get())); return json; } + +///////////////////////////////////////////////////////////////////////////////////////// + +SnowFlake CDiscordProto::getId(const char *szSetting) +{ + SnowFlake result; + DBVARIANT dbv; + dbv.type = DBVT_BLOB; + dbv.pbVal = (BYTE*)&result; + dbv.cpbVal = sizeof(result); + return (db_get(NULL, m_szModuleName, szSetting, &dbv)) ? 0 : result; +} + +SnowFlake CDiscordProto::getId(MCONTACT hContact, const char *szSetting) +{ + SnowFlake result; + DBVARIANT dbv; + dbv.type = DBVT_BLOB; + dbv.pbVal = (BYTE*)&result; + dbv.cpbVal = sizeof(result); + return (db_get(hContact, m_szModuleName, szSetting, &dbv)) ? 0 : result; +} + +void CDiscordProto::setId(const char *szSetting, SnowFlake iValue) +{ + db_set_blob(NULL, m_szModuleName, szSetting, &iValue, sizeof(iValue)); +} + +void CDiscordProto::setId(MCONTACT hContact, const char *szSetting, SnowFlake iValue) +{ + db_set_blob(hContact, m_szModuleName, szSetting, &iValue, sizeof(iValue)); +} |