summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-11-06 14:31:05 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-11-06 14:31:05 +0300
commit0b1fce4ee4946e93b4130563d3fa07da80e1ab82 (patch)
tree2bedefea3c6b93b623af117a96fba0a96fd23946 /protocols
parentb8e8c2328b1b69f6eb82851731b3bb5702007400 (diff)
fixes #2117 ([Discord] Support for the newly introduced Custom Status)
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/proto.cpp45
-rw-r--r--protocols/Discord/src/proto.h38
2 files changed, 66 insertions, 17 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 355ffd9d7a..b8948afe17 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -92,6 +92,9 @@ CDiscordProto::~CDiscordProto()
{
debugLogA("CDiscordProto::~CDiscordProto");
+ for (auto &msg : m_wszStatusMsg)
+ mir_free(msg);
+
arUsers.destroy();
m_arHttpQueue.destroy();
@@ -152,7 +155,7 @@ INT_PTR CDiscordProto::GetCaps(int type, MCONTACT)
{
switch (type) {
case PFLAGNUM_1:
- return PF1_IM | PF1_MODEMSGRECV | PF1_SERVERCLIST | PF1_BASICSEARCH | PF1_EXTSEARCH | PF1_ADDSEARCHRES | PF1_FILESEND;
+ return PF1_IM | PF1_MODEMSG | PF1_MODEMSGRECV | PF1_SERVERCLIST | PF1_BASICSEARCH | PF1_EXTSEARCH | PF1_ADDSEARCHRES | PF1_FILESEND;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_HEAVYDND | PF2_INVISIBLE;
case PFLAGNUM_3:
@@ -415,6 +418,46 @@ int CDiscordProto::SendMsg(MCONTACT hContact, int /*flags*/, const char *pszSrc)
/////////////////////////////////////////////////////////////////////////////////////////
+void __cdecl CDiscordProto::GetAwayMsgThread(void *param)
+{
+ Thread_SetName("Jabber: GetAwayMsgThread");
+
+ auto *pUser = (CDiscordUser *)param;
+ if (pUser != nullptr) {
+ if (!pUser->wszTopic.IsEmpty()) {
+ ProtoBroadcastAck(pUser->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)pUser->wszTopic.c_str());
+ return;
+ }
+ }
+
+ ProtoBroadcastAck(pUser->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, 0);
+}
+
+HANDLE CDiscordProto::GetAwayMsg(MCONTACT hContact)
+{
+ ForkThread(&CDiscordProto::GetAwayMsgThread, FindUser(getId(hContact, DB_KEY_ID)));
+ return (HANDLE)1;
+}
+
+int CDiscordProto::SetAwayMsg(int iStatus, const wchar_t *msg)
+{
+ if (iStatus < ID_STATUS_MIN || iStatus > ID_STATUS_MAX)
+ return 0;
+
+ wchar_t *&pwszMessage = m_wszStatusMsg[iStatus - ID_STATUS_MIN];
+ if (!mir_wstrcmp(msg, pwszMessage))
+ return 0;
+
+ pwszMessage = mir_wstrdup(msg);
+
+ JSONNode status; status.set_name("custom_status"); status << WCHAR_PARAM("text", msg);
+ JSONNode root; root << status;
+ Push(new AsyncHttpRequest(this, REQUEST_PATCH, "/users/@me/settings", nullptr, &root));
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
int CDiscordProto::UserIsTyping(MCONTACT hContact, int type)
{
if (type == PROTOTYPE_SELFTYPING_ON) {
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 028829e91c..2190ee31a7 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -126,6 +126,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void __cdecl SearchThread(void *param);
void __cdecl SendMessageAckThread(void* param);
void __cdecl BatchChatCreate(void* param);
+ void __cdecl GetAwayMsgThread(void *param);
//////////////////////////////////////////////////////////////////////////////////////
// session control
@@ -133,6 +134,8 @@ class CDiscordProto : public PROTO<CDiscordProto>
void ConnectionFailed(int iReason);
void ShutdownSession(void);
+ wchar_t *m_wszStatusMsg[MAX_STATUS_COUNT];
+
ptrA m_szAccessToken, m_szAccessCookie;
mir_cs m_csHttpQueue;
@@ -263,31 +266,34 @@ public:
//////////////////////////////////////////////////////////////////////////////////////
// PROTO_INTERFACE
- INT_PTR GetCaps(int, MCONTACT = 0) override;
+ INT_PTR GetCaps(int, MCONTACT = 0) override;
- HWND CreateExtendedSearchUI(HWND owner) override;
- HWND SearchAdvanced(HWND owner) override;
+ HWND CreateExtendedSearchUI(HWND owner) override;
+ HWND SearchAdvanced(HWND owner) override;
- HANDLE SearchBasic(const wchar_t *id) override;
+ HANDLE SearchBasic(const wchar_t *id) override;
MCONTACT AddToList(int flags, PROTOSEARCHRESULT *psr) override;
- int AuthRecv(MCONTACT, PROTORECVEVENT *pre) override;
- int Authorize(MEVENT hDbEvent) override;
- int AuthDeny(MEVENT hDbEvent, const wchar_t* szReason) override;
- int AuthRequest(MCONTACT hContact, const wchar_t*) override;
+ int AuthRecv(MCONTACT, PROTORECVEVENT *pre) override;
+ int Authorize(MEVENT hDbEvent) override;
+ int AuthDeny(MEVENT hDbEvent, const wchar_t* szReason) override;
+ int AuthRequest(MCONTACT hContact, const wchar_t*) override;
+
+ HANDLE GetAwayMsg(MCONTACT hContact) override;
+ int SetAwayMsg(int iStatus, const wchar_t *msg) override;
- int SendMsg(MCONTACT hContact, int flags, const char *pszSrc) override;
+ int SendMsg(MCONTACT hContact, int flags, const char *pszSrc) override;
- HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
+ HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
- int UserIsTyping(MCONTACT hContact, int type) override;
+ int UserIsTyping(MCONTACT hContact, int type) override;
- int SetStatus(int iNewStatus) override;
+ int SetStatus(int iNewStatus) override;
- void OnBuildProtoMenu() override;
- void OnContactDeleted(MCONTACT) override;
- void OnModulesLoaded() override;
- void OnShutdown() override;
+ void OnBuildProtoMenu() override;
+ void OnContactDeleted(MCONTACT) override;
+ void OnModulesLoaded() override;
+ void OnShutdown() override;
//////////////////////////////////////////////////////////////////////////////////////
// Services