diff options
author | Robert Pösel <robyer@seznam.cz> | 2012-11-09 15:37:34 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2012-11-09 15:37:34 +0000 |
commit | 0b67a54741236361d1ad1adf557e73fd80d1eea9 (patch) | |
tree | b71ce86076216c269420a833689f53a1bdb7d858 /protocols/FacebookRM | |
parent | 336718667f42e964f4deeb54f60d42ff392457d4 (diff) |
Facebook: Show contacts on mobile with different MirVer (support for MobileState plugin)
git-svn-id: http://svn.miranda-ng.org/main/trunk@2259 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 22 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 33 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 49 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 2 |
7 files changed, 74 insertions, 39 deletions
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 4abded5872..c162c4832c 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -57,7 +57,7 @@ void FacebookProto::ChangeStatus(void*) OnLeaveChat(NULL, NULL);
- SetAllContactStatuses( ID_STATUS_OFFLINE );
+ SetAllContactStatuses( ID_STATUS_OFFLINE, true );
ToggleStatusMenuItems(false);
@@ -123,7 +123,7 @@ void FacebookProto::ChangeStatus(void*) else if ( new_status == ID_STATUS_INVISIBLE )
{
facy.buddies.clear( );
- this->SetAllContactStatuses( ID_STATUS_OFFLINE );
+ this->SetAllContactStatuses( ID_STATUS_OFFLINE, true );
}
facy.chat_state( m_iDesiredStatus != ID_STATUS_INVISIBLE );
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index b890ce140a..c160596abd 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // Product management
#define FACEBOOK_NAME "Facebook"
+#define FACEBOOK_MOBILE "Facebook (Mobile)"
#define FACEBOOK_URL_HOMEPAGE "http://www.facebook.com"
#define FACEBOOK_URL_REQUESTS "http://www.facebook.com/n/?reqs.php"
#define FACEBOOK_URL_MESSAGES "http://www.facebook.com/n/?inbox"
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 5337ce6dbe..cabad56410 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -108,9 +108,8 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, BYTE type, bool dont_ DBWriteContactSettingString(hContact,m_szModuleName,FACEBOOK_KEY_ID,fbu->user_id.c_str());
std::string homepage = FACEBOOK_URL_PROFILE + fbu->user_id;
- DBWriteContactSettingString(hContact, m_szModuleName,"Homepage", homepage.c_str());
-
- DBWriteContactSettingString(hContact, m_szModuleName, "MirVer", FACEBOOK_NAME);
+ DBWriteContactSettingString(hContact, m_szModuleName,"Homepage", homepage.c_str());
+ DBWriteContactSettingString(hContact, m_szModuleName, "MirVer", fbu->status_id == ID_STATUS_ONTHEPHONE ? FACEBOOK_MOBILE : FACEBOOK_NAME);
DBDeleteContactSetting(hContact, "CList", "MyHandle");
@@ -141,7 +140,7 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, BYTE type, bool dont_ return 0;
}
-void FacebookProto::SetAllContactStatuses(int status)
+void FacebookProto::SetAllContactStatuses(int status, bool reset_client)
{
for (HANDLE hContact = db_find_first();
hContact;
@@ -149,11 +148,18 @@ void FacebookProto::SetAllContactStatuses(int status) {
if (!IsMyContact(hContact))
continue;
+
+ if (reset_client) {
+ DBVARIANT dbv;
+ if (!DBGetContactSettingTString(hContact,m_szModuleName,"MirVer",&dbv)) {
+ if (_tcscmp(dbv.ptszVal, _T(FACEBOOK_NAME)))
+ DBWriteContactSettingTString(hContact,m_szModuleName,"MirVer", _T(FACEBOOK_NAME));
+ DBFreeVariant(&dbv);
+ }
+ }
- if (DBGetContactSettingWord(hContact,m_szModuleName,"Status",ID_STATUS_OFFLINE) == status)
- continue;
-
- DBWriteContactSettingWord(hContact,m_szModuleName,"Status",status);
+ if (DBGetContactSettingWord(hContact,m_szModuleName,"Status",ID_STATUS_OFFLINE) != status)
+ DBWriteContactSettingWord(hContact,m_szModuleName,"Status",status);
}
}
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 2c03c36a7d..eaf33a083e 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -56,28 +56,25 @@ int facebook_json_parser::parse_buddy_list( void* data, List::List< facebook_use for ( List::Item< facebook_user >* i = buddy_list->begin( ); i != NULL; i = i->next ) {
i->data->status_id = ID_STATUS_OFFLINE;
}
-
+
+ const Array& mobileFriends = objRoot["payload"]["buddy_list"]["mobile_friends"];
// Find mobile friends
- if (DBGetContactSettingByte(NULL,proto->m_szModuleName,FACEBOOK_KEY_LOAD_MOBILE, DEFAULT_LOAD_MOBILE)) {
- const Array& mobileFriends = objRoot["payload"]["buddy_list"]["mobile_friends"];
-
- for ( Array::const_iterator buddy( mobileFriends.Begin()); buddy != mobileFriends.End(); ++buddy) {
- const Number& member = *buddy;
- char was_id[32];
- lltoa( member.Value(), was_id, 10 );
+ for ( Array::const_iterator buddy( mobileFriends.Begin()); buddy != mobileFriends.End(); ++buddy) {
+ const Number& member = *buddy;
+ char was_id[32];
+ lltoa( member.Value(), was_id, 10 );
- std::string id = was_id;
- if (!id.empty()) {
- current = buddy_list->find( id );
+ std::string id = was_id;
+ if (!id.empty()) {
+ current = buddy_list->find( id );
- if ( current == NULL) {
- buddy_list->insert( std::make_pair( id, new facebook_user( )) );
- current = buddy_list->find( id );
- current->user_id = id;
- }
-
- current->status_id = ID_STATUS_ONTHEPHONE;
+ if ( current == NULL) {
+ buddy_list->insert( std::make_pair( id, new facebook_user( )) );
+ current = buddy_list->find( id );
+ current->user_id = id;
}
+
+ current->status_id = ID_STATUS_ONTHEPHONE;
}
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 21fc491f99..768bd342f2 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -42,16 +42,48 @@ void FacebookProto::ProcessBuddyList( void* data ) p->parse_buddy_list( data, &facy.buddies );
delete p;
- for ( List::Item< facebook_user >* i = facy.buddies.begin( ); i != NULL; )
- {
- LOG(" Now %s: %s", (i->data->status_id == ID_STATUS_OFFLINE ? "offline" : "online"), i->data->real_name.c_str());
+ bool use_mobile_status = DBGetContactSettingByte(NULL,m_szModuleName,FACEBOOK_KEY_LOAD_MOBILE, DEFAULT_LOAD_MOBILE) != 0;
- facebook_user* fbu;
+ for ( List::Item< facebook_user >* i = facy.buddies.begin( ); i != NULL; )
+ {
+ facebook_user* fbu = i->data;
+ bool on_mobile = false;
+
+ char *status;
+ switch (fbu->status_id) {
+ case ID_STATUS_OFFLINE:
+ status = "offline"; break;
+ case ID_STATUS_ONLINE:
+ status = "online"; break;
+ case ID_STATUS_ONTHEPHONE:
+ on_mobile = true;
+ status = "onthephone";
+
+ if (!use_mobile_status)
+ fbu->status_id = ID_STATUS_OFFLINE;
+ break;
+ }
+ LOG(" Now %s: %s", status, i->data->real_name.c_str());
- if ( i->data->status_id == ID_STATUS_OFFLINE || i->data->deleted )
+ if (!fbu->deleted && on_mobile && !fbu->handle)
{
- fbu = i->data;
+ HANDLE hContact = fbu->handle;
+ if (!hContact)
+ hContact = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND);
+
+ DBVARIANT dbv;
+ TCHAR* client = on_mobile ? _T(FACEBOOK_MOBILE) : _T(FACEBOOK_NAME);
+ if (!DBGetContactSettingTString(hContact,m_szModuleName,"MirVer",&dbv)) {
+ if (_tcscmp(dbv.ptszVal, client))
+ DBWriteContactSettingTString(hContact,m_szModuleName,"MirVer",client);
+ DBFreeVariant(&dbv);
+ } else {
+ DBWriteContactSettingTString(hContact,m_szModuleName,"MirVer",client);
+ }
+ }
+ if (fbu->status_id == ID_STATUS_OFFLINE || fbu->deleted)
+ {
if (fbu->handle)
DBWriteContactSettingWord(fbu->handle, m_szModuleName, "Status", ID_STATUS_OFFLINE);
@@ -59,12 +91,11 @@ void FacebookProto::ProcessBuddyList( void* data ) i = i->next;
facy.buddies.erase( to_delete );
} else {
- fbu = i->data;
i = i->next;
if (!fbu->handle) { // just been added
- fbu->handle = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND);
-
+ fbu->handle = AddToContactList(fbu, FACEBOOK_CONTACT_FRIEND);
+
if (!fbu->real_name.empty()) {
DBWriteContactSettingUTF8String(fbu->handle,m_szModuleName,FACEBOOK_KEY_NAME,fbu->real_name.c_str());
DBWriteContactSettingUTF8String(fbu->handle,m_szModuleName,FACEBOOK_KEY_NICK,fbu->real_name.c_str());
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 18ada5d913..84a24d3e94 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -79,7 +79,7 @@ FacebookProto::FacebookProto(const char* proto_name,const TCHAR* username) hAvatarFolder_ = FoldersRegisterCustomPathT(m_szModuleName, "Avatars", def_avatar_folder_.c_str());
// Set all contacts offline -- in case we crashed
- SetAllContactStatuses( ID_STATUS_OFFLINE );
+ SetAllContactStatuses( ID_STATUS_OFFLINE, true );
}
FacebookProto::~FacebookProto( )
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 0d58e3ae1e..6f2d8ed057 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -164,7 +164,7 @@ public: HANDLE ContactIDToHContact(std::string);
HANDLE ChatIDToHContact(std::string);
HANDLE AddToContactList(facebook_user*, BYTE type, bool dont_check = false, const char *new_name = "");
- void SetAllContactStatuses(int);
+ void SetAllContactStatuses(int status, bool reset_client = false);
HANDLE HContactFromAuthEvent(HANDLE hEvent);
// Chats handling
|