diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-04 20:45:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-04 20:45:00 +0300 |
commit | 5b32a855e518f67589fd49837795a605a19badce (patch) | |
tree | 58e6664efc8c826a35e72e4d1a54e8e957b75c42 /protocols/FacebookRM/src/messages.cpp | |
parent | 823e3839b108658811f689f959f51058effd82ac (diff) |
code reordering, not to reassemble the whole project on each change in headers
Diffstat (limited to 'protocols/FacebookRM/src/messages.cpp')
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index e634473c6d..d6284c43ea 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -220,3 +220,123 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, cont.path = dir; CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); } + +////////////////////////////////////////////////////////////////////////////////////////// + +SendMessageRequest::SendMessageRequest( + facebook_client *fc, + const char *userId, + const char *threadId, + const char *messageId, + const char *messageText, + bool isChat, + const char *captcha, + const char *captchaPersistData) + : HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/messaging/send/") +{ + // Don't notify errors for this request, because we're getting them inline in messaging window + NotifyErrors = false; + + // Use own persistent connection for sending messages + Persistent = MESSAGES; + + Url << INT_PARAM("dpr", 1); + + if (mir_strlen(captcha) > 0) + Body << CHAR_PARAM("captcha_persist_data", captchaPersistData) << CHAR_PARAM("captcha_response", captcha); + + Body << CHAR_PARAM("client", "mercury") << CHAR_PARAM("action_type", "ma-type:user-generated-message"); + + // Experimental sticker sending support + std::string message_text = messageText; // FIXME: Rewrite this without std::string... + if (message_text.substr(0, 10) == "[[sticker:" && message_text.substr(message_text.length() - 2) == "]]") + // TODO: For sending GIF images instead of "sticker_id=" there is "image_ids[0]=", otherwise it's same + Body + << "body=" + << CHAR_PARAM("sticker_id", ptrA(mir_urlEncode(message_text.substr(10, message_text.length() - 10 - 2).c_str()))) + << BOOL_PARAM("has_attachment", true); + else + Body << CHAR_PARAM("body", ptrA(mir_urlEncode(messageText))) << BOOL_PARAM("has_attachment", false); + + Body + << INT_PARAM("ephemeral_ttl_mode", 0) + << CHAR_PARAM("message_id", messageId) + << CHAR_PARAM("offline_threading_id", messageId); // Same as message ID + + if (isChat) { + // NOTE: Remove "id." prefix as here we need to give threadFbId and not threadId + std::string threadFbid = threadId; // FIXME: Rewrite this without std::string... + if (threadFbid.substr(0, 3) == "id.") + threadFbid = threadFbid.substr(3); + + Body << CHAR_PARAM("thread_fbid", threadFbid.c_str()); + } + else + Body + << CHAR_PARAM("other_user_fbid", userId) + << CHAR_PARAM("specific_to_list[0]", CMStringA(::FORMAT, "fbid:%s", userId)) + << CHAR_PARAM("specific_to_list[1]", CMStringA(::FORMAT, "fbid:%s", fc->self_.user_id.c_str())); + + Body + // << "signature_id=" // TODO: How to generate signature ID? It is present only when sending via "mercury" + << CHAR_PARAM("source", "source:chat:web") // or "source:titan:web" for web_messenger + << CHAR_PARAM("timestamp", utils::time::mili_timestamp().c_str()) + << CHAR_PARAM("ui_push_phase", "V3") + << CHAR_PARAM("__user", fc->self_.user_id.c_str()) + << CHAR_PARAM("__dyn", fc->__dyn()) + << CHAR_PARAM("__req", fc->__req()) + << CHAR_PARAM("__rev", fc->__rev()) + << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str()) + << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str()) + << INT_PARAM("__a", 1) + << CHAR_PARAM("__pc", "PHASED:DEFAULT") + << INT_PARAM("__be", -1); +} + +SendTypingRequest::SendTypingRequest(facebook_client *fc, const char *userId, bool isChat, bool isTyping) : + HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/messaging/typ.php") +{ + Url << INT_PARAM("dpr", 1); + + ptrA idEncoded(mir_urlEncode(userId)); + + Body + << INT_PARAM("typ", isTyping ? 1 : 0) + << CHAR_PARAM("to", isChat ? "" : idEncoded) + << CHAR_PARAM("thread", idEncoded) + << CHAR_PARAM("source", "mercury-chat") + << CHAR_PARAM("__user", fc->self_.user_id.c_str()) + << CHAR_PARAM("__dyn", fc->__dyn()) + << CHAR_PARAM("__req", fc->__req()) + << CHAR_PARAM("__rev", fc->__rev()) + << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str()) + << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str()) + << CHAR_PARAM("__pc", "PHASED:DEFAULT") + << INT_PARAM("__a", 1) + << INT_PARAM("__be", -1); +} + +MarkMessageReadRequest::MarkMessageReadRequest(facebook_client *fc, const LIST<char> &ids) : + HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/mercury/change_read_status.php") +{ + Url << INT_PARAM("__a", 1); + + for (int i = 0; i < ids.getCount(); i++) { + std::string id_ = ids[i]; + // NOTE: Remove "id." prefix as here we need to give threadFbId and not threadId + if (id_.substr(0, 3) == "id.") + id_ = id_.substr(3); + + CMStringA id(::FORMAT, "ids[%s]", ptrA(mir_urlEncode(id_.c_str()))); + Body << BOOL_PARAM(id, true); + } + + Body + << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str()) + << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str()) + << CHAR_PARAM("__user", fc->self_.user_id.c_str()) + << CHAR_PARAM("__dyn", fc->__dyn()) + << CHAR_PARAM("__req", fc->__req()) + << CHAR_PARAM("__rev", fc->__rev()) + << INT_PARAM("__a", 1); +} |