aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-02-09 16:12:28 +0100
committerdec05eba <dec05eba@protonmail.com>2021-02-09 16:12:34 +0100
commitd7631f443388b638b357f50462d99663fdc2ee85 (patch)
tree997102a7ec71ba4125511ea0b4b3b82e3588e821 /src
parentcdab2f33dbc361eec1d6a90899a907e61a682f18 (diff)
I hate this garbage piece of shitware
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp27
-rw-r--r--src/plugins/Matrix.cpp22
2 files changed, 23 insertions, 26 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 4e84cda..db17982 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3257,6 +3257,7 @@ namespace QuickMedia {
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
+ orig_message->replaced_by = message;
}
it = unreferenced_events.erase(it);
} else {
@@ -3292,6 +3293,7 @@ namespace QuickMedia {
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
+ orig_message->replaced_by = message;
}
} else {
unreferenced_events.push_back(message);
@@ -3745,16 +3747,19 @@ namespace QuickMedia {
if(!message)
return;
- if(matrix->is_initial_sync_finished() && message->type >= MessageType::TEXT && message->type <= MessageType::FILE && is_window_focused && chat_state != ChatState::URL_SELECTION && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) {
+ if(matrix->is_initial_sync_finished() && message_is_timeline(message) && is_window_focused && chat_state != ChatState::URL_SELECTION && !setting_read_marker && read_marker_timer.getElapsedTime().asMilliseconds() >= read_marker_timeout_ms) {
+ Message *read_message = message;
+ if(message->replaced_by)
+ read_message = message->replaced_by.get();
// TODO: What if two messages have the same timestamp?
- if(message && !message->event_id.empty() && message->timestamp > current_room->last_read_message_timestamp) {
+ if(!read_message->event_id.empty() && read_message->timestamp > current_room->last_read_message_timestamp) {
//read_marker_timeout_ms = read_marker_timeout_ms_default;
- current_room->last_read_message_timestamp = message->timestamp;
+ current_room->last_read_message_timestamp = read_message->timestamp;
// TODO: What if the message is no longer valid?
setting_read_marker = true;
RoomData *room = current_room;
- std::string event_id = message->event_id;
- int64_t event_timestamp = message->timestamp;
+ std::string event_id = read_message->event_id;
+ int64_t event_timestamp = read_message->timestamp;
set_read_marker_future = [this, room, event_id, event_timestamp]() mutable {
if(matrix->set_read_marker(room, event_id, event_timestamp) != PluginResult::OK) {
fprintf(stderr, "Warning: failed to set read marker to %s\n", event_id.c_str());
@@ -4139,28 +4144,16 @@ namespace QuickMedia {
if(event.type == sf::Event::KeyPressed && event.key.control && event.key.alt && (chat_state == ChatState::NAVIGATING || chat_state == ChatState::URL_SELECTION)) {
if(event.key.code == sf::Keyboard::Up || (event.key.control && event.key.code == sf::Keyboard::K)) {
room_tabs[room_selected_tab].body->select_previous_item();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Down || (event.key.control && event.key.code == sf::Keyboard::J)) {
room_tabs[room_selected_tab].body->select_next_item();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::PageUp) {
room_tabs[room_selected_tab].body->select_previous_page();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::PageDown) {
room_tabs[room_selected_tab].body->select_next_page();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Home) {
room_tabs[room_selected_tab].body->select_first_item();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::End) {
room_tabs[room_selected_tab].body->select_last_item();
- move_room = true;
- goto chat_page_end;
} else if(event.key.code == sf::Keyboard::Escape) {
move_room = false;
goto chat_page_end;
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);