summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src/process.cpp
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-11-19 11:22:31 +0000
committerRobert Pösel <robyer@seznam.cz>2014-11-19 11:22:31 +0000
commitabcda6e46fdfcb07f0c11115805131d6900e89ca (patch)
tree857f22c78ddea780a5a5eeb89e20004f0368fd12 /protocols/FacebookRM/src/process.cpp
parentcf43b9022ce2afb922ad19773ffc369b461e9a34 (diff)
Facebook: Option to log notifications into special chatroom; version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@11020 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src/process.cpp')
-rw-r--r--protocols/FacebookRM/src/process.cpp73
1 files changed, 65 insertions, 8 deletions
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 579779e201..97340db7ca 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -463,6 +463,9 @@ void FacebookProto::LoadLastMessages(void *p)
bool isChat = isChatRoom(hContact);
+ if (isSpecialChatRoom(hContact)) // e.g. nofitications
+ return;
+
if (isChat && !m_enableChat)
return;
@@ -868,15 +871,69 @@ exit:
}
void FacebookProto::ShowNotifications() {
- if (!getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE))
- return;
-
+ ScopedLock s(facy.notifications_lock_);
+
+ bool showPopups = getBool(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE);
+ bool useChatRoom = getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM);
+
+ char *notificationName = _T2A(TranslateT("Notification"), CP_UTF8);
+
+ if (useChatRoom) {
+ // Prepare chatroom if not exists
+ TCHAR *gidT = _T(FACEBOOK_NOTIFICATIONS_CHATROOM);
+
+ MCONTACT hNotificationsChatRoom = ChatIDToHContact(gidT);
+ if (hNotificationsChatRoom == NULL || getDword(hNotificationsChatRoom, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE) {
+ TCHAR nameT[200];
+ mir_sntprintf(nameT, SIZEOF(nameT), _T("%s: %s"), m_tszUserName, TranslateT("Notifications"));
+
+ // Create the group chat session
+ GCSESSION gcw = { sizeof(gcw) };
+ gcw.iType = GCW_PRIVMESS;
+ gcw.ptszID = gidT;
+ gcw.pszModule = m_szModuleName;
+ gcw.ptszName = nameT;
+ CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw);
+
+ // Send setting events
+ GCDEST gcd = { m_szModuleName, gidT, GC_EVENT_CONTROL };
+ GCEVENT gce = { sizeof(gce), &gcd };
+ gce.time = ::time(NULL);
+
+ CallServiceSync(MS_GC_EVENT, WINDOW_HIDDEN, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
+ }
+
+ hNotificationsChatRoom = ChatIDToHContact(gidT);
+ useChatRoom = (hNotificationsChatRoom != NULL && getDword(hNotificationsChatRoom, "Status", ID_STATUS_OFFLINE) == ID_STATUS_ONLINE);
+ }
+
+ // Show popups for unseen notifications and/or write them to chatroom
for (std::map<std::string, facebook_notification*>::iterator it = facy.notifications.begin(); it != facy.notifications.end(); ++it) {
- if (it->second != NULL && !it->second->seen) {
- debugLogA(" Got notification: %s", it->second->text.c_str());
- ptrT szText(mir_utf8decodeT(it->second->text.c_str()));
- it->second->hWndPopup = NotifyEvent(m_tszUserName, szText, ContactIDToHContact(it->second->user_id), FACEBOOK_EVENT_NOTIFICATION, &it->second->link, &it->second->id);
- it->second->seen = true;
+ if (it->second != NULL) {
+ if (useChatRoom && !it->second->written) {
+ it->second->written = true;
+
+ std::stringstream text;
+ text << it->second->text << "\n\n" << it->second->link;
+ UpdateChat(_T(FACEBOOK_NOTIFICATIONS_CHATROOM), ""/*it->second->user_id.c_str()*/, notificationName, text.str().c_str(), it->second->time, it->second->seen);
+ }
+
+ if (showPopups && !it->second->seen) {
+ it->second->seen = true;
+
+ debugLogA(" Showing popup for notification: %s", it->second->text.c_str());
+ ptrT szText(mir_utf8decodeT(it->second->text.c_str()));
+ it->second->hWndPopup = NotifyEvent(m_tszUserName, szText, ContactIDToHContact(it->second->user_id), FACEBOOK_EVENT_NOTIFICATION, &it->second->link, &it->second->id);
+ }
+ }
+ }
+
+ // Remove old seen and processed (without hWndPopup handle) notifications from map
+ for (std::map<std::string, facebook_notification*>::iterator it = facy.notifications.begin(); it != facy.notifications.end();) {
+ if (it->second != NULL && it->second->seen && it->second->hWndPopup == NULL) {
+ delete it->second;
+ it = facy.notifications.erase(it);
}
}
}