From a75ba12d58c579bd1a193c01d452db6cb295ae7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 20 Nov 2014 11:49:22 +0000 Subject: Facebook: Refactor whole groupchat with notifications This fix crash on right-click to notification popup and problem with not working notifications count in statusbar git-svn-id: http://svn.miranda-ng.org/main/trunk@11028 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/chat.cpp | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'protocols/FacebookRM/src/chat.cpp') diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index 684abe0671..d7d725917a 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -385,10 +385,51 @@ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam) return 0; } -bool FacebookProto::isSpecialChatRoom(MCONTACT hContact) { +bool FacebookProto::IsSpecialChatRoom(MCONTACT hContact) { if (!isChatRoom(hContact)) return false; ptrT idT(getTStringA(hContact, "ChatRoomID")); return idT && !_tcscmp(idT, _T(FACEBOOK_NOTIFICATIONS_CHATROOM)); +} + +void FacebookProto::PrepareNotificationsChatRoom() { + if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM)) + return; + + // Prepare notifications 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(&gce)); + CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast(&gce)); + } +} + +void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notification) { + if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM)) + return; + + char *name = _T2A(TranslateT("Notification"), CP_UTF8); + + std::stringstream text; + text << notification->text << "\n\n" << notification->link; + UpdateChat(_T(FACEBOOK_NOTIFICATIONS_CHATROOM), name /*notification->second->user_id.c_str()*/, name, text.str().c_str(), notification->time, notification->seen); } \ No newline at end of file -- cgit v1.2.3