summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-10 14:30:56 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-10 14:30:56 +0300
commit21ffdeca1a3f8d9f65dc9b33d9b2379ba0f1a4ac (patch)
treeca9605417b7b53fb3a9cba503371054d2704f14a
parenta223e58bdb2838350395d723c12f4a3bd76f3453 (diff)
for #629: message removing for Discord
-rw-r--r--protocols/Discord/src/proto.cpp198
-rw-r--r--protocols/Discord/src/proto.h2
-rw-r--r--src/mir_app/src/clui.cpp8
3 files changed, 115 insertions, 93 deletions
diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp
index 7d260bf6dd..4c129de23b 100644
--- a/protocols/Discord/src/proto.cpp
+++ b/protocols/Discord/src/proto.cpp
@@ -63,7 +63,9 @@ CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) :
CreateProtoService(PS_SETMYAVATAR, &CDiscordProto::SetMyAvatar);
CreateProtoService(PS_MENU_REQAUTH, &CDiscordProto::RequestFriendship);
+
CreateProtoService(PS_MENU_LOADHISTORY, &CDiscordProto::OnMenuLoadHistory);
+ CreateProtoService(PS_EMPTY_SRV_HISTORY, &CDiscordProto::SvcEmptyServerHistory);
CreateProtoService(PS_LEAVECHAT, &CDiscordProto::SvcLeaveChat);
@@ -268,97 +270,10 @@ int CDiscordProto::SetStatus(int iNewStatus)
return 0;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static INT_PTR CALLBACK AdvancedSearchDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SetFocus(GetDlgItem(hwndDlg, IDC_NICK));
- return TRUE;
-
- case WM_COMMAND:
- if (HIWORD(wParam) == EN_SETFOCUS)
- PostMessage(GetParent(hwndDlg), WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndDlg);
- }
- return FALSE;
-}
-
-HWND CDiscordProto::CreateExtendedSearchUI(HWND hwndParent)
-{
- if (hwndParent)
- return CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EXTSEARCH), hwndParent, AdvancedSearchDlgProc, 0);
-
- return nullptr;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-void CDiscordProto::SearchThread(void *param)
-{
- Sleep(100);
-
- PROTOSEARCHRESULT psr = { 0 };
- psr.cbSize = sizeof(psr);
- psr.flags = PSR_UNICODE;
- psr.nick.w = (wchar_t*)param;
- psr.firstName.w = L"";
- psr.lastName.w = L"";
- psr.id.w = L"";
- ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, this, (LPARAM)&psr);
-
- ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, this, 0);
- mir_free(param);
-}
-
-HANDLE CDiscordProto::SearchAdvanced(HWND hwndDlg)
-{
- if (!m_bOnline || !IsWindow(hwndDlg))
- return nullptr;
-
- wchar_t wszNick[200];
- GetDlgItemTextW(hwndDlg, IDC_NICK, wszNick, _countof(wszNick));
- if (wszNick[0] == 0) // empty string? reject
- return nullptr;
-
- wchar_t *p = wcschr(wszNick, '#');
- if (p == nullptr) // wrong user id
- return nullptr;
-
- ForkThread(&CDiscordProto::SearchThread, mir_wstrdup(wszNick));
- return this;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// Basic search - by SnowFlake
-
-void CDiscordProto::OnReceiveUserinfo(MHttpResponse *pReply, AsyncHttpRequest*)
-{
- JsonReply root(pReply);
- if (!root) {
- ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_FAILED, this);
- return;
- }
-
- ForkThread(&CDiscordProto::SearchThread, getNick(root.data()).Detach());
-}
-
-HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId)
-{
- if (!m_bOnline)
- return nullptr;
-
- CMStringA szUrl = "/users/";
- szUrl.AppendFormat(ptrA(mir_utf8encodeW(wszId)));
- Push(new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveUserinfo));
- return (HANDLE)1; // Success
-}
-
////////////////////////////////////////////////////////////////////////////////////////
// Authorization
-int CDiscordProto::AuthRequest(MCONTACT hContact, const wchar_t*)
+int CDiscordProto::AuthRequest(MCONTACT hContact, const wchar_t *)
{
ptrW wszUsername(getWStringA(hContact, DB_KEY_NICK));
int iDiscriminator(getDword(hContact, DB_KEY_DISCR, -1));
@@ -390,7 +305,7 @@ int CDiscordProto::Authorize(MEVENT hDbEvent)
return 0;
}
-int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*)
+int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t *)
{
DB::EventInfo dbei;
dbei.cbBlob = -1;
@@ -403,6 +318,31 @@ int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*)
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static INT_PTR CALLBACK AdvancedSearchDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ SetFocus(GetDlgItem(hwndDlg, IDC_NICK));
+ return TRUE;
+
+ case WM_COMMAND:
+ if (HIWORD(wParam) == EN_SETFOCUS)
+ PostMessage(GetParent(hwndDlg), WM_COMMAND, MAKEWPARAM(0, EN_SETFOCUS), (LPARAM)hwndDlg);
+ }
+ return FALSE;
+}
+
+HWND CDiscordProto::CreateExtendedSearchUI(HWND hwndParent)
+{
+ if (hwndParent)
+ return CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EXTSEARCH), hwndParent, AdvancedSearchDlgProc, 0);
+
+ return nullptr;
+}
+
////////////////////////////////////////////////////////////////////////////////////////
MCONTACT CDiscordProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
@@ -458,6 +398,68 @@ MCONTACT CDiscordProto::AddToListByEvent(int flags, int, MEVENT hDbEvent)
return blob.get_contact();
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDiscordProto::SearchThread(void *param)
+{
+ Sleep(100);
+
+ PROTOSEARCHRESULT psr = { 0 };
+ psr.cbSize = sizeof(psr);
+ psr.flags = PSR_UNICODE;
+ psr.nick.w = (wchar_t *)param;
+ psr.firstName.w = L"";
+ psr.lastName.w = L"";
+ psr.id.w = L"";
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, this, (LPARAM)&psr);
+
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, this, 0);
+ mir_free(param);
+}
+
+HANDLE CDiscordProto::SearchAdvanced(HWND hwndDlg)
+{
+ if (!m_bOnline || !IsWindow(hwndDlg))
+ return nullptr;
+
+ wchar_t wszNick[200];
+ GetDlgItemTextW(hwndDlg, IDC_NICK, wszNick, _countof(wszNick));
+ if (wszNick[0] == 0) // empty string? reject
+ return nullptr;
+
+ wchar_t *p = wcschr(wszNick, '#');
+ if (p == nullptr) // wrong user id
+ return nullptr;
+
+ ForkThread(&CDiscordProto::SearchThread, mir_wstrdup(wszNick));
+ return this;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Basic search - by SnowFlake
+
+void CDiscordProto::OnReceiveUserinfo(MHttpResponse *pReply, AsyncHttpRequest *)
+{
+ JsonReply root(pReply);
+ if (!root) {
+ ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_FAILED, this);
+ return;
+ }
+
+ ForkThread(&CDiscordProto::SearchThread, getNick(root.data()).Detach());
+}
+
+HANDLE CDiscordProto::SearchBasic(const wchar_t *wszId)
+{
+ if (!m_bOnline)
+ return nullptr;
+
+ CMStringA szUrl = "/users/";
+ szUrl.AppendFormat(ptrA(mir_utf8encodeW(wszId)));
+ Push(new AsyncHttpRequest(this, REQUEST_GET, szUrl, &CDiscordProto::OnReceiveUserinfo));
+ return (HANDLE)1; // Success
+}
+
////////////////////////////////////////////////////////////////////////////////////////
// SendMsg
@@ -643,8 +645,26 @@ bool CDiscordProto::OnContactDeleted(MCONTACT hContact, uint32_t flags)
return true;
}
+void CDiscordProto::OnEventDeleted(MCONTACT hContact, MEVENT hEvent, int flags)
+{
+ // the command arrived from the server, don't send it back then
+ if (!(flags & CDF_DEL_HISTORY))
+ return;
+
+ DB::EventInfo dbei(hEvent, false);
+ if (dbei && dbei.szId) {
+ CMStringA szUrl(FORMAT, "/channels/%lld/messages/%s", getId(hContact, DB_KEY_ID), dbei.szId);
+ Push(new AsyncHttpRequest(this, REQUEST_DELETE, szUrl, 0));
+ }
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
+INT_PTR CDiscordProto::CDiscordProto::SvcEmptyServerHistory(WPARAM, LPARAM)
+{
+ return 0;
+}
+
INT_PTR CDiscordProto::RequestFriendship(WPARAM hContact, LPARAM)
{
AuthRequest(hContact, 0);
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 7099600f52..53eac9d78d 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -452,6 +452,7 @@ public:
void OnBuildProtoMenu() override;
bool OnContactDeleted(MCONTACT, uint32_t flags) override;
+ void OnEventDeleted(MCONTACT, MEVENT, int flags) override;
MWindow OnCreateAccMgrUI(MWindow) override;
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
@@ -463,6 +464,7 @@ public:
INT_PTR __cdecl RequestFriendship(WPARAM, LPARAM);
INT_PTR __cdecl SvcLeaveChat(WPARAM, LPARAM);
+ INT_PTR __cdecl SvcEmptyServerHistory(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarCaps(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
diff --git a/src/mir_app/src/clui.cpp b/src/mir_app/src/clui.cpp
index 568d839e17..3f8cc664c2 100644
--- a/src/mir_app/src/clui.cpp
+++ b/src/mir_app/src/clui.cpp
@@ -128,7 +128,7 @@ static INT_PTR MenuItem_RenameContact(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-class CDeleteDlg : public CDlgBase
+class CDeleteContactDlg : public CDlgBase
{
MCONTACT m_hContact;
CCtrlCheck chkDelContact, chkDelHistory, chkForEveryone;
@@ -138,7 +138,7 @@ public:
bool bDelContact = true, bDelHistory = false, bForEveryone = false;
bool bHasServer, bHasHistory;
- CDeleteDlg(MCONTACT hContact) :
+ CDeleteContactDlg(MCONTACT hContact) :
CDlgBase(g_plugin, IDD_DELETECONTACT),
m_hContact(hContact),
chkDelContact(this, IDC_DELSERVERCONTACT),
@@ -150,7 +150,7 @@ public:
bHasHistory = ProtoServiceExists(szProto, PS_EMPTY_SRV_HISTORY);
bForEveryone = (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4) & PF4_DELETEFORALL) != 0;
- chkDelHistory.OnChange = Callback(this, &CDeleteDlg::onChange_Server);
+ chkDelHistory.OnChange = Callback(this, &CDeleteContactDlg::onChange_Server);
}
bool OnInitDialog() override
@@ -204,7 +204,7 @@ public:
static INT_PTR MenuItem_DeleteContact(WPARAM hContact, LPARAM lParam)
{
- CDeleteDlg dlg(hContact);
+ CDeleteContactDlg dlg(hContact);
if (dlg.szProto == nullptr)
return 0;