summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-03-21 13:26:12 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-03-21 13:26:12 +0300
commit368611ceedca2c4c37e435ee2da34775eaf06109 (patch)
tree8b96f11af067da368a8186ff739a4dac7f4b28be
parentce09a6d8185f0d9ee8c2b67969aed25e5a29eebe (diff)
Discord: fixes N/A status restoration after login
-rw-r--r--protocols/Discord/src/connection.cpp5
-rw-r--r--protocols/Discord/src/dispatch.cpp2
-rw-r--r--protocols/Discord/src/gateway.cpp11
-rw-r--r--protocols/Discord/src/proto.h4
-rw-r--r--protocols/Discord/src/server.cpp17
-rw-r--r--protocols/Discord/src/version.h2
6 files changed, 20 insertions, 21 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp
index a0b1813319..a2d7bba07c 100644
--- a/protocols/Discord/src/connection.cpp
+++ b/protocols/Discord/src/connection.cpp
@@ -75,11 +75,6 @@ void CDiscordProto::OnLoggedIn()
debugLogA("CDiscordProto::OnLoggedIn");
m_bOnline = true;
SetServerStatus(m_iDesiredStatus);
-
- if (m_szGateway.IsEmpty())
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/gateway", &CDiscordProto::OnReceiveGateway));
- else
- ForkThread(&CDiscordProto::GatewayThread, nullptr);
}
void CDiscordProto::OnLoggedOut()
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 07c13784f4..761ef6a6fe 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -508,6 +508,8 @@ void CDiscordProto::OnCommandPresence(const JSONNode &pRoot)
void CDiscordProto::OnCommandReady(const JSONNode &pRoot)
{
+ OnLoggedIn();
+
GatewaySendHeartbeat();
m_impl.m_heartBeat.StartSafe(m_iHartbeatInterval);
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp
index cfb6d82c17..a8a0ca4efa 100644
--- a/protocols/Discord/src/gateway.cpp
+++ b/protocols/Discord/src/gateway.cpp
@@ -20,14 +20,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////////
// sends a piece of JSON to a server via a websocket, masked
-void CDiscordProto::GatewaySend(const JSONNode &pRoot)
+bool CDiscordProto::GatewaySend(const JSONNode &pRoot)
{
if (m_hGatewayConnection == nullptr)
- return;
+ return false;
json_string szText = pRoot.write();
debugLogA("Gateway send: %s", szText.c_str());
WebSocket_Send(m_hGatewayConnection, szText.c_str(), szText.length());
+ return true;
}
//////////////////////////////////////////////////////////////////////////////////////
@@ -311,11 +312,11 @@ void CDiscordProto::GatewaySendResume()
GatewaySend(root);
}
-void CDiscordProto::GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText)
+bool CDiscordProto::GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText)
{
if (iStatus == ID_STATUS_OFFLINE) {
Push(new AsyncHttpRequest(this, REQUEST_POST, "/auth/logout", nullptr));
- return;
+ return true;
}
const char *pszStatus;
@@ -341,5 +342,5 @@ void CDiscordProto::GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText
}
JSONNode root; root << INT_PARAM("op", OPCODE_STATUS_UPDATE) << payload;
- GatewaySend(root);
+ return GatewaySend(root);
}
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 9dc5f19e35..4b023fde05 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -233,14 +233,14 @@ class CDiscordProto : public PROTO<CDiscordProto>
void __cdecl GatewayThread(void*);
bool GatewayThreadWorker(void);
- void GatewaySend(const JSONNode &pNode);
+ bool GatewaySend(const JSONNode &pNode);
bool GatewayProcess(const JSONNode &pNode);
void GatewaySendGuildInfo(CDiscordGuild *pGuild);
void GatewaySendHeartbeat(void);
void GatewaySendIdentify(void);
void GatewaySendResume(void);
- void GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText);
+ bool GatewaySendStatus(int iStatus, const wchar_t *pwszStatusText);
GatewayHandlerFunc GetHandler(const wchar_t*);
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index ee568d4be3..28aa0f12f8 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -187,7 +187,11 @@ void CDiscordProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*
}
}
- OnLoggedIn();
+ // launch gateway thread
+ if (m_szGateway.IsEmpty())
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/gateway", &CDiscordProto::OnReceiveGateway));
+ else
+ ForkThread(&CDiscordProto::GatewayThread, nullptr);
CheckAvatarChange(0, data["avatar"].as_mstring());
}
@@ -212,13 +216,10 @@ void CDiscordProto::OnReceiveGateway(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest
void CDiscordProto::SetServerStatus(int iStatus)
{
- if (!m_bOnline)
- return;
-
- GatewaySendStatus(iStatus, nullptr);
-
- int iOldStatus = m_iStatus; m_iStatus = iStatus;
- ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus);
+ if (GatewaySendStatus(iStatus, nullptr)) {
+ int iOldStatus = m_iStatus; m_iStatus = iStatus;
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus);
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index 13d0a5f8ba..10427dc97f 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 6
#define __RELEASE_NUM 2
-#define __BUILD_NUM 7
+#define __BUILD_NUM 8
#include <stdver.h>