From 76e1aebbe075287a8297194b38343467c76dd964 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 26 Apr 2021 18:37:00 +0200 Subject: Fix soundcloud (fetch client id), add authors to mangakatana, some other fixes --- src/plugins/Matrix.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/plugins/Matrix.cpp') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 57c879e..0c06458 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -489,14 +489,15 @@ namespace QuickMedia { } static std::string message_to_room_description_text(Message *message) { + std::string body = strip(message->body); if(message->type == MessageType::REACTION) - return "Reacted with: " + extract_first_line_elipses(message->body, 150); + return "Reacted with: " + extract_first_line_elipses(body, 150); else if(message->related_event_type == RelatedEventType::REPLY) - return extract_first_line_elipses(remove_reply_formatting(message->body), 150); + return extract_first_line_elipses(remove_reply_formatting(body), 150); else if(message->related_event_type == RelatedEventType::EDIT) - return "Edited: " + extract_first_line_elipses(remove_reply_formatting(message->body), 150); + return "Edited: " + extract_first_line_elipses(remove_reply_formatting(body), 150); else - return extract_first_line_elipses(message->body, 150); + return extract_first_line_elipses(body, 150); } void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache, Body *chat_body, bool messages_tab_visible) { @@ -1090,18 +1091,20 @@ namespace QuickMedia { } } - void Matrix::start_sync(MatrixDelegate *delegate, bool &cached) { + bool Matrix::start_sync(MatrixDelegate *delegate, bool &cached) { cached = true; if(sync_running) - return; + return true; assert(!this->delegate); assert(!access_token.empty()); // Need to be logged in this->delegate = delegate; Path matrix_cache_dir = get_cache_dir().join("matrix"); - if(create_directory_recursive(matrix_cache_dir) != 0) + if(create_directory_recursive(matrix_cache_dir) != 0) { fprintf(stderr, "Failed to create matrix cache directory\n"); + return false; + } matrix_cache_dir.join("sync_data.json"); cached = (get_file_type(matrix_cache_dir) == FileType::REGULAR); @@ -1196,6 +1199,7 @@ namespace QuickMedia { result = parse_sync_response(json_root, false, initial_sync); if(result != PluginResult::OK) { fprintf(stderr, "Failed to parse sync response\n"); + initial_sync = false; goto sync_end; } @@ -1206,6 +1210,7 @@ namespace QuickMedia { } else { //set_next_batch("Invalid"); fprintf(stderr, "Matrix: missing next batch\n"); + initial_sync = false; goto sync_end; } @@ -1288,6 +1293,8 @@ namespace QuickMedia { std::this_thread::sleep_for(std::chrono::milliseconds(500)); } }); + + return true; } void Matrix::stop_sync() { @@ -1313,6 +1320,10 @@ namespace QuickMedia { delegate = nullptr; sync_failed = false; sync_fail_reason.clear(); + set_next_batch(""); + invites.clear(); + filter_cached.reset(); + my_events_transaction_ids.clear(); } bool Matrix::is_initial_sync_finished() const { @@ -3382,7 +3393,7 @@ namespace QuickMedia { } PluginResult Matrix::logout() { - assert(!sync_running); + stop_sync(); Path session_path = get_storage_dir().join(SERVICE_NAME).join("session.json"); remove(session_path.data.c_str()); @@ -3402,10 +3413,6 @@ namespace QuickMedia { homeserver.clear(); homeserver_domain.clear(); upload_limit.reset(); - set_next_batch(""); - invites.clear(); - filter_cached.reset(); - my_events_transaction_ids.clear(); return PluginResult::OK; } @@ -3950,7 +3957,7 @@ namespace QuickMedia { // TODO: Use at param? which is room->get_prev_batch(); char url[512]; - snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/members?membership=join", homeserver.c_str(), room->id.c_str()); + snprintf(url, sizeof(url), "%s/_matrix/client/r0/rooms/%s/members?not_membership=leave", homeserver.c_str(), room->id.c_str()); rapidjson::Document json_root; DownloadResult download_result = download_json(json_root, url, std::move(additional_args), true); -- cgit v1.2.3