diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Matrix.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index f97f574..cc6f673 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -161,7 +161,7 @@ namespace QuickMedia { 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) + if(message_is_timeline((*it).get())) 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)); @@ -178,7 +178,7 @@ namespace QuickMedia { 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) + if(message_is_timeline((*it).get())) 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)); @@ -479,10 +479,10 @@ namespace QuickMedia { 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) + if(message_is_timeline(messages[i].get()) && 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) + if(message_is_timeline(messages[last_message_index].get())) return messages[last_message_index]; return nullptr; #endif @@ -500,7 +500,7 @@ namespace QuickMedia { } void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync, bool sync_is_cache) { - time_t read_marker_message_timestamp = room->last_read_message_timestamp; + time_t read_marker_message_timestamp = room->read_marker_event_timestamp; std::shared_ptr<UserInfo> me = matrix->get_me(room); std::string my_user_read_marker; if(me && read_marker_message_timestamp == 0) { @@ -1629,7 +1629,7 @@ namespace QuickMedia { if(!timestamp_json.IsInt64()) continue; - room_data->last_read_message_timestamp = timestamp_json.GetInt64(); + room_data->read_marker_event_timestamp = timestamp_json.GetInt64(); } } } @@ -1740,6 +1740,10 @@ namespace QuickMedia { return false; } + bool message_is_timeline(Message *message) { + return message->type >= MessageType::TEXT && message->type <= MessageType::FILE; + } + size_t Matrix::events_add_messages(const rapidjson::Value &events_json, RoomData *room_data, MessageDirection message_dir, bool has_unread_notifications) { if(!events_json.IsArray()) return 0; @@ -3395,13 +3399,13 @@ namespace QuickMedia { std::string server_response; DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/rooms/" + room->id + "/read_markers", server_response, std::move(additional_args), use_tor, true); - if(download_result != DownloadResult::OK) return download_result_to_plugin_result(download_result); auto me = get_me(room); if(me) room->set_user_read_marker(me, event_id); - return set_qm_last_read_message_timestamp(room, event_timestamp); + set_qm_last_read_message_timestamp(room, event_timestamp); + return download_result_to_plugin_result(download_result); } PluginResult Matrix::set_qm_last_read_message_timestamp(RoomData *room, int64_t timestamp) { @@ -3419,7 +3423,7 @@ namespace QuickMedia { { "--data-binary", buffer.GetString() } }; - room->last_read_message_timestamp = timestamp; + room->read_marker_event_timestamp = timestamp; std::string server_response; DownloadResult download_result = download_to_string(homeserver + "/_matrix/client/r0/user/" + my_user_id + "/rooms/" + room->id + "/account_data/qm.last_read_message_timestamp", server_response, std::move(additional_args), use_tor, true); |