From 99f1e39a46f191bf60bc138206437bb5ce00834b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Thu, 16 May 2013 09:57:54 +0000 Subject: Facebook: Added contact menu item to open Frindship details. Small cleanup of code. git-svn-id: http://svn.miranda-ng.org/main/trunk@4666 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/proto.cpp | 155 ++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 81 deletions(-) (limited to 'protocols/FacebookRM/src/proto.cpp') diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 1d3e8383bd..61d07d41b2 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -164,14 +164,12 @@ int FacebookProto::SetStatus(int new_status) break; } - if (m_iStatus == ID_STATUS_CONNECTING) - { + if (m_iStatus == ID_STATUS_CONNECTING) { LOG("===== Status is connecting, no change"); return 0; } - if (m_iStatus == m_iDesiredStatus) - { + if (m_iStatus == m_iDesiredStatus) { LOG("===== Statuses are same, no change"); return 0; } @@ -179,14 +177,12 @@ int FacebookProto::SetStatus(int new_status) facy.invisible_ = (new_status == ID_STATUS_INVISIBLE); ForkThread(&FacebookProto::ChangeStatus, this); - return 0; } int FacebookProto::SetAwayMsg(int status, const PROTOCHAR *msg) { - if (!msg) - { + if (!msg) { last_status_msg_.clear(); return 0; } @@ -196,9 +192,8 @@ int FacebookProto::SetAwayMsg(int status, const PROTOCHAR *msg) utils::mem::detract(narrow); if (isOnline() && getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS)) - { ForkThread(&FacebookProto::SetAwayMsgWorker, this, NULL); - } + return 0; } @@ -245,13 +240,11 @@ HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr) HANDLE hContact = AddToContactList(&fbu, FACEBOOK_CONTACT_NONE, false, fbu.real_name.c_str()); if (hContact) { - if (flags & PALF_TEMPORARY) - { + if (flags & PALF_TEMPORARY) { db_set_b(hContact, "Clist", "Hidden", 1); db_set_b(hContact, "Clist", "NotOnList", 1); } - else if (db_get_b(hContact, "CList", "NotOnList", 0)) - { + else if (db_get_b(hContact, "CList", "NotOnList", 0)) { db_unset(hContact, "CList", "Hidden"); db_unset(hContact, "CList", "NotOnList"); } @@ -271,36 +264,31 @@ int FacebookProto::AuthRequest(HANDLE hContact,const PROTOCHAR *message) int FacebookProto::Authorize(HANDLE hDbEvent) { - if (!isOffline() && hDbEvent) - { - HANDLE hContact = HContactFromAuthEvent(hDbEvent); - if (hContact == INVALID_HANDLE_VALUE) - return 1; + if (!hDbEvent || isOffline()) + return 1; - return ApproveFriendship((WPARAM)hContact, NULL); - } + HANDLE hContact = HContactFromAuthEvent(hDbEvent); + if (hContact == INVALID_HANDLE_VALUE) + return 1; - return 1; + return ApproveFriendship((WPARAM)hContact, NULL); } int FacebookProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason) { + if (!hDbEvent || isOffline()) + return 1; - if (!isOffline() && hDbEvent) - { - HANDLE hContact = HContactFromAuthEvent(hDbEvent); - if (hContact == INVALID_HANDLE_VALUE) - return 1; - - // TODO: hide from facebook requests list + HANDLE hContact = HContactFromAuthEvent(hDbEvent); + if (hContact == INVALID_HANDLE_VALUE) + return 1; - if (db_get_b(hContact, "CList", "NotOnList", 0)) - CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); + // TODO: hide from facebook requests list - return 0; - } + if (db_get_b(hContact, "CList", "NotOnList", 0)) + CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); - return 1; + return 0; } ////////////////////////////////////////////////////////////////////////////// @@ -465,32 +453,48 @@ int FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam) { HANDLE hContact = reinterpret_cast(wParam); + // TODO: why isn't wParam == 0 when is status menu moved to main menu? + if (wParam == 0 || !IsMyContact(hContact)) + return 1; + std::string url = FACEBOOK_URL_PROFILE; - DBVARIANT dbv; - // TODO: why isn't wParam == 0 when is status menu moved to main menu? - if (wParam != 0 && IsMyContact(hContact)) { - if (!db_get_s(hContact, m_szModuleName, "Homepage", &dbv)) { - // Homepage link already present, get it - url = dbv.pszVal; - db_free(&dbv); - } else if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv)) { - // No homepage link, create and save it - url += dbv.pszVal; - db_set_s(hContact, m_szModuleName, "Homepage", url.c_str()); - db_free(&dbv); - } + mir_ptr val = db_get_sa(hContact, m_szModuleName, "Homepage"); + if (val != NULL) { + // Homepage link already present, get it + url = val; + } else { + // No homepage link, create and save it + val = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + url += val; + db_set_s(hContact, m_szModuleName, "Homepage", url.c_str()); } CallService(MS_UTILS_OPENURL, 1, reinterpret_cast(url.c_str())); + return 0; +} + +int FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam) +{ + HANDLE hContact = reinterpret_cast(wParam); + + if (wParam == 0 || !IsMyContact(hContact)) + return 1; + + mir_ptr id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + std::string url = FACEBOOK_URL_PROFILE; + url += facy.self_.user_id; + url += "&and=" + std::string(id); + + CallService(MS_UTILS_OPENURL, 1, reinterpret_cast(url.c_str())); return 0; } int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam) { if (wParam == NULL || isOffline()) - return 0; + return 1; bool deleting = (lParam == 1); @@ -501,34 +505,26 @@ int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam) || (deleting && db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != FACEBOOK_CONTACT_FRIEND)) return 0; - DBVARIANT dbv; - TCHAR tstr[256]; - - if (!db_get_ts(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv)) { - mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), dbv.ptszVal); - db_free(&dbv); - } else if (!db_get_ts(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) { - mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), dbv.ptszVal); - db_free(&dbv); - } + mir_ptr tname = db_get_tsa(hContact, m_szModuleName, FACEBOOK_KEY_NAME); + if (tname == NULL) + tname = db_get_tsa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + TCHAR tstr[256]; if (MessageBox(0, tstr, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) { - if (!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) - { - std::string* id = new std::string(dbv.pszVal); + mir_ptr id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + if (id == NULL) + return 1; - if (deleting) { - facebook_user* fbu = facy.buddies.find((*id)); - if (fbu != NULL) { - fbu->handle = NULL; - } - } + std::string *val = new std::string(id); - ForkThread(&FacebookProto::DeleteContactFromServer, this, (void*)id); - db_free(&dbv); + if (deleting) { + facebook_user *fbu = facy.buddies.find(*val); + if (fbu != NULL) + fbu->handle = NULL; } + ForkThread(&FacebookProto::DeleteContactFromServer, this, (void*)val); } return 0; @@ -537,40 +533,37 @@ int FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam) int FacebookProto::RequestFriendship(WPARAM wParam,LPARAM lParam) { if (wParam == NULL || isOffline()) - return 0; + return 1; HANDLE hContact = reinterpret_cast(wParam); - DBVARIANT dbv; - if (!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) - { - std::string* id = new std::string(dbv.pszVal); - ForkThread(&FacebookProto::AddContactToServer, this, (void*)id); - db_free(&dbv); - } - + mir_ptr id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + if (id == NULL) + return 1; + + ForkThread(&FacebookProto::AddContactToServer, this, new std::string(id)); return 0; } int FacebookProto::ApproveFriendship(WPARAM wParam,LPARAM lParam) { if (wParam == NULL || isOffline()) - return 0; + return 1; HANDLE *hContact = new HANDLE(reinterpret_cast(wParam)); - ForkThread(&FacebookProto::ApproveContactToServer, this, (void*)hContact); + ForkThread(&FacebookProto::ApproveContactToServer, this, (void*)hContact); return 0; } int FacebookProto::OnCancelFriendshipRequest(WPARAM wParam,LPARAM lParam) { if (wParam == NULL || isOffline()) - return 0; + return 1; HANDLE *hContact = new HANDLE(reinterpret_cast(wParam)); - ForkThread(&FacebookProto::CancelFriendsRequest, this, (void*)hContact); + ForkThread(&FacebookProto::CancelFriendsRequest, this, (void*)hContact); return 0; } -- cgit v1.2.3