summaryrefslogtreecommitdiff
path: root/protocols/ICQ-WIM
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-10 23:09:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-10 23:09:50 +0300
commit7346b03e8c19eb1c99aa7cb64948c662194ff83d (patch)
tree6456dce415e70ac9a6c98f00e9f8b96993fc87f8 /protocols/ICQ-WIM
parent3ed82dc60191a4bee2a1d59e9da51b5106d019fb (diff)
fixes #1835 (basic support for MRA mail notifications: displays unread message count, incoming emails, popups)
Diffstat (limited to 'protocols/ICQ-WIM')
-rw-r--r--protocols/ICQ-WIM/src/poll.cpp40
-rw-r--r--protocols/ICQ-WIM/src/proto.cpp18
-rw-r--r--protocols/ICQ-WIM/src/proto.h8
-rw-r--r--protocols/ICQ-WIM/src/stdafx.h2
4 files changed, 66 insertions, 2 deletions
diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp
index 907505dc28..d417b09d9c 100644
--- a/protocols/ICQ-WIM/src/poll.cpp
+++ b/protocols/ICQ-WIM/src/poll.cpp
@@ -108,6 +108,8 @@ void CIcqProto::ProcessEvent(const JSONNode &ev)
ProcessGroupChat(pData);
else if (szType == L"myInfo")
ProcessMyInfo(pData);
+ else if (szType == L"notification")
+ ProcessNotification(pData);
else if (szType == L"permitDeny")
ProcessPermissions(pData);
else if (szType == L"presence")
@@ -198,6 +200,44 @@ void CIcqProto::ProcessMyInfo(const JSONNode &ev)
CheckAvatarChange(0, ev);
}
+void CIcqProto::ProcessNotification(const JSONNode &ev)
+{
+ for (auto &fld : ev["fields"]) {
+ const JSONNode &email = fld["mailbox.newMessage"];
+ if (email) {
+ CMStringW wszFrom(email["from"].as_mstring());
+ CMStringW wszSubj(email["subject"].as_mstring());
+ m_unreadEmails = email["unreadCount"].as_int();
+
+ POPUPDATAT Popup = {};
+ mir_snwprintf(Popup.lptzText, LPGENW("You received e-mail from %s: %s"), wszFrom.c_str(), wszSubj.c_str());
+ Popup.lchIcon = IcoLib_GetIconByHandle(Skin_GetIconHandle(SKINICON_EVENT_MESSAGE), true);
+ if (g_bPopupService) {
+ wcsncpy_s(Popup.lptzContactName, m_tszUserName, _TRUNCATE);
+ CallService(MS_POPUP_ADDPOPUPT, (WPARAM)&Popup, 0);
+ }
+
+ char szServiceFunction[MAX_PATH];
+ mir_snprintf(szServiceFunction, "%s%s", m_szModuleName, PS_GOTO_INBOX);
+
+ CLISTEVENT cle = {};
+ cle.lpszProtocol = m_szModuleName;
+ cle.hIcon = Popup.lchIcon;
+ cle.flags = (CLEF_UNICODE | CLEF_PROTOCOLGLOBAL);
+ cle.pszService = szServiceFunction;
+ cle.szTooltip.w = Popup.lptzText;
+ g_clistApi.pfnAddEvent(&cle);
+ }
+
+ const JSONNode &status = fld["mailbox.status"];
+ if (status) {
+ JSONROOT root(status.as_string().c_str());
+ m_szMailBox = (*root)["email"].as_mstring();
+ m_unreadEmails = (*root)["unreadCount"].as_int();
+ }
+ }
+}
+
void CIcqProto::ProcessPresence(const JSONNode &ev)
{
CMStringW aimId = ev["aimId"].as_mstring();
diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp
index ac606ddf58..8ad2ba6d12 100644
--- a/protocols/ICQ-WIM/src/proto.cpp
+++ b/protocols/ICQ-WIM/src/proto.cpp
@@ -58,9 +58,11 @@ CIcqProto::CIcqProto(const char* aProtoName, const wchar_t* aUserName) :
// services
CreateProtoService(PS_CREATEACCMGRUI, &CIcqProto::CreateAccMgrUI);
+ CreateProtoService(PS_GETAVATARCAPS, &CIcqProto::GetAvatarCaps);
CreateProtoService(PS_GETAVATARINFO, &CIcqProto::GetAvatarInfo);
CreateProtoService(PS_GETMYAVATAR, &CIcqProto::GetAvatar);
- CreateProtoService(PS_GETAVATARCAPS, &CIcqProto::GetAvatarCaps);
+ CreateProtoService(PS_GETUNREADEMAILCOUNT, &CIcqProto::GetEmailCount);
+ CreateProtoService(PS_GOTO_INBOX, &CIcqProto::GotoInbox);
CreateProtoService(PS_SETMYAVATAR, &CIcqProto::SetAvatar);
// events
@@ -182,6 +184,20 @@ INT_PTR CIcqProto::UploadGroups(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
+INT_PTR CIcqProto::GetEmailCount(WPARAM, LPARAM)
+{
+ if (!m_bOnline)
+ return 0;
+ return m_unreadEmails;
+}
+
+INT_PTR CIcqProto::GotoInbox(WPARAM, LPARAM)
+{
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
int CIcqProto::OnContactMenu(WPARAM hContact, LPARAM)
{
Menu_ShowItem(g_plugin.m_hmiRoot, true);
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index dd241ad8fa..325c745a32 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -37,6 +37,8 @@
#define ICQ_API_SERVER "https://api.icq.net"
#define ICQ_ROBUST_SERVER "https://rapi.icq.net"
+#define PS_GOTO_INBOX "/GotoInbox"
+
#define WIM_CAP_VOIP_VOICE "094613504c7f11d18222444553540000"
#define WIM_CAP_VOIP_VIDEO "094613514c7f11d18222444553540000"
#define WIM_CAP_FILETRANSFER "094613434c7f11d18222444553540000"
@@ -201,6 +203,7 @@ class CIcqProto : public PROTO<CIcqProto>
void ProcessHistData(const JSONNode&);
void ProcessImState(const JSONNode&);
void ProcessMyInfo(const JSONNode&);
+ void ProcessNotification(const JSONNode&);
void ProcessPermissions(const JSONNode&);
void ProcessPresence(const JSONNode&);
void ProcessTyping(const JSONNode&);
@@ -220,6 +223,9 @@ class CIcqProto : public PROTO<CIcqProto>
CIcqDlgBase *m_pdlgEditIgnore;
+ int m_unreadEmails = -1;
+ CMStringA m_szMailBox;
+
////////////////////////////////////////////////////////////////////////////////////////
// group chats
@@ -276,6 +282,8 @@ class CIcqProto : public PROTO<CIcqProto>
INT_PTR __cdecl CreateAccMgrUI(WPARAM, LPARAM);
INT_PTR __cdecl EditIgnoreList(WPARAM, LPARAM);
+ INT_PTR __cdecl GetEmailCount(WPARAM, LPARAM);
+ INT_PTR __cdecl GotoInbox(WPARAM, LPARAM);
INT_PTR __cdecl UploadGroups(WPARAM, LPARAM);
////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h
index 1116920bfc..8725dfd75b 100644
--- a/protocols/ICQ-WIM/src/stdafx.h
+++ b/protocols/ICQ-WIM/src/stdafx.h
@@ -45,7 +45,7 @@
#include <newpluginapi.h> // This must be included first
#include <m_avatars.h>
#include <m_chat_int.h>
-#include <m_clist.h>
+#include <m_clistint.h>
#include <m_database.h>
#include <m_gui.h>
#include <m_idle.h>