diff options
Diffstat (limited to 'src/plugins/Matrix.cpp')
-rw-r--r-- | src/plugins/Matrix.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 5355208..fae8451 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1667,7 +1667,11 @@ namespace QuickMedia { FILE *sync_cache_file; const rapidjson::Value *next_batch_json = nullptr; - load_qm_read_markers_from_account_data(); // TODO: Remove when https://github.com/matrix-org/synapse/issues/14444 is fixed, if ever. + if(!load_qm_read_markers_from_account_data()) { // TODO: Remove when https://github.com/matrix-org/synapse/issues/14444 is fixed, if ever. + show_notification("QuickMedia", "Failed to connect to matrix homeserver. Is your internet down?", Urgency::CRITICAL); + sync_running = false; + return; + } std::ifstream sync_cache_file_stream; sync_cache_file_stream.open(matrix_cache_dir.data.c_str(), std::ifstream::in | std::ifstream::binary); @@ -5287,7 +5291,11 @@ namespace QuickMedia { rapidjson::Document request_data(rapidjson::kObjectType); { std::lock_guard<std::recursive_mutex> lock(room_data_mutex); - load_qm_read_markers_from_account_data(); // TODO: Only do this if multiple instances of quickmedia matrix is running (on the same account) + if(!load_qm_read_markers_from_account_data()) { // TODO: Only do this if multiple instances of quickmedia matrix is running (on the same account) + fprintf(stderr, "Error: load_qm_read_markers_from_account_data failed, failed to set read marker\n"); + return PluginResult::ERR; + } + qm_read_markers_by_room_cache[room->id] = timestamp; room->read_marker_event_timestamp = timestamp; for(const auto &[key, val] : qm_read_markers_by_room_cache) { @@ -5314,7 +5322,7 @@ namespace QuickMedia { return PluginResult::OK; } - void Matrix::load_qm_read_markers_from_account_data() { + bool Matrix::load_qm_read_markers_from_account_data() { std::vector<CommandArg> additional_args = { { "-H", "content-type: application/json" }, { "-H", "Authorization: Bearer " + access_token } @@ -5325,11 +5333,11 @@ namespace QuickMedia { DownloadResult download_result = download_json(json_root, homeserver + "/_matrix/client/r0/user/" + my_user_id + "/account_data/qm.last_read_message_timestamp", std::move(additional_args), true, &err_msg); if(download_result != DownloadResult::OK) { fprintf(stderr, "Warning: failed to get account qm.last_read_message_timestamp\n"); - return; + return false; } if(!json_root.IsObject()) - return; + return false; std::lock_guard<std::recursive_mutex> lock(room_data_mutex); qm_read_markers_by_room_cache.clear(); @@ -5343,6 +5351,8 @@ namespace QuickMedia { rooms[room_it->second]->read_marker_event_timestamp = obj.value.GetInt64(); qm_read_markers_by_room_cache[std::move(room_id)] = obj.value.GetInt64(); } + + return true; } PluginResult Matrix::join_room(const std::string &room_id_or_name) { |