diff options
author | George Hazan <ghazan@miranda.im> | 2017-12-29 17:27:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-12-29 17:27:08 +0300 |
commit | f16cf071e51f4768f20692c99414cb39521fa413 (patch) | |
tree | 7dd3cc512fe65fdd546f7753937261c518e5008c /protocols/FacebookRM | |
parent | 939048b7ebce6a70c8e243fec36983de7d931e8b (diff) |
PROTO_INTERFACE::setAllContactStatuses - common code moved to the core
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 28 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 26 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 1 |
5 files changed, 16 insertions, 45 deletions
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index c8c3bd2329..e66fb5b921 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -55,7 +55,7 @@ void FacebookProto::ChangeStatus(void*) facy.logout(); OnLeaveChat(NULL, NULL); - SetAllContactStatuses(ID_STATUS_OFFLINE); + setAllContactStatuses(ID_STATUS_OFFLINE); ToggleStatusMenuItems(false); delSetting(FACEBOOK_KEY_LOGON_TS); @@ -161,7 +161,7 @@ void FacebookProto::ChangeStatus(void*) else { // Change between online/away/invisible statuses if (new_status == ID_STATUS_INVISIBLE) // When switching to invisible (from online/away), we need to set all contacts offline as we won't receive no status updates from Facebook - SetAllContactStatuses(ID_STATUS_OFFLINE); + setAllContactStatuses(ID_STATUS_OFFLINE); } bool wasAwayOrInvisible = (old_status == ID_STATUS_AWAY || old_status == ID_STATUS_INVISIBLE); diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 91d52145fd..415a6afb49 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -393,16 +393,6 @@ MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, bool force_add, boo return hContact; } -void FacebookProto::SetAllContactStatuses(int status) -{ - for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - if (isChatRoom(hContact)) - continue; - - setWord(hContact, "Status", status); - } -} - void FacebookProto::DeleteContactFromServer(void *data) { facy.handle_entry("DeleteContactFromServer"); @@ -638,13 +628,11 @@ void FacebookProto::RefreshUserInfo(void *data) std::string homepage = FACEBOOK_URL_PROFILE + fbu.user_id; setString(hContact, "Homepage", homepage.c_str()); - if (!fbu.real_name.empty()) { + if (!fbu.real_name.empty()) SaveName(hContact, &fbu); - } - if (fbu.gender) { + if (fbu.gender) setByte(hContact, "Gender", fbu.gender); - } int oldType = getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); // From server we won't get request/approve types, only none, so we don't want to overwrite and lost it in that case @@ -653,9 +641,8 @@ void FacebookProto::RefreshUserInfo(void *data) } // If this contact is page, set it as invisible (if enabled in options) - if (getBool(FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE) && fbu.type == CONTACT_PAGE) { + if (getBool(FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE) && fbu.type == CONTACT_PAGE) setWord(hContact, "Status", ID_STATUS_INVISIBLE); - } CheckAvatarChange(hContact, fbu.image_url); @@ -686,26 +673,21 @@ void FacebookProto::RefreshUserInfo(void *data) std::string year = birthday.substr(pos2 + 2, 4); setWord(hContact, "BirthYear", atoi(year.c_str())); } - else { - // We have to set ANY year, otherwise UserInfoEx shows completely wrong date + else // We have to set ANY year, otherwise UserInfoEx shows completely wrong date setWord(hContact, "BirthYear", 1800); - } } } ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)nullptr, 0); } - HANDLE FacebookProto::GetAwayMsg(MCONTACT) { return nullptr; // Status messages are disabled } -int FacebookProto::OnContactDeleted(WPARAM wParam, LPARAM) +int FacebookProto::OnContactDeleted(WPARAM hContact, LPARAM) { - MCONTACT hContact = (MCONTACT)wParam; - // Remove this contact from caches ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); if (id) diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 01beebc0e4..c7d768c1e7 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -844,11 +844,10 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag for (auto itNodes = buddyList.begin(); itNodes != buddyList.end(); ++itNodes) { std::string id = (*itNodes).name(); + // Facebook now sends info also about some nonfriends, so we just ignore status change of contacts we don't have in list MCONTACT hContact = ContactIDToHContact(id); - if (!hContact) { - // Facebook now sends info also about some nonfriends, so we just ignore status change of contacts we don't have in list + if (!hContact) continue; - } // TODO: Check for friends existence/inexistence? Here we should get all friends (but we're already doing friendslist request, so we should have fresh data already) @@ -880,27 +879,18 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag delSetting(hContact, "LastActiveTS"); // Set users inactive for too long as offline - if (last_active > 0 && last_active < offlineThreshold) { + if (last_active > 0 && last_active < offlineThreshold) setWord(hContact, "Status", ID_STATUS_OFFLINE); - } } // Probably means client: guess 0 = web, 8 = messenger, 10 = something else? if (vc_) { - int vc = vc_.as_int(); wchar_t *client; - - if (vc == 0) { - client = FACEBOOK_CLIENT_WEB; - } - else if (vc == 8) { - client = FACEBOOK_CLIENT_MESSENGER; // I was online on Miranda, but when looked at myself at messenger.com I had icon of Messenger. - } - else if (vc == 10) { - client = FACEBOOK_CLIENT_MOBILE; - } - else { - client = FACEBOOK_CLIENT_OTHER; + switch (vc_.as_int()) { + case 0: client = FACEBOOK_CLIENT_WEB; break; + case 8: client = FACEBOOK_CLIENT_MESSENGER; break; + case 10: client = FACEBOOK_CLIENT_MOBILE; break; + default: client = FACEBOOK_CLIENT_OTHER; break; } setWString(hContact, "MirVer", client); } diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 4d42208359..f365cee0ea 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -99,7 +99,7 @@ FacebookProto::FacebookProto(const char* proto_name, const wchar_t* username) : facy.set_handle(m_hNetlibUser); // Set all contacts offline -- in case we crashed - SetAllContactStatuses(ID_STATUS_OFFLINE); + setAllContactStatuses(ID_STATUS_OFFLINE); // register special type of event // there's no need to declare the special service for getting text diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index d3306433f9..779b6bc11d 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -221,7 +221,6 @@ public: std::string ThreadIDToContactID(const std::string&); void LoadContactInfo(facebook_user* fbu); MCONTACT AddToContactList(facebook_user*, bool force_add = false, bool add_temporarily = false); - void SetAllContactStatuses(int status); MCONTACT HContactFromAuthEvent(MEVENT hEvent); void StartTyping(MCONTACT hContact); void StopTyping(MCONTACT hContact); |