summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-07-30 22:36:59 +0000
committerRobert Pösel <robyer@seznam.cz>2014-07-30 22:36:59 +0000
commit6dcfe55905a55fad9169a26d434c93ca15d0717f (patch)
tree618f69a07800ac13c95c52f8ef90754a0d52ded4 /protocols/FacebookRM
parent4c117da80411021cabef4a40ebfaad05c6a7ff8b (diff)
Facebook: Support for denying friendship requests
git-svn-id: http://svn.miranda-ng.org/main/trunk@9999 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/communication.cpp17
-rw-r--r--protocols/FacebookRM/src/constants.h4
-rw-r--r--protocols/FacebookRM/src/contacts.cpp64
-rw-r--r--protocols/FacebookRM/src/proto.cpp19
-rw-r--r--protocols/FacebookRM/src/proto.h2
-rw-r--r--protocols/FacebookRM/src/theme.cpp10
-rw-r--r--protocols/FacebookRM/src/theme.h9
7 files changed, 92 insertions, 33 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 58fa61ed51..4c32e9648e 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -223,6 +223,7 @@ DWORD facebook_client::choose_security_level(RequestType request_type)
// case REQUEST_REQUEST_FRIEND:
// case REQUEST_APPROVE_FRIEND:
// case REQUEST_CANCEL_REQUEST:
+// case REQUEST_FRIENDS_REQUEST:
// case REQUEST_FEEDS:
// case REQUEST_PAGES:
// case REQUEST_NOTIFICATIONS:
@@ -270,8 +271,8 @@ int facebook_client::choose_method(RequestType request_type)
case REQUEST_LOGOUT:
case REQUEST_DELETE_FRIEND:
case REQUEST_REQUEST_FRIEND:
- case REQUEST_APPROVE_FRIEND:
case REQUEST_CANCEL_REQUEST:
+ case REQUEST_FRIENDS_REQUEST:
case REQUEST_UNREAD_THREADS:
return REQUEST_POST;
@@ -317,7 +318,6 @@ std::string facebook_client::choose_server(RequestType request_type, std::string
case REQUEST_HOME:
case REQUEST_DTSG:
- case REQUEST_APPROVE_FRIEND:
case REQUEST_LOAD_REQUESTS:
case REQUEST_SEARCH:
case REQUEST_USER_INFO:
@@ -348,6 +348,7 @@ std::string facebook_client::choose_server(RequestType request_type, std::string
// case REQUEST_DELETE_FRIEND:
// case REQUEST_REQUEST_FRIEND:
// case REQUEST_CANCEL_REQUEST:
+// case REQUEST_FRIENDS_REQUEST:
// case REQUEST_UNREAD_THREADS:
default:
return FACEBOOK_SERVER_REGULAR;
@@ -435,18 +436,14 @@ std::string facebook_client::choose_action(RequestType request_type, std::string
return "/ajax/add_friend/action.php?__a=1";
}
- case REQUEST_APPROVE_FRIEND:
+ case REQUEST_CANCEL_REQUEST:
{
- std::string action = "/a/notifications.php?__a=1";
- if (get_data != NULL) {
- action += "&" + (*get_data);
- }
- return action;
+ return "/ajax/friends/requests/cancel.php?__a=1";
}
- case REQUEST_CANCEL_REQUEST:
+ case REQUEST_FRIENDS_REQUEST:
{
- return "/ajax/friends/requests/cancel.php?__a=1";
+ return "/requests/friends/ajax/?__a=1";
}
case REQUEST_FEEDS:
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h
index a0b29ad867..4e5fdab90c 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -122,9 +122,9 @@ enum RequestType {
REQUEST_LOAD_FRIENDS, // getting info about all friends
REQUEST_USER_INFO, // getting info about particular user (from mobile website)
REQUEST_REQUEST_FRIEND, // requesting friendships
- REQUEST_APPROVE_FRIEND, // approving friendships
REQUEST_DELETE_FRIEND, // deleting friendships
- REQUEST_CANCEL_REQUEST, // canceling friendship request
+ REQUEST_CANCEL_REQUEST, // canceling (our) friendship request
+ REQUEST_FRIENDS_REQUEST, // approving or ignoring friendship requests
REQUEST_MESSAGE_SEND, // sending message
REQUEST_MESSAGE_SEND2, // sending message through inbox
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 5ad0b8a4d3..c7604da722 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -455,17 +455,23 @@ void FacebookProto::ApproveContactToServer(void *data)
MCONTACT hContact = *(MCONTACT*)data;
delete data;
- std::string post_data = "fb_dtsg=" + facy.dtsg_;
- post_data += "&charset_test=%e2%82%ac%2c%c2%b4%2c%e2%82%ac%2c%c2%b4%2c%e6%b0%b4%2c%d0%94%2c%d0%84&confirm_button=";
+ std::string query = "action=confirm";
+ query += "&id=" + std::string(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ query += "&__user=" + facy.self_.user_id;
+ query += "&fb_dtsg=" + facy.dtsg_;
- std::string get_data = "id=";
+ // Ignore friendship request
+ http::response resp = facy.flap(REQUEST_FRIENDS_REQUEST, &query);
- ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
- get_data += id;
-
- http::response resp = facy.flap(REQUEST_APPROVE_FRIEND, &post_data, &get_data);
+ if (resp.data.find("\"success\":true") != std::string::npos)
+ {
+ setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND);
+ NotifyEvent(m_tszUserName, TranslateT("Request for friendship was accepted."), NULL, FACEBOOK_EVENT_OTHER);
+ }
+ else facy.client_notify(TranslateT("Error occurred when accepting friendship request."));
- setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND);
+ if (resp.code != HTTP_CODE_OK)
+ facy.handle_error("ApproveContactToServer");
}
void FacebookProto::CancelFriendsRequest(void *data)
@@ -483,14 +489,14 @@ void FacebookProto::CancelFriendsRequest(void *data)
MCONTACT hContact = *(MCONTACT*)data;
delete data;
- std::string query = "phstamp=0&confirmed=1";
+ std::string query = "confirmed=1";
query += "&fb_dtsg=" + facy.dtsg_;
query += "&__user=" + facy.self_.user_id;
ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
query += "&friend=" + std::string(id);
- // Get unread inbox threads
+ // Cancel (our) friendship request
http::response resp = facy.flap(REQUEST_CANCEL_REQUEST, &query);
if (resp.data.find("\"payload\":null", 0) != std::string::npos)
@@ -504,6 +510,44 @@ void FacebookProto::CancelFriendsRequest(void *data)
facy.handle_error("CancelFriendsRequest");
}
+void FacebookProto::IgnoreFriendshipRequest(void *data)
+{
+ facy.handle_entry("IgnoreFriendshipRequest");
+
+ if (data == NULL)
+ return;
+
+ if (isOffline()) {
+ delete (MCONTACT*)data;
+ return;
+ }
+
+ MCONTACT hContact = *(MCONTACT*)data;
+ delete data;
+
+ std::string query = "action=reject";
+ query += "&id=" + std::string(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ query += "&__user=" + facy.self_.user_id;
+ query += "&fb_dtsg=" + facy.dtsg_;
+
+ // Ignore friendship request
+ http::response resp = facy.flap(REQUEST_FRIENDS_REQUEST, &query);
+
+ if (resp.data.find("\"success\":true") != std::string::npos)
+ {
+ setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
+ NotifyEvent(m_tszUserName, TranslateT("Request for friendship was ignored."), NULL, FACEBOOK_EVENT_OTHER);
+
+ // Delete this contact, if he's temporary
+ if (db_get_b(hContact, "CList", "NotOnList", 0))
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
+ }
+ else facy.client_notify(TranslateT("Error occurred when ignoring friendship request."));
+
+ if (resp.code != HTTP_CODE_OK)
+ facy.handle_error("IgnoreFriendshipRequest");
+}
+
void FacebookProto::SendPokeWorker(void *p)
{
facy.handle_entry("SendPokeWorker");
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index a4517e2a24..0f8685b91b 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -308,12 +308,7 @@ int FacebookProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR *reason)
if (hContact == INVALID_CONTACT_ID)
return 1;
- // TODO: hide from facebook requests list
-
- if (db_get_b(hContact, "CList", "NotOnList", 0))
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
-
- return 0;
+ return DenyFriendship(hContact, NULL);
}
int FacebookProto::GetInfo(MCONTACT hContact, int infoType)
@@ -730,6 +725,18 @@ INT_PTR FacebookProto::ApproveFriendship(WPARAM wParam,LPARAM lParam)
return 0;
}
+INT_PTR FacebookProto::DenyFriendship(WPARAM wParam, LPARAM lParam)
+{
+ if (wParam == NULL || isOffline())
+ return 1;
+
+ MCONTACT *hContact = new MCONTACT((MCONTACT)wParam);
+
+ ForkThread(&FacebookProto::IgnoreFriendshipRequest, hContact);
+
+ return 0;
+}
+
INT_PTR FacebookProto::OnCancelFriendshipRequest(WPARAM wParam,LPARAM lParam)
{
if (wParam == NULL || isOffline())
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 8fd911ed63..1472f96539 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -125,6 +125,7 @@ public:
INT_PTR __cdecl CancelFriendship(WPARAM, LPARAM);
INT_PTR __cdecl RequestFriendship(WPARAM, LPARAM);
INT_PTR __cdecl ApproveFriendship(WPARAM, LPARAM);
+ INT_PTR __cdecl DenyFriendship(WPARAM, LPARAM);
INT_PTR __cdecl OnCancelFriendshipRequest(WPARAM, LPARAM);
INT_PTR __cdecl CheckNewsfeeds(WPARAM, LPARAM);
INT_PTR __cdecl CheckFriendRequests(WPARAM, LPARAM);
@@ -191,6 +192,7 @@ public:
void __cdecl ApproveContactToServer(void*);
void __cdecl CancelFriendsRequest(void*);
void __cdecl SendPokeWorker(void*);
+ void __cdecl IgnoreFriendshipRequest(void*);
// Contacts handling
bool IsMyContact(MCONTACT, bool include_chat = false);
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index e6b67f6778..50ef5b342b 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -151,6 +151,13 @@ void InitContactMenus()
mi.pszService = "FacebookProto/ApproveFriendship";
CreateServiceFunction(mi.pszService,GlobalService<&FacebookProto::ApproveFriendship>);
g_hContactMenuItems[CMI_AUTH_GRANT] = Menu_AddContactMenuItem(&mi);
+
+ mi.position = -2000006014;
+ mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REVOKE);
+ mi.pszName = LPGEN("Deny friendship request");
+ mi.pszService = "FacebookProto/DenyFriendship";
+ CreateServiceFunction(mi.pszService, GlobalService<&FacebookProto::DenyFriendship>);
+ g_hContactMenuItems[CMI_AUTH_DENY] = Menu_AddContactMenuItem(&mi);
}
void UninitContactMenus()
@@ -176,8 +183,9 @@ int FacebookProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam)
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_ASK], ctrlPressed || type == CONTACT_NONE || !type);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_GRANT], ctrlPressed || type == CONTACT_APPROVE);
+ Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_DENY], ctrlPressed || type == CONTACT_APPROVE);
Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_REVOKE], ctrlPressed || type == CONTACT_FRIEND);
- Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_CANCEL], ctrlPressed || type == CONTACT_REQUEST);
+ Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_CANCEL], ctrlPressed || type == CONTACT_REQUEST);
Menu_ShowItem(g_hContactMenuItems[CMI_POKE], true);
}
diff --git a/protocols/FacebookRM/src/theme.h b/protocols/FacebookRM/src/theme.h
index 6c3f9a566a..e54e4d8f9d 100644
--- a/protocols/FacebookRM/src/theme.h
+++ b/protocols/FacebookRM/src/theme.h
@@ -35,8 +35,9 @@ void UninitContactMenus(void);
#define CMI_AUTH_ASK 3
#define CMI_AUTH_GRANT 4
#define CMI_AUTH_CANCEL 5
-#define CMI_POKE 6
-#define CMI_POST_STATUS 7
-#define CMI_VISIT_CONVERSATION 8
+#define CMI_AUTH_DENY 6
+#define CMI_POKE 7
+#define CMI_POST_STATUS 8
+#define CMI_VISIT_CONVERSATION 9
-#define CMITEMS_COUNT 9 \ No newline at end of file
+#define CMITEMS_COUNT 10 \ No newline at end of file