diff options
Diffstat (limited to 'protocols/Discord')
20 files changed, 111 insertions, 105 deletions
diff --git a/protocols/Discord/proto_discord/res/Away.ico b/protocols/Discord/proto_discord/res/Away.ico Binary files differindex 844c1d4b3a..46dccb19ca 100644 --- a/protocols/Discord/proto_discord/res/Away.ico +++ b/protocols/Discord/proto_discord/res/Away.ico diff --git a/protocols/Discord/proto_discord/res/DND.ico b/protocols/Discord/proto_discord/res/DND.ico Binary files differindex 6341c0e08c..805dd75622 100644 --- a/protocols/Discord/proto_discord/res/DND.ico +++ b/protocols/Discord/proto_discord/res/DND.ico diff --git a/protocols/Discord/proto_discord/res/Invisible.ico b/protocols/Discord/proto_discord/res/Invisible.ico Binary files differindex 7d34d4ca58..d168845ae6 100644 --- a/protocols/Discord/proto_discord/res/Invisible.ico +++ b/protocols/Discord/proto_discord/res/Invisible.ico diff --git a/protocols/Discord/proto_discord/res/Offline.ico b/protocols/Discord/proto_discord/res/Offline.ico Binary files differindex f2ec365064..7473a3b968 100644 --- a/protocols/Discord/proto_discord/res/Offline.ico +++ b/protocols/Discord/proto_discord/res/Offline.ico diff --git a/protocols/Discord/proto_discord/res/Online.ico b/protocols/Discord/proto_discord/res/Online.ico Binary files differindex 94f4d0d8bd..1d3efde242 100644 --- a/protocols/Discord/proto_discord/res/Online.ico +++ b/protocols/Discord/proto_discord/res/Online.ico diff --git a/protocols/Discord/res/discord.ico b/protocols/Discord/res/discord.ico Binary files differindex c2830ed132..1d3efde242 100644 --- a/protocols/Discord/res/discord.ico +++ b/protocols/Discord/res/discord.ico diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp index ff7e765ecb..909c4f528f 100644 --- a/protocols/Discord/src/connection.cpp +++ b/protocols/Discord/src/connection.cpp @@ -87,14 +87,15 @@ void CDiscordProto::ShutdownSession() return;
debugLogA("CDiscordProto::ShutdownSession");
+ m_bTerminated = true;
// shutdown all resources
if (pMfaDialog)
pMfaDialog->Close();
if (m_hWorkerThread)
SetEvent(m_evRequestsQueue);
- if (m_ws)
- m_ws->terminate();
+ if (m_bConnected)
+ m_ws.terminate();
if (m_hAPIConnection)
Netlib_Shutdown(m_hAPIConnection);
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index abcae9afb8..1e7c6be758 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -124,7 +124,7 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot) else {
CDiscordGuild *pGuild = FindGuild(guildId);
if (pGuild != nullptr) {
- db_delete_contact(pUser->si->hContact);
+ db_delete_contact(pUser->hContact);
pUser->si = nullptr;
}
}
@@ -440,7 +440,7 @@ void CDiscordProto::OnCommandRoleDeleted(const JSONNode &pRoot) SESSION_INFO *si = Chat_Find(it->wszUsername, m_szModuleName);
if (si != nullptr) {
- g_chatApi.TM_RemoveAll(&si->pStatuses);
+ si->arStatuses.destroy();
BuildStatusList(pGuild, si);
}
}
@@ -521,14 +521,15 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (userId == m_ownId)
dbei.flags |= DBEF_READ | DBEF_SENT;
- if (auto &nReply = pRoot["message_reference"]) {
- _i64toa(::getId(nReply["message_id"]), szReplyId, 10);
- dbei.szReplyId = szReplyId;
- }
+ if (auto &nReply = pRoot["message_reference"])
+ if (auto replyId = ::getId(nReply["message_id"])) {
+ _i64toa(replyId, szReplyId, 10);
+ dbei.szReplyId = szReplyId;
+ }
debugLogA("store a message from private user %lld, channel id %lld", pUser->id, pUser->channelId);
- dbei.timestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring());
+ dbei.iTimestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring());
dbei.szId = szMsgId;
replaceStr(dbei.pBlob, mir_utf8encodeW(wszText));
dbei.cbBlob = (int)mir_strlen(dbei.pBlob);
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index d6b7846eeb..283ebe6bb5 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -22,12 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. bool CDiscordProto::GatewaySend(const JSONNode &pRoot)
{
- if (m_ws == nullptr)
+ if (!m_bConnected)
return false;
- json_string szText = pRoot.write();
- debugLogA("Gateway send: %s", szText.c_str());
- m_ws->sendText(szText.c_str());
+ m_ws.sendText(pRoot.write().c_str());
return true;
}
@@ -51,8 +49,7 @@ bool CDiscordProto::GatewayThreadWorker() hdrs.AddHeader("Cookie", m_szWSCookie);
}
- JsonWebSocket<CDiscordProto> ws(this);
- NLHR_PTR pReply(ws.connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", &hdrs));
+ NLHR_PTR pReply(m_ws.connect(m_hGatewayNetlibUser, m_szGateway + "/?encoding=json&v=8", &hdrs));
if (pReply == nullptr) {
debugLogA("Gateway connection failed, exiting");
return false;
@@ -74,11 +71,10 @@ bool CDiscordProto::GatewayThreadWorker() // succeeded!
debugLogA("Gateway connection succeeded");
- m_ws = &ws;
- ws.run();
-
- m_ws = nullptr;
- return true;
+ m_bConnected = true;
+ m_ws.run();
+ m_bConnected = false;
+ return !m_bTerminated;
}
//////////////////////////////////////////////////////////////////////////////////////
@@ -105,7 +101,7 @@ void JsonWebSocket<CDiscordProto>::process(const JSONNode &json) case OPCODE_RECONNECT: // we need to reconnect asap
p->debugLogA("we need to reconnect, leaving worker thread");
- p->m_bTerminated = true;
+ p->m_ws.terminate();
return;
case OPCODE_INVALID_SESSION: // session invalidated
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp index 19210b4cbc..160a152c0d 100644 --- a/protocols/Discord/src/guilds.cpp +++ b/protocols/Discord/src/guilds.cpp @@ -357,12 +357,10 @@ void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMembe break;
}
- auto *pStatus = g_chatApi.TM_FindStatus(pGuild->pParentSi->pStatuses, pUser.wszRole);
-
wchar_t wszUserId[100];
_i64tow_s(pUser.userId, wszUserId, _countof(wszUserId), 10);
- auto *pu = g_chatApi.UM_AddUser(pGuild->pParentSi, wszUserId, pUser.wszNick, (pStatus) ? pStatus->iStatus : 0);
+ auto *pu = g_chatApi.UM_AddUser(pGuild->pParentSi, wszUserId, pUser.wszNick, 0);
pu->iStatusEx = flags;
if (pUser.userId == m_ownId)
pGuild->pParentSi->pMe = pu;
diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index c5d5e1e0c0..f6a912e9e4 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -74,25 +74,6 @@ AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR m_iReqNum = ::InterlockedIncrement(&g_reqNum);
}
-JsonReply::JsonReply(MHttpResponse *pReply)
-{
- if (pReply == nullptr) {
- m_errorCode = 500;
- return;
- }
-
- m_errorCode = pReply->resultCode;
-
- m_root = json_parse(pReply->body);
- if (m_root == nullptr)
- m_errorCode = 500;
-}
-
-JsonReply::~JsonReply()
-{
- json_delete(m_root);
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
void CDiscordProto::ServerThread(void*)
@@ -121,11 +102,11 @@ void CDiscordProto::ServerThread(void*) JSONNode root; root << WCHAR_PARAM("password", wszPassword);
if (wszEmail.Find('@') == -1) {
+ // ensure that a phone number begins with +
if (wszEmail[0] != '+')
wszEmail.Insert(0, L"+");
- root << WCHAR_PARAM("login", wszEmail) ;
}
- else root << WCHAR_PARAM("email", wszEmail);
+ root << WCHAR_PARAM("login", wszEmail);
Push(new AsyncHttpRequest(this, REQUEST_POST, "/auth/login", &CDiscordProto::OnReceiveToken, &root));
}
diff --git a/protocols/Discord/src/main.cpp b/protocols/Discord/src/main.cpp index 023a7b7925..08d8c27dbe 100644 --- a/protocols/Discord/src/main.cpp +++ b/protocols/Discord/src/main.cpp @@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. CMPlugin g_plugin;
+HGENMENU g_hMenuLeaveGuild, g_hMenuCreateChannel, g_hMenuToggleSync, g_hMenuDatabaseHistory;
+
/////////////////////////////////////////////////////////////////////////////////////////
PLUGININFOEX pluginInfoEx = {
@@ -79,6 +81,8 @@ int CMPlugin::Load() HookEvent(ME_SYSTEM_MODULESLOADED, &OnModulesLoaded);
+ CDiscordProto::InitMenus();
+
g_plugin.registerIcon("Protocols/Discord", g_iconList);
return 0;
}
diff --git a/protocols/Discord/src/menus.cpp b/protocols/Discord/src/menus.cpp index 13c5f204d9..58de289f66 100644 --- a/protocols/Discord/src/menus.cpp +++ b/protocols/Discord/src/menus.cpp @@ -53,12 +53,26 @@ INT_PTR CDiscordProto::OnMenuDatabaseHistory(WPARAM hContact, LPARAM) /////////////////////////////////////////////////////////////////////////////////////////
+void CDiscordProto::OnReceiveJoin(MHttpResponse *pResponse, AsyncHttpRequest *)
+{
+ if (pResponse->resultCode == 400) {
+ auto reply = JSONNode::parse(pResponse->body);
+ if (reply && reply["captcha_key"]) {
+ POPUPDATAW popup;
+ popup.lchIcon = IcoLib_GetIconByHandle(Skin_GetIconHandle(SKINICON_ERROR), true);
+ wcscpy_s(popup.lpwzContactName, m_tszUserName);
+ mir_snwprintf(popup.lpwzText, TranslateT("You need to enter a captcha to join this server. Open this link in a browser."));
+ PUAddPopupW(&popup);
+ }
+ }
+}
+
INT_PTR CDiscordProto::OnMenuJoinGuild(WPARAM, LPARAM)
{
ENTER_STRING es = { m_szModuleName, "guild_name", TranslateT("Enter invitation code you received"), nullptr, ESF_COMBO, 5 };
if (EnterString(&es)) {
- CMStringA szUrl(FORMAT, "/invite/%S", es.ptszResult);
- Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, nullptr));
+ CMStringA szUrl(FORMAT, "/invites/%S", es.ptszResult);
+ Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, &CDiscordProto::OnReceiveJoin));
mir_free(es.ptszResult);
}
return 0;
@@ -96,7 +110,8 @@ INT_PTR CDiscordProto::OnMenuToggleSync(WPARAM hContact, LPARAM) if (bEnabled)
if (auto *pGuild = FindGuild(getId(hContact, DB_KEY_CHANNELID)))
- GatewaySendGuildInfo(pGuild);
+ ForkThread(&CDiscordProto::BatchChatCreate, pGuild);
+
return 0;
}
@@ -106,23 +121,23 @@ int CDiscordProto::OnMenuPrebuild(WPARAM hContact, LPARAM) {
// "Leave guild" menu item should be visible only for the guild contacts
bool bIsGuild = getByte(hContact, "ChatRoom") == 2;
- Menu_ShowItem(m_hMenuLeaveGuild, bIsGuild);
- Menu_ShowItem(m_hMenuCreateChannel, bIsGuild);
- Menu_ShowItem(m_hMenuToggleSync, bIsGuild);
- Menu_ShowItem(m_hMenuDatabaseHistory, bIsGuild);
+ Menu_ShowItem(g_hMenuLeaveGuild, bIsGuild);
+ Menu_ShowItem(g_hMenuCreateChannel, bIsGuild);
+ Menu_ShowItem(g_hMenuToggleSync, bIsGuild);
+ Menu_ShowItem(g_hMenuDatabaseHistory, bIsGuild);
if (!bIsGuild && getWord(hContact, "ApparentMode") != 0)
Menu_ShowItem(GetMenuItem(PROTO_MENU_REQ_AUTH), true);
if (getByte(hContact, DB_KEY_ENABLE_SYNC))
- Menu_ModifyItem(m_hMenuToggleSync, LPGENW("Disable sync"), Skin_GetIconHandle(SKINICON_CHAT_LEAVE));
+ Menu_ModifyItem(g_hMenuToggleSync, LPGENW("Disable sync"), Skin_GetIconHandle(SKINICON_CHAT_LEAVE));
else
- Menu_ModifyItem(m_hMenuToggleSync, LPGENW("Enable sync"), Skin_GetIconHandle(SKINICON_CHAT_JOIN));
+ Menu_ModifyItem(g_hMenuToggleSync, LPGENW("Enable sync"), Skin_GetIconHandle(SKINICON_CHAT_JOIN));
if (getByte(hContact, DB_KEY_ENABLE_HIST))
- Menu_ModifyItem(m_hMenuDatabaseHistory, LPGENW("Disable database history for a guild"), Skin_GetIconHandle(SKINICON_CHAT_LEAVE));
+ Menu_ModifyItem(g_hMenuDatabaseHistory, LPGENW("Disable database history for a guild"), Skin_GetIconHandle(SKINICON_CHAT_LEAVE));
else
- Menu_ModifyItem(m_hMenuDatabaseHistory, LPGENW("Enable database history for a guild"), Skin_GetIconHandle(SKINICON_CHAT_JOIN));
+ Menu_ModifyItem(g_hMenuDatabaseHistory, LPGENW("Enable database history for a guild"), Skin_GetIconHandle(SKINICON_CHAT_JOIN));
return 0;
}
@@ -153,47 +168,58 @@ void CDiscordProto::OnBuildProtoMenu() /////////////////////////////////////////////////////////////////////////////////////////
// Contact menu items
+static std::vector<HGENMENU> g_menuItems;
+
+static int OnPrebuildMenu(WPARAM hContact, LPARAM)
+{
+ auto *ppro = CMPlugin::getInstance(hContact);
+ for (auto &it : g_menuItems)
+ Menu_ShowItem(it, ppro != 0);
+ return 0;
+}
+
void CDiscordProto::InitMenus()
{
CMenuItem mi(&g_plugin);
- mi.pszService = "/LeaveGuild";
- CreateProtoService(mi.pszService, &CDiscordProto::OnMenuLeaveGuild);
+ mi.pszService = MODULENAME "/LeaveGuild";
+ CreateServiceFunction(mi.pszService, GlobalService<&CDiscordProto::OnMenuLeaveGuild>);
SET_UID(mi, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8C);
mi.name.a = LPGEN("Leave guild");
mi.position = -200001000;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_CHAT_LEAVE);
- m_hMenuLeaveGuild = Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_menuItems.push_back(g_hMenuLeaveGuild = Menu_AddContactMenuItem(&mi));
- mi.pszService = "/CreateChannel";
- CreateProtoService(mi.pszService, &CDiscordProto::OnMenuCreateChannel);
+ mi.pszService = MODULENAME "/CreateChannel";
+ CreateServiceFunction(mi.pszService, GlobalService<&CDiscordProto::OnMenuCreateChannel>);
SET_UID(mi, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8D);
mi.name.a = LPGEN("Create new channel");
mi.position++;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_ADDCONTACT);
- m_hMenuCreateChannel = Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_menuItems.push_back(g_hMenuCreateChannel = Menu_AddContactMenuItem(&mi));
SET_UID(mi, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8E);
- mi.pszService = "/CopyId";
+ CreateServiceFunction(mi.pszService, GlobalService<&CDiscordProto::OnMenuCopyId>);
+ mi.pszService = MODULENAME "/CopyId";
mi.name.a = LPGEN("Copy ID");
mi.position++;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_USERONLINE);
- Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_menuItems.push_back(Menu_AddContactMenuItem(&mi));
- mi.pszService = "/ToggleSync";
- CreateProtoService(mi.pszService, &CDiscordProto::OnMenuToggleSync);
+ mi.pszService = MODULENAME "/ToggleSync";
+ CreateServiceFunction(mi.pszService, GlobalService<&CDiscordProto::OnMenuToggleSync>);
SET_UID(mi, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x8F);
mi.name.a = LPGEN("Enable guild sync");
mi.position++;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_CHAT_JOIN);
- m_hMenuToggleSync = Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_menuItems.push_back(g_hMenuToggleSync = Menu_AddContactMenuItem(&mi));
- mi.pszService = "/DatabaseHistory";
- CreateProtoService(mi.pszService, &CDiscordProto::OnMenuDatabaseHistory);
+ mi.pszService = MODULENAME "/DatabaseHistory";
+ CreateServiceFunction(mi.pszService, GlobalService<&CDiscordProto::OnMenuDatabaseHistory>);
SET_UID(mi, 0x6EF11AD6, 0x6111, 0x4E29, 0xBA, 0x8B, 0xA7, 0xB2, 0xE0, 0x22, 0xE1, 0x90);
mi.name.a = LPGEN("Enable database history for a guild");
mi.position++;
mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_HISTORY);
- m_hMenuDatabaseHistory = Menu_AddContactMenuItem(&mi, m_szModuleName);
+ g_menuItems.push_back(g_hMenuDatabaseHistory = Menu_AddContactMenuItem(&mi));
- HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CDiscordProto::OnMenuPrebuild);
+ HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &OnPrebuildMenu);
}
diff --git a/protocols/Discord/src/mfa.cpp b/protocols/Discord/src/mfa.cpp index 86b37fe63d..703b0c17dd 100644 --- a/protocols/Discord/src/mfa.cpp +++ b/protocols/Discord/src/mfa.cpp @@ -80,7 +80,18 @@ public: JSONNode root; root << CHAR_PARAM("ticket", m_szTicket) << WCHAR_PARAM("code", wszCode); - auto *pReq = new AsyncHttpRequest(m_proto, REQUEST_POST, (m_mode == 1) ? "/auth/mfa/sms" : "/auth/mfa/totp", &CDiscordProto::OnSendTotp, &root); + const char *pszUrl; + switch (m_mode) { + case 0: pszUrl = "/auth/mfa/totp"; break; + case 1: pszUrl = "/auth/mfa/sms"; break; + case 2: pszUrl = "/auth/mfa/backup"; break; + default: + return false; + } + + auto *pReq = new AsyncHttpRequest(m_proto, REQUEST_POST, pszUrl, &CDiscordProto::OnSendTotp, &root); + pReq->AddHeader("Origin", "https://discord.com"); + pReq->AddHeader("Referer", "https://discord.com/login"); pReq->pUserInfo = this; m_proto->Push(pReq); return false; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index 8ebdcf45fa..8c10036837 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -44,6 +44,7 @@ static int compareCalls(const CDiscordVoiceCall *p1, const CDiscordVoiceCall *p2 CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
PROTO<CDiscordProto>(proto_name, username),
+ m_ws(this),
m_impl(*this),
m_arHttpQueue(10, compareRequests),
m_evRequestsQueue(CreateEvent(nullptr, FALSE, FALSE, nullptr)),
@@ -54,7 +55,7 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : arVoiceCalls(1, compareCalls),
m_wszEmail(this, "Email", L""),
- m_wszDefaultGroup(this, "GroupName", DB_KEYVAL_GROUP),
+ m_wszDefaultGroup(this, "GroupName", L"Discord"),
m_bSyncMarkRead(this, "SendMarkRead", true),
m_bUseGroupchats(this, "UseGroupChats", true),
m_bHideGroupchats(this, "HideChats", true),
@@ -63,7 +64,7 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : m_bSyncDeleteUsers(this, "DeleteServerUsers", true)
{
// Hidden setting!
- m_szApiUrl = getMStringA("ApiUrl", "https://discord.com/api/v10");
+ m_szApiUrl = getMStringA("ApiUrl", "https://discord.com/api/v9");
// Services
CreateProtoService(PS_GETAVATARINFO, &CDiscordProto::GetAvatarInfo);
@@ -90,7 +91,8 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : // Events
HookProtoEvent(ME_OPT_INITIALISE, &CDiscordProto::OnOptionsInit);
HookProtoEvent(ME_PROTO_ACCLISTCHANGED, &CDiscordProto::OnAccountChanged);
-
+ HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CDiscordProto::OnMenuPrebuild);
+
HookProtoEvent(PE_VOICE_CALL_STATE, &CDiscordProto::OnVoiceState);
// avatars
@@ -147,7 +149,6 @@ void CDiscordProto::OnModulesLoaded() HookProtoEvent(ME_GC_EVENT, &CDiscordProto::GroupchatEventHook);
HookProtoEvent(ME_GC_BUILDMENU, &CDiscordProto::GroupchatMenuHook);
- InitMenus();
InitVoip(true);
// Voice support
@@ -174,8 +175,8 @@ void CDiscordProto::OnShutdown() for (auto &it : arGuilds)
it->SaveToFile();
- if (m_ws)
- m_ws->terminate();
+ if (m_bConnected)
+ m_ws.terminate();
if (g_plugin.bVoiceService)
CallService(MS_VOICESERVICE_UNREGISTER, (WPARAM)m_szModuleName, 0);
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index 8342ba5724..28f2bda045 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -71,20 +71,6 @@ struct AsyncHttpRequest : public MTHttpRequest<CDiscordProto> MCONTACT hContact;
};
-class JsonReply
-{
- JSONNode *m_root = nullptr;
- int m_errorCode = 0;
-
-public:
- JsonReply(MHttpResponse *);
- ~JsonReply();
-
- __forceinline int error() const { return m_errorCode; }
- __forceinline JSONNode& data() const { return *m_root; }
- __forceinline operator bool() const { return m_errorCode == 200; }
-};
-
/////////////////////////////////////////////////////////////////////////////////////////
struct CDiscordRole : public MZeroedObject
@@ -364,9 +350,10 @@ class CDiscordProto : public PROTO<CDiscordProto> HANDLE m_hWorkerThread; // worker thread handle
HNETLIBCONN m_hAPIConnection; // working connection
- bool
+ bool
m_bOnline, // protocol is online
- m_bTerminated; // Miranda's going down
+ m_bTerminated, // Miranda's going down
+ m_bConnected; // web socket is connected
//////////////////////////////////////////////////////////////////////////////////////
// gateway
@@ -380,7 +367,7 @@ class CDiscordProto : public PROTO<CDiscordProto> m_szWSCookie; // cookie used for establishing websocket connection
HNETLIBUSER m_hGatewayNetlibUser; // the separate netlib user handle for gateways
- JsonWebSocket<CDiscordProto> *m_ws;
+ JsonWebSocket<CDiscordProto> m_ws;
void __cdecl GatewayThread(void*);
bool GatewayThreadWorker(void);
@@ -433,8 +420,10 @@ class CDiscordProto : public PROTO<CDiscordProto> //////////////////////////////////////////////////////////////////////////////////////
// menu items
- void InitMenus(void);
+public:
+ static void InitMenus(void);
+private:
int __cdecl OnMenuPrebuild(WPARAM, LPARAM);
INT_PTR __cdecl OnMenuCopyId(WPARAM, LPARAM);
@@ -445,8 +434,6 @@ class CDiscordProto : public PROTO<CDiscordProto> INT_PTR __cdecl OnMenuLoadHistory(WPARAM, LPARAM);
INT_PTR __cdecl OnMenuToggleSync(WPARAM, LPARAM);
- HGENMENU m_hMenuLeaveGuild, m_hMenuCreateChannel, m_hMenuToggleSync, m_hMenuDatabaseHistory;
-
//////////////////////////////////////////////////////////////////////////////////////
// guilds
@@ -628,6 +615,7 @@ public: void OnReceiveCreateChannel(MHttpResponse*, AsyncHttpRequest*);
void OnReceiveFile(MHttpResponse*, AsyncHttpRequest*);
void OnReceiveGateway(MHttpResponse*, AsyncHttpRequest*);
+ void OnReceiveJoin(MHttpResponse*, AsyncHttpRequest*);
void OnReceiveLogout(MHttpResponse*, AsyncHttpRequest*);
void OnReceiveMarkRead(MHttpResponse*, AsyncHttpRequest *);
void OnReceiveMessageAck(MHttpResponse*, AsyncHttpRequest*);
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp index beef589e30..dae31e4c16 100644 --- a/protocols/Discord/src/server.cpp +++ b/protocols/Discord/src/server.cpp @@ -103,7 +103,7 @@ void CDiscordProto::OnReceiveHistory(MHttpResponse *pReply, AsyncHttpRequest *pR dbei.szModule = m_szModuleName;
dbei.flags = DBEF_UTF;
dbei.eventType = EVENTTYPE_MESSAGE;
- dbei.timestamp = dwTimeStamp;
+ dbei.iTimestamp = dwTimeStamp;
if (authorid == m_ownId)
dbei.flags |= DBEF_SENT;
diff --git a/protocols/Discord/src/stdafx.h b/protocols/Discord/src/stdafx.h index 6e11d96455..646cb3f4e0 100644 --- a/protocols/Discord/src/stdafx.h +++ b/protocols/Discord/src/stdafx.h @@ -56,6 +56,7 @@ #include "opus/opus.h"
extern IconItem g_iconList[];
+extern HGENMENU g_hMenuLeaveGuild, g_hMenuCreateChannel, g_hMenuToggleSync, g_hMenuDatabaseHistory;
#define DB_KEY_ID "id"
#define DB_KEY_TOKEN "AccessToken"
@@ -73,7 +74,7 @@ extern IconItem g_iconList[]; #define DB_KEY_ENABLE_SYNC "EnableSync"
#define DB_KEY_ENABLE_HIST "EnableDbHistory"
-#define DB_KEYVAL_GROUP L"Discord"
+#define MODULENAME "Discord"
#include "version.h"
#include "proto.h"
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp index ce5a88ae58..c52c7a0c64 100644 --- a/protocols/Discord/src/utils.cpp +++ b/protocols/Discord/src/utils.cpp @@ -379,8 +379,8 @@ CMStringW CDiscordProto::PrepareMessageText(const JSONNode &pRoot, CDiscordUser T2Utf szDescr(wszText);
DB::EventInfo dbei(db_event_getById(m_szModuleName, szId));
- dbei.flags = DBEF_TEMPORARY;
- dbei.timestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring());
+ dbei.flags |= DBEF_TEMPORARY;
+ dbei.iTimestamp = (uint32_t)StringToDate(pRoot["timestamp"].as_mstring());
dbei.szId = szId;
dbei.szUserId = szUserId;
if (_atoi64(szUserId) == m_ownId)
@@ -479,7 +479,7 @@ void CDiscordProto::ProcessType(CDiscordUser *pUser, const JSONNode &pRoot) DB::AUTH_BLOB blob(pUser->hContact, T2Utf(pUser->wszUsername), nullptr, nullptr, szId, nullptr);
DB::EventInfo dbei;
- dbei.timestamp = (uint32_t)time(0);
+ dbei.iTimestamp = (uint32_t)time(0);
dbei.cbBlob = blob.size();
dbei.pBlob = blob;
ProtoChainRecv(pUser->hContact, PSR_AUTH, 0, (LPARAM)&dbei);
diff --git a/protocols/Discord/src/voice_client.cpp b/protocols/Discord/src/voice_client.cpp index 1e20a93723..99d7668d74 100644 --- a/protocols/Discord/src/voice_client.cpp +++ b/protocols/Discord/src/voice_client.cpp @@ -61,9 +61,7 @@ void CDiscordVoiceCall::write(int op, JSONNode &d) JSONNode payload; payload << INT_PARAM("op", op) << d; - auto json = payload.write(); - ppro->debugLogA("Voice JSON sent: %s", json.c_str()); mir_cslock lck(m_cs); m_ws->sendText(json.c_str()); |