aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-26 23:19:35 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-26 23:19:35 +0100
commit60e48e51cff48bc17959267a985e1e2431f77cea (patch)
tree0f6b056f04a31b88660ab78521aae312d9e38a7d /src
parent36db818f77b8a69f6e585ddd1edb4b9cc6376596 (diff)
Better system messages for /id and /help
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp23
-rw-r--r--src/plugins/Matrix.cpp19
2 files changed, 26 insertions, 16 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index f09ed89..069378e 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -4690,7 +4690,7 @@ namespace QuickMedia {
if(message->related_event_type == RelatedEventType::REDACTION || message->related_event_type == RelatedEventType::EDIT || message->related_event_type == RelatedEventType::REACTION)
body_item->visible = false;
if(is_system_message_type(message->type)) {
- body_item->set_author("Server");
+ body_item->set_author("System");
body_item->set_author_color(get_theme().text_color);
body_item->set_description_color(get_theme().faded_text_color);
body_item->thumbnail_url.clear();
@@ -5105,6 +5105,11 @@ namespace QuickMedia {
std::unordered_set<std::string> fetched_messages_set;
auto filter_existing_messages = [&fetched_messages_set](Messages &messages) {
for(auto it = messages.begin(); it != messages.end();) {
+ if((*it)->event_id.empty()) {
+ ++it;
+ continue;
+ }
+
auto res = fetched_messages_set.insert((*it)->event_id);
if(!res.second)
it = messages.erase(it);
@@ -5194,7 +5199,7 @@ namespace QuickMedia {
auto filter_sent_messages = [&sent_messages, &message_set_replaced_by](Messages &messages) {
for(auto it = messages.begin(); it != messages.end();) {
- if(sent_messages.find((*it)->event_id) != sent_messages.end()) {
+ if(!(*it)->event_id.empty() && sent_messages.find((*it)->event_id) != sent_messages.end()) {
message_set_replaced_by(*it);
it = messages.erase(it);
} else {
@@ -5368,12 +5373,7 @@ namespace QuickMedia {
"/react [text]: React to the selected message (also works if you are replying to a message).\n"
"/id: Show the room id.";
message->timestamp = time(nullptr) * 1000;
-
- auto body_item = message_to_body_item(current_room, message.get(), current_room->get_user_avatar_url(me), me->user_id);
- tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps({body_item});
-
- if(scroll_to_end)
- tabs[MESSAGES_TAB_INDEX].body->select_last_item();
+ matrix->append_system_message(current_room, std::move(message));
chat_input.set_editable(false);
chat_state = ChatState::NAVIGATING;
@@ -5384,12 +5384,7 @@ namespace QuickMedia {
message->user = me;
message->body = current_room->id;
message->timestamp = time(nullptr) * 1000;
-
- auto body_item = message_to_body_item(current_room, message.get(), current_room->get_user_avatar_url(me), me->user_id);
- tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps({body_item});
-
- if(scroll_to_end)
- tabs[MESSAGES_TAB_INDEX].body->select_last_item();
+ matrix->append_system_message(current_room, std::move(message));
chat_input.set_editable(false);
chat_state = ChatState::NAVIGATING;
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 2689904..c69a6df 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -187,7 +187,10 @@ namespace QuickMedia {
int64_t last_new_message_timestamp = last_message_timestamp;
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)->event_id.empty()) {
+ messages.insert(messages.begin(), std::move(*it));
+ ++num_new_messages;
+ } else if(message_by_event_id.find((*it)->event_id) == message_by_event_id.end()) {
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));
@@ -204,7 +207,10 @@ namespace QuickMedia {
int64_t last_new_message_timestamp = last_message_timestamp;
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)->event_id.empty()) {
+ messages.push_back(std::move(*it));
+ ++num_new_messages;
+ } else if(message_by_event_id.find((*it)->event_id) == message_by_event_id.end()) {
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));
@@ -2065,6 +2071,15 @@ namespace QuickMedia {
return message->type >= MessageType::TEXT && message->type <= MessageType::FILE;
}
+ void Matrix::append_system_message(RoomData *room_data, std::shared_ptr<Message> message) {
+ Messages new_messages;
+ new_messages.push_back(std::move(message));
+ room_data->append_messages(new_messages);
+ ui_thread_tasks.push([this, room_data, new_messages{std::move(new_messages)}]{
+ delegate->room_add_new_messages(room_data, new_messages, false, false, MessageDirection::AFTER);
+ });
+ }
+
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;