diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-12-01 13:32:27 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-12-01 13:32:27 +0000 |
commit | 597d4be9de7903814c01631fbd4180a6f297ce92 (patch) | |
tree | 4ba2e27133c437e61d7dceffce251d7bf6dc582d /protocols/FacebookRM/src/chat.cpp | |
parent | f7782fbf614361339617da21e6220044ffcf6822 (diff) |
Facebook: More improvements for chatrooms
git-svn-id: http://svn.miranda-ng.org/main/trunk@11194 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src/chat.cpp')
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 96 |
1 files changed, 46 insertions, 50 deletions
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<LPARAM>(&gce)); - gce.ptszStatus = TranslateT("Friend"); - CallServiceSync(MS_GC_EVENT, NULL, reinterpret_cast<LPARAM>(&gce)); - gce.ptszStatus = TranslateT("User"); - CallServiceSync(MS_GC_EVENT, NULL, reinterpret_cast<LPARAM>(&gce)); + facebook_chatroom *fbc; + std::tstring tthread_id = ptrT(getTStringA(hContact, FACEBOOK_KEY_TID)); + + std::map<std::tstring, facebook_chatroom*>::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<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()); + } - 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<LPARAM>(&gce)); CallServiceSync(MS_GC_EVENT,SESSION_TERMINATE,reinterpret_cast<LPARAM>(&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<LPARAM>(&gce)); - CallServiceSync(MS_GC_EVENT,SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce)); - } - else - { - CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE,reinterpret_cast<LPARAM>(&gce)); + std::map<std::tstring, facebook_chatroom*>::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) { |