From 1ff0429a1eeb75f2d84ec89fd06a06acf9c0219b Mon Sep 17 00:00:00 2001 From: ikeblaster Date: Thu, 20 Feb 2020 15:10:33 +0100 Subject: Facebook: group chat loading improvement Loading only unarchived group chats, where user is still subscribed. When thread_count limit is sent, response is sorted. Hardcoded to 40 threads - not ideal, since response contains also normal chats (those are skipped). Better solution proposed in TODO. --- protocols/Facebook/src/proto.h | 4 ++-- protocols/Facebook/src/server.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'protocols/Facebook') diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index 2f6df655b3..bd3eca0938 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -249,8 +249,8 @@ along with this program. If not, see . * The query hash for the `ThreadListQuery`. * * Key mapping: - * 0: folder_tag - * 1: thread_count + * 0: folder_tag (INBOX, PENDING, ARCHIVED, OTHER, UNREAD) + * 1: thread_count (result is sorted from newest to oldest when parameter is sent) * 2: include_thread_info * 3: verification_type * 4: hash_key diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp index fbff76af40..faa8032d7b 100644 --- a/protocols/Facebook/src/server.cpp +++ b/protocols/Facebook/src/server.cpp @@ -267,8 +267,10 @@ FacebookUser* FacebookProto::RefreshThread(CMStringW& wszId) { void FacebookProto::RefreshThreads() { + int threadsLimit = 40; + auto * pReq = CreateRequestGQL(FB_API_QUERY_THREADS); - JSONNode json; json << CHAR_PARAM("2", "true") << CHAR_PARAM("12", "false") << CHAR_PARAM("13", "false"); + JSONNode json; json << INT_PARAM("1", threadsLimit) << CHAR_PARAM("2", "true") << CHAR_PARAM("12", "false") << CHAR_PARAM("13", "false"); pReq << CHAR_PARAM("query_params", json.write().c_str()); pReq->CalcSig(); @@ -277,8 +279,12 @@ void FacebookProto::RefreshThreads() auto &root = reply.data()["viewer"]["message_threads"]; for (auto &n : root["nodes"]) { - RefreshThread(n); + if (n["is_group_thread"].as_bool() && n["is_viewer_subscribed"].as_bool() && !n["has_viewer_archived"].as_bool()) + RefreshThread(n); } + + // TODO: save timestamp of last message/action/... into DB + // TODO: lower threadsLimit to 10, load next pages if timestamp of last message is higher than timestamp in DB } } -- cgit v1.2.3