INT_PTR FacebookProto::OnLeaveChat(WPARAM wParam, LPARAM) { ptrT idT(wParam ? getTStringA(wParam, "ChatRoomID") : NULL); GCDEST gcd = { m_szModuleName, NULL, GC_EVENT_CONTROL }; gcd.ptszID = idT; GCEVENT gce = { sizeof(gce), &gcd }; gce.time = ::time(NULL); CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce)); CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, reinterpret_cast<LPARAM>(&gce)); if (!wParam) { facy.clear_chatrooms(); } else if (!IsSpecialChatRoom(wParam)) { ptrA threadId(getStringA(wParam, FACEBOOK_KEY_TID)); if (!threadId) return 0; auto it = facy.chat_rooms.find(std::string(threadId)); if (it != facy.chat_rooms.end()) { delete it->second; facy.chat_rooms.erase(it); } } return 0; }
INT_PTR CSkypeProto::OnJoinChatRoom(WPARAM hContact, LPARAM) { if (hContact) { ptrT idT(getTStringA(hContact, "ChatRoomID")); ptrT nameT(getTStringA(hContact, "Nick")); StartChatRoom(idT, nameT != NULL ? nameT : idT); } return 0; }
INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM) { if (!m_enableChat || IsSpecialChatRoom(hContact)) return 0; ptrT idT(getTStringA(hContact, "ChatRoomID")); ptrT nameT(getTStringA(hContact, "Nick")); ptrA threadId(getStringA(hContact, FACEBOOK_KEY_TID)); if (!idT || !nameT || !threadId) return 0; facebook_chatroom *fbc; std::string tthread_id = threadId; auto it = facy.chat_rooms.find(tthread_id); if (it != facy.chat_rooms.end()) { fbc = it->second; } else { // We don't have this chat loaded in memory yet, lets load some info (name, list of users) fbc = new facebook_chatroom(tthread_id); LoadChatInfo(fbc); facy.chat_rooms.insert(std::make_pair(tthread_id, fbc)); } // RM TODO: better use check if chatroom exists/is in db/is online... no? // like: if (ChatIDToHContact(tthread_id) == NULL) { ptrA users(GetChatUsers(tthread_id.c_str())); if (users == NULL) { // Add chatroom AddChat(fbc->thread_id.c_str(), fbc->chat_name.c_str()); // Add chat contacts for (std::map<std::string, std::string>::iterator jt = fbc->participants.begin(); jt != fbc->participants.end(); ++jt) { AddChatContact(fbc->thread_id.c_str(), jt->first.c_str(), jt->second.c_str()); } // Load last messages delSetting(hContact, FACEBOOK_KEY_MESSAGE_ID); // We're creating new chatroom so we want load all recent messages ForkThread(&FacebookProto::LoadLastMessages, new MCONTACT(hContact)); } return 0; }
INT_PTR CSkypeProto::OnLeaveChatRoom(WPARAM hContact, LPARAM) { if (!IsOnline()) return 1; if (hContact && IDYES == MessageBox(NULL, TranslateT("This chat is going to be destroyed forever with all its contents. This action cannot be undone. Are you sure?"), TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION)) { ptrT idT(getTStringA(hContact, "ChatRoomID")); GCDEST gcd = { m_szModuleName, NULL, GC_EVENT_CONTROL }; gcd.ptszID = idT; GCEVENT gce = { sizeof(gce), &gcd }; gce.time = ::time(NULL); CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce)); CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, reinterpret_cast<LPARAM>(&gce)); SendRequest(new KickUserRequest(m_szRegToken, _T2A(idT), m_szSelfSkypeName, m_szServer)); CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); } return 0; }
void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notification) { if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM)) return; std::stringstream text; text << notification->text << "\n\n" << PrepareUrl(notification->link); std::string message = text.str(); utils::text::replace_all(&message, "%", "%%"); ptrT idT(mir_tstrdup(_T(FACEBOOK_NOTIFICATIONS_CHATROOM))); ptrT messageT(mir_a2t_cp(message.c_str(), CP_UTF8)); GCDEST gcd = { m_szModuleName, _T(FACEBOOK_NOTIFICATIONS_CHATROOM), GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.ptszText = messageT; gce.time = notification->time ? notification->time : ::time(NULL); gce.bIsMe = false; gce.dwFlags |= GCEF_ADDTOLOG; gce.ptszNick = TranslateT("Notifications"); gce.ptszUID = idT; CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce)); }