summaryrefslogtreecommitdiff
path: root/protocols/Discord/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-27 20:53:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-27 20:53:06 +0300
commitda2c4abfc249d194d36b4bdc5dca1b711a9685f1 (patch)
treedc6df2f697cfcbcbdb71616cc8719e62600195fa /protocols/Discord/src
parente2135de541615dbae15e5f714d7658130334656c (diff)
fixes #1782 (highlighting in Discord groupchats)
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r--protocols/Discord/src/groupchat.cpp36
-rw-r--r--protocols/Discord/src/guilds.cpp6
-rw-r--r--protocols/Discord/src/utils.cpp2
-rw-r--r--protocols/Discord/src/version.h2
4 files changed, 34 insertions, 12 deletions
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index a612704f7c..babe48803a 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -157,17 +157,35 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam)
switch (gch->iType) {
case GC_USER_MESSAGE:
- if (mir_wstrlen(gch->ptszText) > 0) {
- rtrimw(gch->ptszText);
+ if (m_bOnline && mir_wstrlen(gch->ptszText) > 0) {
+ CMStringW wszText(gch->ptszText);
+ wszText.TrimRight();
+
+ int pos = wszText.Find(':');
+ if (pos != -1) {
+ auto wszWord = wszText.Left(pos);
+ wszWord.Trim();
+ if (auto *si = g_chatApi.SM_FindSession(gch->ptszID, gch->pszModule)) {
+ USERINFO *pUser = nullptr;
+
+ for (auto &U : si->getUserList())
+ if (wszWord == U->pszNick) {
+ pUser = U;
+ break;
+ }
+
+ if (pUser) {
+ wszText.Delete(0, pos);
+ wszText.Insert(0, L"<@" + CMStringW(pUser->pszUID) + L">");
+ }
+ }
+ }
- if (m_bOnline) {
- wchar_t *wszText = NEWWSTR_ALLOCA(gch->ptszText);
- Chat_UnescapeTags(wszText);
+ Chat_UnescapeTags(wszText.GetBuffer());
- JSONNode body; body << WCHAR_PARAM("content", wszText);
- CMStringA szUrl(FORMAT, "/channels/%S/messages", gch->ptszID);
- Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, nullptr, &body));
- }
+ JSONNode body; body << WCHAR_PARAM("content", wszText);
+ CMStringA szUrl(FORMAT, "/channels/%S/messages", gch->ptszID);
+ Push(new AsyncHttpRequest(this, REQUEST_POST, szUrl, nullptr, &body));
}
break;
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index 5cda9d41e8..da7b4a7441 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -244,7 +244,11 @@ void CDiscordProto::AddGuildUser(CDiscordGuild *pGuild, const CDiscordGuildMembe
wchar_t wszUserId[100];
_i64tow_s(pUser.userId, wszUserId, _countof(wszUserId), 10);
- g_chatApi.UM_AddUser(pGuild->pParentSi, wszUserId, pUser.wszNick, (pStatus) ? pStatus->iStatus : 0)->iStatusEx = flags;
+
+ auto *p = g_chatApi.UM_AddUser(pGuild->pParentSi, wszUserId, pUser.wszNick, (pStatus) ? pStatus->iStatus : 0);
+ p->iStatusEx = flags;
+ if (pUser.userId == m_ownId)
+ pGuild->pParentSi->pMe = p;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index 0a9c47e5ff..8735b2bffe 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -268,7 +268,7 @@ void CDiscordProto::ParseSpecialChars(SESSION_INFO *si, CMStringW &str)
USERINFO *ui = g_chatApi.UM_FindUser(si, wszWord.c_str() + iStart);
if (ui != nullptr)
- str.Replace(L"<" + wszWord + L">", CMStringW('@') + ui->pszNick);
+ str.Replace(L"<" + wszWord + L">", CMStringW(ui->pszNick) + L": ");
}
else if (wszWord[0] == '#') {
CDiscordUser *pUser = FindUserByChannel(_wtoi64(wszWord.c_str() + 1));
diff --git a/protocols/Discord/src/version.h b/protocols/Discord/src/version.h
index 99ce3845fa..970893d9dd 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 1
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>