From 597d4be9de7903814c01631fbd4180a6f297ce92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Mon, 1 Dec 2014 13:32:27 +0000 Subject: Facebook: More improvements for chatrooms git-svn-id: http://svn.miranda-ng.org/main/trunk@11194 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/chat.cpp | 96 +++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 50 deletions(-) (limited to 'protocols/FacebookRM/src/chat.cpp') diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index b9f416a632..2fc753e6be 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -3,7 +3,7 @@ Facebook plugin for Miranda Instant Messenger _____________________________________________ -Copyright � 2011-13 Robert P�sel +Copyright © 2011-13 Robert Pösel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -168,6 +168,9 @@ int FacebookProto::OnGCEvent(WPARAM wParam,LPARAM lParam) void FacebookProto::AddChatContact(const TCHAR *tchat_id, const char *id, const char *name) { + if (IsChatContact(tchat_id, id)) + return; + ptrT tnick( mir_a2t_cp(name, CP_UTF8)); ptrT tid( mir_a2t(id)); @@ -272,43 +275,45 @@ void FacebookProto::AddChat(const TCHAR *tid, const TCHAR *tname) INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM suppress) { - // TODO: load info from server + old history,... + if (!m_enableChat || IsSpecialChatRoom(hContact)) + return 0; ptrT idT( getTStringA(hContact, "ChatRoomID")); ptrT nameT( getTStringA(hContact, "Nick")); - if (idT && nameT) - AddChat(idT, nameT); - -/* GCSESSION gcw = {sizeof(gcw)}; - - // Create the group chat session - gcw.dwFlags = GC_TCHAR; - gcw.iType = GCW_PRIVMESS; - gcw.pszModule = m_szModuleName; - gcw.ptszName = m_tszUserName; - gcw.ptszID = m_tszUserName; - CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw); - - if(m_iStatus != ID_STATUS_ONLINE) + if (!idT || !nameT) return 0; - // Create a group - GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_ADDGROUP }; - GCEVENT gce = { sizeof(gce), &gcd }; - gce.ptszStatus = TranslateT("Myself"); - CallServiceSync(MS_GC_EVENT, NULL, reinterpret_cast(&gce)); - gce.ptszStatus = TranslateT("Friend"); - CallServiceSync(MS_GC_EVENT, NULL, reinterpret_cast(&gce)); - gce.ptszStatus = TranslateT("User"); - CallServiceSync(MS_GC_EVENT, NULL, reinterpret_cast(&gce)); + facebook_chatroom *fbc; + std::tstring tthread_id = ptrT(getTStringA(hContact, FACEBOOK_KEY_TID)); + + std::map::iterator 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::iterator jt = fbc->participants.begin(); jt != fbc->participants.end(); ++jt) { + AddChatContact(fbc->thread_id.c_str(), jt->first.c_str(), jt->second.c_str()); + } - SetTopic("Omegle is a great way of meeting new friends!"); + // 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)); + } - // Note: Initialization will finish up in SetChatStatus, called separately - if (!suppress) - SetChatStatus(m_iStatus); -*/ return 0; } @@ -324,30 +329,21 @@ INT_PTR FacebookProto::OnLeaveChat(WPARAM wParam,LPARAM) CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE, reinterpret_cast(&gce)); CallServiceSync(MS_GC_EVENT,SESSION_TERMINATE,reinterpret_cast(&gce)); - return 0; -} - -/* -void FacebookProto::SetChatStatus(int status) -{ - GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL }; - GCEVENT gce = { sizeof(gce), &gcd }; - gce.time = ::time(NULL); - if(status == ID_STATUS_ONLINE) - { - // Add self contact - AddChatContact(facy.nick_.c_str()); + if (!wParam) { + facy.clear_chatrooms(); + } else if (!IsSpecialChatRoom(wParam)) { + std::tstring tthread_id = ptrT(getTStringA(wParam, FACEBOOK_KEY_TID)); - CallServiceSync(MS_GC_EVENT,SESSION_INITDONE,reinterpret_cast(&gce)); - CallServiceSync(MS_GC_EVENT,SESSION_ONLINE, reinterpret_cast(&gce)); - } - else - { - CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE,reinterpret_cast(&gce)); + std::map::iterator it = facy.chat_rooms.find(tthread_id); + if (it != facy.chat_rooms.end()) { + delete it->second; + facy.chat_rooms.erase(it); + } } + + return 0; } -*/ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam) { -- cgit v1.2.3