summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-01-08 22:25:39 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-01-08 22:25:39 +0300
commit1e5ae8efefc6f50082c1c1734c763aab2fb1b7f5 (patch)
tree3c6988ab32b6458289a830d7bf544a8357119246 /protocols/FacebookRM
parent2f058ad0b6a6df7074f5ca05b37b8f4717d9eb13 (diff)
adds support for exiting groupchats
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/chat.cpp10
-rw-r--r--protocols/FacebookRM/src/client.h1
-rw-r--r--protocols/FacebookRM/src/json.cpp4
-rw-r--r--protocols/FacebookRM/src/messages.cpp32
-rw-r--r--protocols/FacebookRM/src/process.cpp22
5 files changed, 54 insertions, 15 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index 85e31f545e..7ccaef2459 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -118,6 +118,12 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
break;
case IDM_EXIT:
+ {
+ std::string thread_id = _T2A(hook->ptszID, CP_UTF8);
+ auto it = facy.chat_rooms.find(thread_id);
+ if (it != facy.chat_rooms.end())
+ facy.sendRequest(facy.exitThreadRequest(it->second));
+ }
break;
}
break;
@@ -189,10 +195,6 @@ void FacebookProto::AddChatContact(const char *chat_id, const chatroom_participa
void FacebookProto::RemoveChatContact(const char *chat_id, const char *id, const char *name)
{
- // We dont want to remove our self-contact from chat. Ever.
- if (!mir_strcmp(id, facy.self_.user_id.c_str()))
- return;
-
ptrW tchat_id(mir_a2u(chat_id));
ptrW tnick(mir_a2u_cp(name, CP_UTF8));
ptrW tid(mir_a2u(id));
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index e3875ab14e..bcc161d3fc 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -239,6 +239,7 @@ public:
HttpRequest* sendMessageRequest(const char *userId, const char *threadId, const char *messageId, const char *messageText, bool isChat, const char *captcha, const char *captchaPersistData);
HttpRequest* sendTypingRequest(const char *userId, bool isChat, bool isTyping);
HttpRequest* markMessageReadRequest(const LIST<char> &ids);
+ HttpRequest* exitThreadRequest(facebook_chatroom *fbc);
// notifications.cpp
HttpRequest* getNotificationsRequest(int count);
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 69dd1e02fa..ee743ec2f4 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -103,6 +103,10 @@ void FacebookProto::ParseMessageType(facebook_message &message, const JSONNode &
else if (logType == "log:unsubscribe") {
message.type = UNSUBSCRIBE;
+ const JSONNode &client_id = log_data_["client_message_id"];
+ if (client_id)
+ message.message_id = client_id.as_string();
+
const JSONNode &fbids_ = log_data_["removed_participants"];
for (auto &it2 : fbids_) {
std::string id = it2.as_string().substr(5); // strip "fbid:" prefix
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 5957cf4ba7..794225de2a 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -343,3 +343,35 @@ HttpRequest* facebook_client::markMessageReadRequest(const LIST<char> &ids)
return p;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+HttpRequest* facebook_client::exitThreadRequest(facebook_chatroom *fbc)
+{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/messaging/send/");
+
+ p->Url << INT_PARAM("dpr", 1);
+
+ std::string msgid = utils::text::rand_string(15);
+
+ p->Body
+ << CHAR_PARAM("client", "mercury")
+ << CHAR_PARAM("action_type", "ma-type:log-message")
+ << CHAR_PARAM("log_message_data[removed_participants][0]", ("fbid:" + self_.user_id).c_str())
+ << CHAR_PARAM("log_message_type", "log:unsubscribe")
+ << CHAR_PARAM("message_id", msgid.c_str())
+ << CHAR_PARAM("offline_threading_id", msgid.c_str())
+ << CHAR_PARAM("source", "source:chat:web")
+ << CHAR_PARAM("thread_fbid", fbc->thread_id.substr(3).c_str())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << INT64_PARAM("timestamp", ::time(nullptr) * 1000)
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("__pc", "PHASED:DEFAULT")
+ << INT_PARAM("__a", 1)
+ << INT_PARAM("__be", 1);
+
+ return p;
+}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index bb228332c4..cf11d945bf 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -781,19 +781,12 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
case MESSAGE:
UpdateChat(fbc->thread_id.c_str(), msg.user_id.c_str(), name.c_str(), msg.message_text.c_str(), msg.time);
break;
+
case ADMIN_TEXT:
UpdateChat(thread_id.c_str(), nullptr, nullptr, msg.message_text.c_str());
break;
- case UNSUBSCRIBE:
- // this is our own request to leave the groupchat
- if (_atoi64(msg.message_id.c_str()) == fbc->tmp_msgid) {
- Chat_Terminate(m_szModuleName, _A2T(fbc->thread_id.c_str()), true);
- facy.chat_rooms.erase(thread_id);
- delete fbc;
- break;
- }
- // fall through
+ case UNSUBSCRIBE:
case SUBSCRIBE:
UpdateChat(thread_id.c_str(), nullptr, nullptr, msg.message_text.c_str());
{
@@ -815,8 +808,15 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
if (jt != fbc->participants.end()) {
if (msg.type == SUBSCRIBE)
AddChatContact(thread_id.c_str(), jt->second, msg.isUnread);
- else
- RemoveChatContact(thread_id.c_str(), jt->second.user_id.c_str(), jt->second.nick.c_str());
+ else {
+ if (jt->second.user_id == facy.self_.user_id) {
+ // we exited the thread
+ Chat_Terminate(m_szModuleName, _A2T(fbc->thread_id.c_str()), true);
+ facy.chat_rooms.erase(thread_id);
+ delete fbc;
+ }
+ else RemoveChatContact(thread_id.c_str(), jt->second.user_id.c_str(), jt->second.nick.c_str());
+ }
}
}
}