aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-11-13 02:05:27 +0100
committerdec05eba <dec05eba@protonmail.com>2022-11-13 02:05:27 +0100
commitaea90e2c43d6dbf8b8276e1209f4d4abe1cea128 (patch)
treea21cd16b95e027d7e277e25089b63b45e2bdb735 /src/plugins
parent01f23292bf2451a0c7b9ada88c6314dcb09509b1 (diff)
Matrix: fix message edits not being applied correctly
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 133193b..6e6264f 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -999,7 +999,7 @@ namespace QuickMedia {
}
void MatrixInvitesPage::add_body_item(std::shared_ptr<BodyItem> body_item) {
- body->insert_item_by_timestamp_reverse(std::move(body_item));
+ body->insert_item_by_timestamp(std::move(body_item));
if(body->get_num_items() != prev_invite_count) {
prev_invite_count = body->get_num_items();
title = "Invites (" + std::to_string(body->get_num_items()) + ")";
@@ -1604,7 +1604,7 @@ namespace QuickMedia {
PluginResult result;
bool initial_sync = true;
while(sync_running) {
- char url[1024];
+ char url[2048];
if(next_batch.empty())
snprintf(url, sizeof(url), "%s/_matrix/client/r0/sync?filter=%s&timeout=0", homeserver.c_str(), filter_encoded.c_str());
else
@@ -1762,7 +1762,6 @@ namespace QuickMedia {
next_notifications_token.clear();
invites.clear();
filter_cached.reset();
- my_events_transaction_ids.clear();
finished_fetching_notifications = false;
custom_emoji_by_key.clear();
}
@@ -2162,7 +2161,7 @@ namespace QuickMedia {
bool has_unread_notifications = false;
const rapidjson::Value &unread_notification_json = GetMember(it.value, "unread_notifications");
- if(unread_notification_json.IsObject() && !is_additional_messages_sync) {
+ if(unread_notification_json.IsObject() && !is_additional_messages_sync && !sync_is_cache) {
const rapidjson::Value &highlight_count_json = GetMember(unread_notification_json, "highlight_count");
if(highlight_count_json.IsInt64() && (highlight_count_json.GetInt64() > 0 || initial_sync)) {
room->unread_notification_count = highlight_count_json.GetInt64();
@@ -2392,7 +2391,8 @@ namespace QuickMedia {
if(!timestamp_json.IsInt64())
continue;
- room_data->read_marker_event_timestamp = timestamp_json.GetInt64();
+ if(timestamp_json.GetInt64() > room_data->read_marker_event_timestamp)
+ room_data->read_marker_event_timestamp = timestamp_json.GetInt64();
}
}
}
@@ -2878,7 +2878,7 @@ namespace QuickMedia {
const rapidjson::Value &unsigned_json = GetMember(event_item_json, "unsigned");
if(unsigned_json.IsObject()) {
const rapidjson::Value &transaction_id_json = GetMember(unsigned_json, "transaction_id");
- if(transaction_id_json.IsString() && my_events_transaction_ids.find(transaction_id_json.GetString()) != my_events_transaction_ids.end())
+ if(transaction_id_json.IsString())
transaction_id = std::string(transaction_id_json.GetString(), transaction_id_json.GetStringLength());
}
@@ -2915,6 +2915,26 @@ namespace QuickMedia {
}
}
+ /*
+ if(related_event_id.empty() && unsigned_json.IsObject()) {
+ const rapidjson::Value &relations_json = GetMember(unsigned_json, "m.relations");
+ if(relations_json.IsObject()) {
+ const rapidjson::Value &replace_json = GetMember(relations_json, "m.replace");
+ if(replace_json.IsObject()) {
+ const rapidjson::Value &event_id_json = GetMember(replace_json, "event_id");
+ const rapidjson::Value &origin_server_ts = GetMember(replace_json, "origin_server_ts");
+ if(origin_server_ts.IsInt64())
+ timestamp = origin_server_ts.GetInt64();
+
+ if(event_id_json.IsString()) {
+ related_event_id = event_id_json.GetString();
+ related_event_type = RelatedEventType::EDIT;
+ }
+ }
+ }
+ }
+ */
+
const rapidjson::Value &new_content_json = GetMember(*content_json, "m.new_content");
if(new_content_json.IsObject())
content_json = &new_content_json;
@@ -3286,11 +3306,11 @@ namespace QuickMedia {
if(user_info.size() == 0)
result = extract_user_name_from_user_id(fallback_user_id);
else if(user_info.size() == 1)
- result = extract_first_line_remove_newline_elipses(user_info[0]->room->get_user_display_name(user_info[0]), AUTHOR_MAX_LENGTH);
+ result = user_info[0]->room->get_user_display_name(user_info[0]);
else if(user_info.size() == 2)
- result = extract_first_line_remove_newline_elipses(user_info[0]->room->get_user_display_name(user_info[0]) + " and " + user_info[1]->room->get_user_display_name(user_info[1]), 64);
+ result = user_info[0]->room->get_user_display_name(user_info[0]) + " and " + user_info[1]->room->get_user_display_name(user_info[1]);
else if(user_info.size() > 2)
- result = extract_first_line_remove_newline_elipses(user_info[0]->room->get_user_display_name(user_info[0]) + ", " + user_info[1]->room->get_user_display_name(user_info[1]) + " and " + std::to_string(user_info.size() - 2) + " other(s)", 64);
+ result = user_info[0]->room->get_user_display_name(user_info[0]) + ", " + user_info[1]->room->get_user_display_name(user_info[1]) + " and " + std::to_string(user_info.size() - 2) + " other(s)";
return result;
}
@@ -3901,15 +3921,16 @@ namespace QuickMedia {
}
void Matrix::on_exit_room(RoomData *room) {
- my_events_transaction_ids.clear();
+
}
- PluginResult Matrix::post_message(RoomData *room, const std::string &body, std::string &event_id_response, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype) {
- std::string transaction_id = create_transaction_id();
+ PluginResult Matrix::post_message(RoomData *room, const std::string &body, std::string &event_id_response, const std::optional<UploadInfo> &file_info, const std::optional<UploadInfo> &thumbnail_info, const std::string &msgtype, const std::string &custom_transaction_id) {
+ std::string transaction_id = custom_transaction_id;
+ if(transaction_id.empty())
+ transaction_id = create_transaction_id();
+
if(transaction_id.empty())
return PluginResult::ERR;
- if(!file_info)
- my_events_transaction_ids.insert(transaction_id);
std::string formatted_body;
if(!file_info)
@@ -4085,9 +4106,6 @@ namespace QuickMedia {
if(transaction_id.empty())
return PluginResult::ERR;
- if(!file_info)
- my_events_transaction_ids.insert(transaction_id);
-
rapidjson::Document in_reply_to_json(rapidjson::kObjectType);
in_reply_to_json.AddMember("event_id", rapidjson::StringRef(relates_to_message_raw->event_id.c_str()), in_reply_to_json.GetAllocator());
@@ -4191,14 +4209,16 @@ namespace QuickMedia {
return body_to_formatted_body(room, " * " + body);
}
- PluginResult Matrix::post_edit(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response) {
+ PluginResult Matrix::post_edit(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response, const std::string &custom_transaction_id) {
Message *relates_to_message_raw = (Message*)relates_to;
Message *replied_to_message = get_replied_to_message_recursive(this, room, relates_to_message_raw);
- std::string transaction_id = create_transaction_id();
+ std::string transaction_id = custom_transaction_id;
+ if(transaction_id.empty())
+ transaction_id = create_transaction_id();
+
if(transaction_id.empty())
return PluginResult::ERR;
- my_events_transaction_ids.insert(transaction_id);
rapidjson::Document request_data(rapidjson::kObjectType);
@@ -4252,13 +4272,15 @@ namespace QuickMedia {
return PluginResult::OK;
}
- PluginResult Matrix::post_reaction(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response) {
+ PluginResult Matrix::post_reaction(RoomData *room, const std::string &body, void *relates_to, std::string &event_id_response, const std::string &custom_transaction_id) {
Message *relates_to_message_raw = (Message*)relates_to;
- std::string transaction_id = create_transaction_id();
+ std::string transaction_id = custom_transaction_id;
+ if(transaction_id.empty())
+ transaction_id = create_transaction_id();
+
if(transaction_id.empty())
return PluginResult::ERR;
- my_events_transaction_ids.insert(transaction_id);
rapidjson::Document relates_to_json(rapidjson::kObjectType);
relates_to_json.AddMember("event_id", rapidjson::StringRef(relates_to_message_raw->event_id.c_str()), relates_to_json.GetAllocator());
@@ -4887,7 +4909,6 @@ namespace QuickMedia {
std::string transaction_id = create_transaction_id();
if(transaction_id.empty())
return PluginResult::ERR;
- //my_events_transaction_ids.insert(transaction_id);
Message *message_typed = (Message*)message;