aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 446cdf1..b102cfa 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -325,12 +325,13 @@ namespace QuickMedia {
room_tags_page->remove_room_body_item_from_tag(room_body_item_by_room[room], tag);
}
- void MatrixQuickMedia::room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache) {
+ void MatrixQuickMedia::room_add_new_messages(RoomData *room, const Messages &messages, bool is_initial_sync, bool sync_is_cache, MessageDirection message_dir) {
std::lock_guard<std::mutex> lock(pending_room_messages_mutex);
auto &room_messages_data = pending_room_messages[room];
room_messages_data.messages.insert(room_messages_data.messages.end(), messages.begin(), messages.end());
room_messages_data.is_initial_sync = is_initial_sync;
room_messages_data.sync_is_cache = sync_is_cache;
+ room_messages_data.message_dir = message_dir;
}
void MatrixQuickMedia::add_invite(const std::string &room_id, const Invite &invite) {
@@ -408,7 +409,6 @@ namespace QuickMedia {
show_notification("QuickMedia matrix - " + unread_notification.sender + " (" + it.first->get_name() + ")", unread_notification.body);
}
}
- update_room_description(it.first, false);
}
//if(!unread_notifications.empty()) {
// rooms_page->sort_rooms();
@@ -434,10 +434,7 @@ namespace QuickMedia {
});
}
- void MatrixQuickMedia::update_room_description(RoomData *room, bool is_initial_sync) {
- room->acquire_room_lock();
- const Messages &messages = room->get_messages_thread_unsafe();
-
+ void MatrixQuickMedia::update_room_description(RoomData *room, Messages &new_messages, bool is_initial_sync) {
time_t read_marker_message_timestamp = 0;
std::shared_ptr<UserInfo> me = matrix->get_me(room);
if(me) {
@@ -446,25 +443,21 @@ namespace QuickMedia {
read_marker_message_timestamp = read_marker_message->timestamp;
}
- std::shared_ptr<Message> last_message = get_last_message_by_timestamp(messages);
- if(!last_message) {
- room->release_room_lock();
+ std::shared_ptr<Message> last_new_message = get_last_message_by_timestamp(new_messages);
+ if(!last_new_message)
return;
- }
auto last_message_it = last_message_by_room.find(room);
if(last_message_it != last_message_by_room.end()) {
- if(last_message->timestamp > last_message_it->second->timestamp)
- last_message_it->second = last_message;
- else
- last_message = last_message_it->second;
+ if(last_new_message->timestamp > last_message_it->second->timestamp)
+ last_message_it->second = last_new_message;
} else {
- last_message_by_room[room] = last_message;
+ last_message_by_room[room] = last_new_message;
}
Message *last_unread_message = nullptr;
- if(last_message->timestamp > read_marker_message_timestamp)
- last_unread_message = last_message.get();
+ if(last_new_message->timestamp > read_marker_message_timestamp)
+ last_unread_message = last_new_message.get();
BodyItem *room_body_item = static_cast<BodyItem*>(room->userdata);
assert(room_body_item);
@@ -481,10 +474,8 @@ namespace QuickMedia {
rooms_page->move_room_to_top(room);
room_tags_page->move_room_to_top(room);
} else if(is_initial_sync) {
- room_body_item->set_description(matrix->message_get_author_displayname(last_message.get()) + ": " + extract_first_line_elipses(last_message->body, 150));
+ room_body_item->set_description(matrix->message_get_author_displayname(last_new_message.get()) + ": " + extract_first_line_elipses(last_new_message->body, 150));
}
-
- room->release_room_lock();
}
void MatrixQuickMedia::update_pending_room_messages(MatrixPageType page_type) {
@@ -509,7 +500,7 @@ namespace QuickMedia {
}
}
- update_room_description(room, is_initial_sync);
+ update_room_description(room, messages, is_initial_sync);
}
pending_room_messages.clear();
}
@@ -1065,9 +1056,6 @@ namespace QuickMedia {
goto sync_end;
}
- if(next_batch.empty())
- additional_messages_queue.push(true);
-
next_batch_json = &GetMember(json_root, "next_batch");
if(next_batch_json->IsString()) {
set_next_batch(next_batch_json->GetString());
@@ -1101,6 +1089,7 @@ namespace QuickMedia {
});
filter_encoded = url_param_encode(CONTINUE_FILTER);
+ additional_messages_queue.push(true);
}
#if 0
@@ -1279,7 +1268,6 @@ namespace QuickMedia {
fprintf(stderr, "Warning: got notification in unknown room %s\n", room_id.c_str());
continue;
}
- room->unread_notification_count++;
std::string event_id(event_id_json.GetString(), event_id_json.GetStringLength());
std::string sender(sender_json.GetString(), sender_json.GetStringLength());
@@ -1380,7 +1368,7 @@ namespace QuickMedia {
// TODO: Use /_matrix/client/r0/notifications ? or remove this and always look for displayname/user_id in messages
bool has_unread_notifications = false;
const rapidjson::Value &unread_notification_json = GetMember(it.value, "unread_notifications");
- if(unread_notification_json.IsObject() && is_initial_sync_finished() && !is_additional_messages_sync) {
+ if(unread_notification_json.IsObject() && !is_additional_messages_sync) {
const rapidjson::Value &highlight_count_json = GetMember(unread_notification_json, "highlight_count");
if(highlight_count_json.IsNumber() && highlight_count_json.GetInt64() > 0) {
room->unread_notification_count = highlight_count_json.GetInt64();
@@ -1679,7 +1667,7 @@ namespace QuickMedia {
}
if(delegate)
- delegate->room_add_new_messages(room_data, new_messages, next_batch.empty(), sync_is_cache);
+ delegate->room_add_new_messages(room_data, new_messages, next_batch.empty(), sync_is_cache, message_dir);
}
std::shared_ptr<Message> Matrix::parse_message_event(const rapidjson::Value &event_item_json, RoomData *room_data) {