aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 515ef7a..a821158 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -885,7 +885,6 @@ namespace QuickMedia {
auto tag_body_item = BodyItem::create(std::move(tag_name));
tag_body_item->url = tag;
tag_body_items_by_name.insert(std::make_pair(tag, TagData{tag_body_item, {}}));
- // TODO: Sort by tag priority
body->append_item(tag_body_item);
tag_data = &tag_body_items_by_name[tag];
tag_data->tag_item = tag_body_item;
@@ -4051,7 +4050,7 @@ namespace QuickMedia {
"</mx-reply>" + std::move(formatted_body);
}
- static Message* get_latest_message_in_edit_chain(Message *message) {
+ Message* get_latest_message_in_edit_chain(Message *message) {
while(message) {
Message *replaced_by = message->replaced_by.get();
if(!replaced_by)
@@ -4152,40 +4151,61 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ static Message* get_replied_to_message_recursive(Matrix *matrix, RoomData *room, Message *message) {
+ while(message) {
+ if(message->related_event_type == RelatedEventType::REPLY && !message->related_event_id.empty())
+ return get_latest_message_in_edit_chain(matrix->get_message_by_id(room, message->related_event_id).get());
+ else if(message->related_event_type == RelatedEventType::EDIT && !message->related_event_id.empty())
+ message = matrix->get_message_by_id(room, message->related_event_id).get();
+ else
+ return nullptr;
+ }
+ return nullptr;
+ }
+
+ static std::string create_body_for_message_edit(Matrix *matrix, const Message *replied_to_message, const std::string &body) {
+ if(replied_to_message)
+ return create_body_for_message_reply(matrix, replied_to_message, " * " + body);
+ else
+ return " * " + body;
+ }
+
+ std::string Matrix::create_formatted_body_for_message_edit(RoomData *room, const Message *replied_to_message, const std::string &body) {
+ if(replied_to_message)
+ return create_formatted_body_for_message_reply(room, replied_to_message, " * " + body);
+ else
+ 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) {
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();
if(transaction_id.empty())
return PluginResult::ERR;
my_events_transaction_ids.insert(transaction_id);
- std::string formatted_body = body_to_formatted_body(room, body);
+ rapidjson::Document request_data(rapidjson::kObjectType);
+ const std::string message_edit_body = create_body_for_message_edit(this, replied_to_message, body);
+ const std::string formatted_message_edit_body = create_formatted_body_for_message_edit(room, replied_to_message, body);
+ request_data.AddMember("msgtype", "m.text", request_data.GetAllocator());
+ request_data.AddMember("body", rapidjson::StringRef(message_edit_body.c_str()), request_data.GetAllocator());
+ request_data.AddMember("format", "org.matrix.custom.html", request_data.GetAllocator());
+ request_data.AddMember("formatted_body", rapidjson::StringRef(formatted_message_edit_body.c_str()), request_data.GetAllocator());
+
+ const std::string formatted_body = body_to_formatted_body(room, body);
rapidjson::Document new_content_json(rapidjson::kObjectType);
new_content_json.AddMember("msgtype", "m.text", new_content_json.GetAllocator());
new_content_json.AddMember("body", rapidjson::StringRef(body.c_str()), new_content_json.GetAllocator());
- if(!formatted_body.empty()) {
- new_content_json.AddMember("format", "org.matrix.custom.html", new_content_json.GetAllocator());
- new_content_json.AddMember("formatted_body", rapidjson::StringRef(formatted_body.c_str()), new_content_json.GetAllocator());
- }
+ new_content_json.AddMember("format", "org.matrix.custom.html", new_content_json.GetAllocator());
+ new_content_json.AddMember("formatted_body", rapidjson::StringRef(formatted_body.c_str()), new_content_json.GetAllocator());
+ request_data.AddMember("m.new_content", std::move(new_content_json), request_data.GetAllocator());
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());
relates_to_json.AddMember("rel_type", "m.replace", relates_to_json.GetAllocator());
-
- std::string body_edit_str = " * " + body;
- std::string formatted_body_edit_str;
-
- rapidjson::Document request_data(rapidjson::kObjectType);
- request_data.AddMember("msgtype", "m.text", request_data.GetAllocator());
- request_data.AddMember("body", rapidjson::StringRef(body_edit_str.c_str()), request_data.GetAllocator());
- if(!formatted_body.empty()) {
- formatted_body_edit_str = " * " + formatted_body;
- request_data.AddMember("format", "org.matrix.custom.html", request_data.GetAllocator());
- request_data.AddMember("formatted_body", rapidjson::StringRef(formatted_body_edit_str.c_str()), request_data.GetAllocator());
- }
- request_data.AddMember("m.new_content", std::move(new_content_json), request_data.GetAllocator());
request_data.AddMember("m.relates_to", std::move(relates_to_json), request_data.GetAllocator());
rapidjson::StringBuffer buffer;