aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-02-09 10:38:39 +0100
committerdec05eba <dec05eba@protonmail.com>2021-02-09 10:38:39 +0100
commit07c8a8f1d469672be5196570608cf0d14b4d5b21 (patch)
tree56f42cec6c6d4a121cb5edfa9dd7a3809617ce3c /src/plugins
parent34fd966273c4544e4f58fe1b88fc8ea4bbd2b52d (diff)
Matrix: test: only show m.room.message types in room list description, sort room list by activity, improve initial sync time
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp84
1 files changed, 57 insertions, 27 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 9a785b6..6900dbc 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -23,7 +23,7 @@
static const char* SERVICE_NAME = "matrix";
static const char* OTHERS_ROOM_TAG = "tld.name.others";
// Filter without account data
-static const char* INITIAL_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":1,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}";
+static const char* INITIAL_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"types\":[\"m.room.message\"],\"limit\":1,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":1,\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}";
static const char* ADDITIONAL_MESSAGES_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"limit\":20,\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true}}}";
static const char* CONTINUE_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\"]},\"account_data\":{\"limit\":0,\"types\":[\"\"]},\"room\":{\"state\":{\"not_types\":[\"m.room.related_groups\",\"m.room.power_levels\",\"m.room.join_rules\",\"m.room.history_visibility\"],\"lazy_load_members\":true},\"timeline\":{\"lazy_load_members\":true},\"ephemeral\":{\"limit\":0,\"types\":[\"\"],\"lazy_load_members\":true},\"account_data\":{\"types\":[\"m.fully_read\",\"m.tag\"],\"lazy_load_members\":true}}}";
@@ -157,27 +157,35 @@ namespace QuickMedia {
size_t RoomData::prepend_messages_reverse(const std::vector<std::shared_ptr<Message>> &new_messages) {
std::lock_guard<std::recursive_mutex> lock(room_mutex);
+ int64_t last_new_message_timestamp = last_message_timestamp;
size_t num_new_messages = 0;
for(auto it = new_messages.begin(); it != new_messages.end(); ++it) {
if(message_by_event_id.find((*it)->event_id) == message_by_event_id.end()) {
+ if((*it)->type >= MessageType::TEXT && (*it)->type <= MessageType::FILE)
+ last_new_message_timestamp = std::max(last_new_message_timestamp, (*it)->timestamp);
message_by_event_id.insert(std::make_pair((*it)->event_id, *it));
messages.insert(messages.begin(), std::move(*it));
++num_new_messages;
}
}
+ last_message_timestamp = last_new_message_timestamp;
return num_new_messages;
}
size_t RoomData::append_messages(const std::vector<std::shared_ptr<Message>> &new_messages) {
std::lock_guard<std::recursive_mutex> lock(room_mutex);
+ int64_t last_new_message_timestamp = last_message_timestamp;
size_t num_new_messages = 0;
for(auto it = new_messages.begin(); it != new_messages.end(); ++it) {
if(message_by_event_id.find((*it)->event_id) == message_by_event_id.end()) {
+ if((*it)->type >= MessageType::TEXT && (*it)->type <= MessageType::FILE)
+ last_new_message_timestamp = std::max(last_new_message_timestamp, (*it)->timestamp);
message_by_event_id.insert(std::make_pair((*it)->event_id, *it));
messages.push_back(std::move(*it));
++num_new_messages;
}
}
+ last_message_timestamp = last_new_message_timestamp;
return num_new_messages;
}
@@ -398,6 +406,7 @@ namespace QuickMedia {
}
static void sort_room_body_items(std::vector<std::shared_ptr<BodyItem>> &room_body_items) {
+ #if 0
std::sort(room_body_items.begin(), room_body_items.end(), [](const std::shared_ptr<BodyItem> &body_item1, const std::shared_ptr<BodyItem> &body_item2) {
return strcasecmp(body_item1->get_title().c_str(), body_item2->get_title().c_str()) < 0;
});
@@ -414,6 +423,14 @@ namespace QuickMedia {
return strcasecmp(body_item1->get_title().c_str(), body_item2->get_title().c_str()) < 0;
});
#endif
+ #endif
+ std::sort(room_body_items.begin(), room_body_items.end(), [](const std::shared_ptr<BodyItem> &body_item1, const std::shared_ptr<BodyItem> &body_item2) {
+ RoomData *room1 = static_cast<RoomData*>(body_item1->userdata);
+ RoomData *room2 = static_cast<RoomData*>(body_item2->userdata);
+ int64_t room1_focus_sum = room1->last_message_timestamp;
+ int64_t room2_focus_sum = room2->last_message_timestamp;
+ return room1_focus_sum > room2_focus_sum;
+ });
}
void MatrixQuickMedia::update(MatrixPageType page_type) {
@@ -443,9 +460,22 @@ namespace QuickMedia {
}
static std::shared_ptr<Message> get_last_message_by_timestamp(const Messages &messages) {
+ #if 0
return *std::max_element(messages.begin(), messages.end(), [](const std::shared_ptr<Message> &message1, const std::shared_ptr<Message> &message2) {
return message1->timestamp < message2->timestamp;
});
+ #else
+ if(messages.empty())
+ return nullptr;
+ size_t last_message_index = 0;
+ for(size_t i = 1; i < messages.size(); ++i) {
+ if(messages[i]->type >= MessageType::TEXT && messages[i]->type <= MessageType::FILE && messages[i]->timestamp >= messages[last_message_index]->timestamp)
+ last_message_index = i;
+ }
+ if(messages[last_message_index]->type >= MessageType::TEXT && messages[last_message_index]->type <= MessageType::FILE)
+ return messages[last_message_index];
+ return nullptr;
+ #endif
}
static std::string message_to_room_description_text(Message *message) {
@@ -1019,32 +1049,6 @@ namespace QuickMedia {
{ "-m", "35" }
};
- sync_additional_messages_thread = std::thread([this]() {
- std::vector<CommandArg> additional_args = {
- { "-H", "Authorization: Bearer " + access_token },
- { "-m", "35" }
- };
-
- char url[1024];
- std::string filter_encoded = url_param_encode(ADDITIONAL_MESSAGES_FILTER);
- snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=0", homeserver.c_str(), filter_encoded.c_str());
-
- rapidjson::Document json_root;
- std::string err_msg;
- DownloadResult download_result = download_json(json_root, url, additional_args, use_tor, true, &err_msg);
- if(download_result != DownloadResult::OK) {
- fprintf(stderr, "/sync for additional messages failed\n");
- return;
- }
-
- // TODO: Test?
- //if(next_batch.empty())
- // clear_sync_cache_for_new_sync();
-
- additional_messages_queue.pop_wait();
- parse_sync_response(json_root, true, false);
- });
-
const rapidjson::Value *next_batch_json;
PluginResult result;
bool initial_sync = true;
@@ -1121,6 +1125,32 @@ namespace QuickMedia {
const rapidjson::Value &notification_json = GetMember(json_root, "notifications");
parse_notifications(notification_json);
+
+ {
+ std::vector<CommandArg> additional_args = {
+ { "-H", "Authorization: Bearer " + access_token },
+ { "-m", "35" }
+ };
+
+ char url[1024];
+ std::string filter_encoded = url_param_encode(ADDITIONAL_MESSAGES_FILTER);
+ snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=0", homeserver.c_str(), filter_encoded.c_str());
+
+ rapidjson::Document json_root;
+ std::string err_msg;
+ DownloadResult download_result = download_json(json_root, url, additional_args, use_tor, true, &err_msg);
+ if(download_result != DownloadResult::OK) {
+ fprintf(stderr, "/sync for additional messages failed\n");
+ return;
+ }
+
+ // TODO: Test?
+ //if(next_batch.empty())
+ // clear_sync_cache_for_new_sync();
+
+ additional_messages_queue.pop_wait();
+ parse_sync_response(json_root, true, false);
+ }
});
filter_encoded = url_param_encode(CONTINUE_FILTER);