From d9afe7697ba309f6d78b61adea474942c0b55424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 19 Nov 2013 19:18:00 +0000 Subject: Facebook: distinguish more types of clients and don't reset old client at login/logoff git-svn-id: http://svn.miranda-ng.org/main/trunk@6940 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/common.h | 2 +- protocols/FacebookRM/src/connection.cpp | 4 ++-- protocols/FacebookRM/src/constants.h | 15 +++++++++++++-- protocols/FacebookRM/src/contacts.cpp | 10 ++-------- protocols/FacebookRM/src/entities.h | 25 ++++++++++++++++++++++--- protocols/FacebookRM/src/json.cpp | 14 ++++++++------ protocols/FacebookRM/src/process.cpp | 4 ++-- protocols/FacebookRM/src/proto.cpp | 2 +- protocols/FacebookRM/src/proto.h | 2 +- 9 files changed, 52 insertions(+), 26 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/common.h b/protocols/FacebookRM/src/common.h index 7bf92430af..0972c1e7a6 100644 --- a/protocols/FacebookRM/src/common.h +++ b/protocols/FacebookRM/src/common.h @@ -63,6 +63,7 @@ along with this program. If not, see . class FacebookProto; +#include "constants.h" #include "definitions.h" #include "entities.h" #include "http.h" @@ -72,7 +73,6 @@ class FacebookProto; #include "proto.h" #include "json.h" #include "db.h" -#include "constants.h" #include "dialogs.h" #include "theme.h" #include "resource.h" diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 3b6a57e45e..f88f3b2e90 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -39,7 +39,7 @@ void FacebookProto::ChangeStatus(void*) Netlib_Shutdown(facy.hMsgCon); OnLeaveChat(NULL, NULL); - SetAllContactStatuses(ID_STATUS_OFFLINE, true); + SetAllContactStatuses(ID_STATUS_OFFLINE); ToggleStatusMenuItems(false); delSetting("LogonTS"); @@ -122,7 +122,7 @@ void FacebookProto::ChangeStatus(void*) else if (new_status == ID_STATUS_INVISIBLE) { facy.buddies.clear(); - this->SetAllContactStatuses(ID_STATUS_OFFLINE, true); + this->SetAllContactStatuses(ID_STATUS_OFFLINE); } facy.chat_state(m_iDesiredStatus != ID_STATUS_INVISIBLE); diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 5d1c6f98a6..8eec0e5586 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -41,8 +41,11 @@ along with this program. If not, see . #define FACEBOOK_SERVER_DOMAIN "facebook.com" // Facebook clients -#define FACEBOOK_CLIENT "Facebook" -#define FACEBOOK_CLIENT_MOBILE "Facebook (Mobile)" +#define FACEBOOK_CLIENT_WEB "Facebook (website)" +#define FACEBOOK_CLIENT_MOBILE "Facebook (mobile)" +#define FACEBOOK_CLIENT_OTHER "Facebook (other)" +#define FACEBOOK_CLIENT_APP "Facebook App" +#define FACEBOOK_CLIENT_MESSENGER "Facebook Messenger" // Limits #define FACEBOOK_MESSAGE_LIMIT 200000 // this is guessed limit, in reality it is bigger @@ -137,6 +140,14 @@ enum ContactType { CONTACT_APPROVE = 4 // contact that is asking us for approval of friendship }; +enum ClientType { + CLIENT_WEB = 1, // Facebook website + CLIENT_APP = 2, // Facebook mobile application + CLIENT_MESSENGER = 3, // Facebook Messenger application + CLIENT_OTHER = 4, // Facebook over XMPP + CLIENT_MOBILE = 5 // Facebook on unknown mobile client (can't be determined for offline contacts) +}; + typedef struct { const char *name; const char *id; diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index adef0e21b0..c7487cd71d 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -115,7 +115,7 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, boo std::string homepage = FACEBOOK_URL_PROFILE + fbu->user_id; setString(hContact, "Homepage", homepage.c_str()); - setTString(hContact, "MirVer", fbu->mobile ? _T(FACEBOOK_CLIENT_MOBILE) : _T(FACEBOOK_CLIENT)); + setTString(hContact, "MirVer", fbu->getMirVer()); db_unset(hContact, "CList", "MyHandle"); @@ -147,18 +147,12 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, boo return 0; } -void FacebookProto::SetAllContactStatuses(int status, bool reset_client) +void FacebookProto::SetAllContactStatuses(int status) { for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (isChatRoom(hContact)) continue; - if (reset_client) { - ptrT mirver( getTStringA(hContact, "MirVer")); - if (!mirver || _tcscmp(mirver, _T(FACEBOOK_CLIENT))) - setTString(hContact, "MirVer", _T(FACEBOOK_CLIENT)); - } - if (getWord(hContact, "Status", 0) != status) setWord(hContact, "Status", status); } diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index a52c3ed701..a924324019 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -37,7 +37,8 @@ struct facebook_user bool deleted; bool idle; - bool mobile; + + ClientType client; facebook_user() { @@ -45,7 +46,8 @@ struct facebook_user this->user_id = this->real_name = this->image_url = ""; this->status_id = ID_STATUS_OFFLINE; this->gender = this->last_active = 0; - this->deleted = this->idle = this->mobile = false; + this->deleted = this->idle = false; + this->client = CLIENT_WEB; } facebook_user(facebook_user* fu) @@ -59,7 +61,24 @@ struct facebook_user this->image_url = fu->image_url; this->deleted = fu->deleted; this->idle = fu->idle; - this->mobile = fu->mobile; + this->client = fu->client; + } + + TCHAR *getMirVer() + { + switch (this->client) { + case CLIENT_APP: + return _T(FACEBOOK_CLIENT_APP); + case CLIENT_MESSENGER: + return _T(FACEBOOK_CLIENT_MESSENGER); + case CLIENT_OTHER: + return _T(FACEBOOK_CLIENT_OTHER); + case CLIENT_MOBILE: + return _T(FACEBOOK_CLIENT_MOBILE); + case CLIENT_WEB: + default: + return _T(FACEBOOK_CLIENT_WEB); + } } }; diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index a103a6f29c..84e7b46abf 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -81,7 +81,7 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user } current->status_id = ID_STATUS_OFFLINE; - current->mobile = true; + current->client = CLIENT_MOBILE; } } @@ -113,16 +113,18 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user if (json_as_pstring(status) != "active") current->status_id = ID_STATUS_OFFLINE; + bool b; + // "webStatus" and "otherStatus" are marked as "WEB" on FB website - if (json_as_pstring(webStatus) == "active" || json_as_pstring(otherStatus) == "active") { - current->status_id = ID_STATUS_ONLINE; - current->mobile = false; + if ((b = json_as_pstring(webStatus) == "active") || json_as_pstring(otherStatus) == "active") { + current->status_id = ID_STATUS_ONLINE; + current->client = b ? CLIENT_WEB : CLIENT_OTHER; } // "fbAppStatus" and "messengerStatus" are marked as "MOBILE" on FB website - if (json_as_pstring(fbAppStatus) == "active" || json_as_pstring(messengerStatus) == "active") { + if ((b = json_as_pstring(fbAppStatus) == "active") || json_as_pstring(messengerStatus) == "active") { current->status_id = ID_STATUS_ONTHEPHONE; - current->mobile = true; + current->client = b ? CLIENT_APP : CLIENT_MESSENGER; } // this is not marked anyhow on website (yet?) diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index d62271b1a3..f5807a512d 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -68,8 +68,8 @@ void FacebookProto::ProcessBuddyList(void* data) hContact = AddToContactList(fbu, CONTACT_FRIEND); ptrT client( getTStringA(hContact, "MirVer")); - if (!client || _tcscmp(client, fbu->mobile ? _T(FACEBOOK_CLIENT_MOBILE) : _T(FACEBOOK_CLIENT))) - setTString(hContact, "MirVer", fbu->mobile ? _T(FACEBOOK_CLIENT_MOBILE) : _T(FACEBOOK_CLIENT)); + if (!client || _tcscmp(client, fbu->getMirVer())) + setTString(hContact, "MirVer", fbu->getMirVer()); if (getDword(fbu->handle, "IdleTS", 0) != fbu->last_active) { if ((fbu->idle || fbu->status_id == ID_STATUS_OFFLINE) && fbu->last_active > 0) diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 99c1c9becd..981fc37484 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -78,7 +78,7 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) : facy.set_handle(m_hNetlibUser); // Set all contacts offline -- in case we crashed - SetAllContactStatuses(ID_STATUS_OFFLINE, true); + SetAllContactStatuses(ID_STATUS_OFFLINE); } FacebookProto::~FacebookProto() diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 3ab2c867c0..000afba6ec 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -189,7 +189,7 @@ public: HANDLE ContactIDToHContact(std::string); HANDLE ChatIDToHContact(std::tstring); HANDLE AddToContactList(facebook_user*, ContactType type, bool dont_check = false); - void SetAllContactStatuses(int status, bool reset_client = false); + void SetAllContactStatuses(int status); HANDLE HContactFromAuthEvent(HANDLE hEvent); // Chats handling -- cgit v1.2.3