summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-02-11 22:07:42 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-02-11 22:07:42 +0300
commite97d67ed64ca40a146cd3329e36b060c89f3bc60 (patch)
treea2006480a80479eb79015e81807502d1bf9ddb55
parentea22a022d6d370c0aa82b93c4b97e09ac11ae0d0 (diff)
Discord:
- support for group chat topics; - version bump
-rw-r--r--protocols/Discord/src/dispatch.cpp30
-rw-r--r--protocols/Discord/src/groupchat.cpp19
-rw-r--r--protocols/Discord/src/proto.h1
-rw-r--r--protocols/Discord/src/version.h2
4 files changed, 48 insertions, 4 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index e28f6f70d2..1f4f9b3993 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -30,6 +30,7 @@ static handlers[] = // these structures must me sorted alphabetically
{
{ L"CHANNEL_CREATE", &CDiscordProto::OnCommandChannelCreated },
{ L"CHANNEL_DELETE", &CDiscordProto::OnCommandChannelDeleted },
+ { L"CHANNEL_UPDATE", &CDiscordProto::OnCommandChannelUpdated },
{ L"GUILD_CREATE", &CDiscordProto::OnCommandGuildCreate },
{ L"GUILD_DELETE", &CDiscordProto::OnCommandGuildDelete },
@@ -89,6 +90,25 @@ void CDiscordProto::OnCommandChannelDeleted(const JSONNode &pRoot)
}
}
+void CDiscordProto::OnCommandChannelUpdated(const JSONNode &pRoot)
+{
+ CDiscordUser *pUser = FindUserByChannel(::getId(pRoot["id"]));
+ if (pUser == NULL)
+ return;
+
+ pUser->lastMessageId = ::getId(pRoot["last_message_id"]);
+
+ CMStringW wszTopic = pRoot["topic"].as_mstring();
+ if (!wszTopic.IsEmpty()) {
+ Chat_SetStatusbarText(m_szModuleName, pUser->wszUsername, wszTopic);
+
+ GCDEST gcd = { m_szModuleName, pUser->wszUsername, GC_EVENT_TOPIC };
+ GCEVENT gce = { &gcd };
+ gce.ptszText = wszTopic;
+ Chat_Event(&gce);
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// reading a new message
@@ -158,6 +178,7 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
CMStringW wszChannelName = pch["name"].as_mstring();
CMStringW wszChannelId = pch["id"].as_mstring();
+ CMStringW wszTopic = pch["topic"].as_mstring();
SnowFlake channelId = _wtoi64(wszChannelId);
si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszChannelId, wszGuildName + L"#" + wszChannelName);
@@ -165,6 +186,15 @@ void CDiscordProto::ProcessGuild(const JSONNode &readState, const JSONNode &p)
Chat_Control(m_szModuleName, wszChannelId, WINDOW_HIDDEN);
Chat_Control(m_szModuleName, wszChannelId, SESSION_ONLINE);
+ if (!wszTopic.IsEmpty()) {
+ Chat_SetStatusbarText(m_szModuleName, wszChannelId, wszTopic);
+
+ GCDEST gcd = { m_szModuleName, wszChannelId, GC_EVENT_TOPIC };
+ GCEVENT gce = { &gcd };
+ gce.ptszText = wszTopic;
+ Chat_Event(&gce);
+ }
+
CDiscordUser *pUser = FindUserByChannel(channelId);
if (pUser == NULL) {
// missing channel - create it
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index 13c2690bd2..5525f6658f 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -20,12 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
enum {
IDM_CANCEL,
- IDM_CHANGENICK, IDM_INVITE
+ IDM_CHANGENICK, IDM_CHANGETOPIC, IDM_INVITE
};
static gc_item sttLogListItems[] =
{
{ LPGENW("Change &nickname"), IDM_CHANGENICK, MENU_ITEM },
+ { LPGENW("Change &topic"), IDM_CHANGETOPIC, MENU_ITEM },
+ { L"", 100, MENU_SEPARATOR, FALSE },
{ LPGENW("&Invite a user"), IDM_INVITE, MENU_ITEM },
};
@@ -82,12 +84,23 @@ void CDiscordProto::Chat_ProcessLogMenu(GCHOOK *gch)
if (pUser == NULL)
return;
+ ENTER_STRING es = { sizeof(es) };
+
switch (gch->dwData) {
- case IDM_INVITE:
+ case IDM_CHANGETOPIC:
+ es.caption = TranslateT("Enter new topic:");
+ es.type = ESF_RICHEDIT;
+ es.szModuleName = m_szModuleName;
+ es.szDataPrefix = "chat_topic";
+ if (EnterString(&es)) {
+ JSONNode root; root << WCHAR_PARAM("topic", es.ptszResult);
+ CMStringA szUrl(FORMAT, "/channels/%S", pUser->wszUsername);
+ Push(new AsyncHttpRequest(this, REQUEST_PATCH, szUrl, NULL, &root));
+ mir_free(es.ptszResult);
+ }
break;
case IDM_CHANGENICK:
- ENTER_STRING es = { sizeof(es) };
es.caption = TranslateT("Enter your new nick name:");
es.type = ESF_COMBO;
es.szModuleName = m_szModuleName;
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index fea2cf5ee7..29c0319719 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -260,6 +260,7 @@ public:
// dispatch commands
void OnCommandChannelCreated(const JSONNode&);
void OnCommandChannelDeleted(const JSONNode&);
+ void OnCommandChannelUpdated(const JSONNode&);
void OnCommandGuildCreate(const JSONNode&);
void OnCommandGuildDelete(const JSONNode&);
void OnCommandGuildRemoveMember(const JSONNode&);
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index ec797c4ed4..1844aa3c1e 100644
--- a/protocols/Discord/src/version.h
+++ b/protocols/Discord/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 3
#define __RELEASE_NUM 1
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>