aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-04 22:38:33 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-04 22:38:33 +0200
commitcfef90021917df0052bb49e9e35298260e7ca38c (patch)
treeb922f32067a37d717d5df512e92c064ccae0753a /src/plugins
parent5267b66a8822205187399290f44f27d720b01dda (diff)
Matrix: remove initial delay when entering room
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 34c47f1..ca3fc28 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -42,20 +42,30 @@ namespace QuickMedia {
return user->read_marker_event_id;
}
- void RoomData::prepend_messages_reverse(std::vector<std::shared_ptr<Message>> new_messages) {
+ size_t RoomData::prepend_messages_reverse(std::vector<std::shared_ptr<Message>> new_messages) {
std::lock_guard<std::mutex> lock(room_mutex);
- for(auto &new_message : new_messages) {
- message_by_event_id[new_message->event_id] = new_message;
+ size_t num_inserted = 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()) {
+ message_by_event_id.insert(std::make_pair((*it)->event_id, *it));
+ messages.insert(messages.begin(), std::move(*it));
+ ++num_inserted;
+ }
}
- messages.insert(messages.begin(), new_messages.rbegin(), new_messages.rend());
+ return num_inserted;
}
- void RoomData::append_messages(std::vector<std::shared_ptr<Message>> new_messages) {
+ size_t RoomData::append_messages(std::vector<std::shared_ptr<Message>> new_messages) {
std::lock_guard<std::mutex> lock(room_mutex);
- for(auto &new_message : new_messages) {
- message_by_event_id[new_message->event_id] = new_message;
+ size_t num_inserted = 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()) {
+ message_by_event_id.insert(std::make_pair((*it)->event_id, *it));
+ messages.push_back(std::move(*it));
+ ++num_inserted;
+ }
}
- messages.insert(messages.end(), new_messages.begin(), new_messages.end());
+ return num_inserted;
}
std::shared_ptr<Message> RoomData::get_message_by_id(const std::string &id) {
@@ -225,6 +235,7 @@ namespace QuickMedia {
}
// TODO: Thread safe?
+ /*
if(!room->initial_fetch_finished) {
PluginResult result = get_previous_room_messages(room);
if(result == PluginResult::OK) {
@@ -234,6 +245,7 @@ namespace QuickMedia {
return result;
}
}
+ */
room->acquire_room_lock();
room_messages_to_body_items(room->get_messages_thread_unsafe().data(), room->get_messages_thread_unsafe().size(), result_items);
@@ -249,6 +261,7 @@ namespace QuickMedia {
return PluginResult::ERR;
}
+ /*
if(!room->initial_fetch_finished) {
PluginResult result = get_previous_room_messages(room);
if(result == PluginResult::OK) {
@@ -258,6 +271,7 @@ namespace QuickMedia {
return result;
}
}
+ */
room->acquire_room_lock();
size_t num_new_messages = room->get_messages_thread_unsafe().size() - room->last_read_index;
@@ -670,10 +684,10 @@ namespace QuickMedia {
// TODO: Loop and std::move instead? doesn't insert create copies?
if(message_dir == MessageDirection::BEFORE) {
- room_data->prepend_messages_reverse(std::move(new_messages));
+ size_t num_inserted_messages = room_data->prepend_messages_reverse(std::move(new_messages));
// TODO: Is this thread-safe?
if(room_data->last_read_index != 0)
- room_data->last_read_index += new_messages.size();
+ room_data->last_read_index += num_inserted_messages;
} else if(message_dir == MessageDirection::AFTER) {
room_data->append_messages(std::move(new_messages));
}