From fd699d287de23771c17e395d79aa38287453a850 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Nov 2020 18:48:43 +0100 Subject: Matrix: readd additional messages sync, remove reply/edit formatting from room description --- src/plugins/Matrix.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 278ffa3..95ce1dc 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -230,7 +230,9 @@ namespace QuickMedia { void RoomData::set_prev_batch(const std::string &new_prev_batch) { std::lock_guard lock(room_mutex); - prev_batch = new_prev_batch; + // TODO: Check if this always works and if it also works for other homeservers than synapse + if(prev_batch.empty() || new_prev_batch < prev_batch) + prev_batch = new_prev_batch; } std::string RoomData::get_prev_batch() { @@ -455,7 +457,7 @@ namespace QuickMedia { if(message->type == MessageType::REACTION) return "Reacted with: " + extract_first_line_elipses(message->body, 150); else - return extract_first_line_elipses(message->body, 150); + return extract_first_line_elipses(message_get_body_remove_formatting(message), 150); } void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache) { @@ -1017,7 +1019,7 @@ namespace QuickMedia { { "-H", "Authorization: Bearer " + access_token }, { "-m", "35" } }; -#if 0 + sync_additional_messages_thread = std::thread([this]() { std::vector additional_args = { { "-H", "Authorization: Bearer " + access_token }, @@ -1043,7 +1045,7 @@ namespace QuickMedia { additional_messages_queue.pop_wait(); parse_sync_response(json_root, true); }); -#endif + const rapidjson::Value *next_batch_json; PluginResult result; bool initial_sync = true; @@ -1388,7 +1390,7 @@ namespace QuickMedia { const rapidjson::Value &timeline_json = GetMember(it.value, "timeline"); if(timeline_json.IsObject()) { - if(!sync_is_cache && !room->has_prev_batch()) { + if(is_additional_messages_sync) { // This may be non-existent if this is the first event in the room const rapidjson::Value &prev_batch_json = GetMember(timeline_json, "prev_batch"); if(prev_batch_json.IsString()) @@ -2338,16 +2340,8 @@ namespace QuickMedia { PluginResult Matrix::get_previous_room_messages(RoomData *room_data, bool latest_messages, size_t &num_new_messages) { num_new_messages = 0; std::string from = room_data->get_prev_batch(); - if(from.empty()) { - fprintf(stderr, "Info: missing previous batch for room: %s, using /sync next batch\n", room_data->id.c_str()); - // TODO: When caching /sync, remember to add lock around getting next_batch! - from = get_next_batch(); - if(from.empty()) { - fprintf(stderr, "Warning: missing next batch, using END\n"); - from = "END"; - //return PluginResult::OK; - } - } + if(from.empty()) + from = "END"; rapidjson::Document request_data(rapidjson::kObjectType); request_data.AddMember("lazy_load_members", true, request_data.GetAllocator()); @@ -2535,7 +2529,7 @@ namespace QuickMedia { return PluginResult::OK; } - static std::string remove_reply_formatting(const std::string &str) { + std::string remove_reply_formatting(const std::string &str) { if(strncmp(str.c_str(), "> <@", 4) == 0) { size_t index = str.find("> ", 4); if(index != std::string::npos) { @@ -2547,6 +2541,13 @@ namespace QuickMedia { return str; } + std::string message_get_body_remove_formatting(Message *message) { + if(message->related_event_type == RelatedEventType::REPLY || message->related_event_type == RelatedEventType::EDIT) + return remove_reply_formatting(message->body); + else + return message->body; + } + static std::string block_quote(const std::string &str) { std::string result; for(char c : str) { -- cgit v1.2.3