aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp54
1 files changed, 38 insertions, 16 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index d9b1041..0f4c695 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3433,7 +3433,7 @@ namespace QuickMedia {
auto filter_my_messages = [&me](Messages &messages) {
for(auto it = messages.begin(); it != messages.end();) {
- if((*it)->user == me && (*it)->type == MessageType::TEXT)
+ if((*it)->user == me && ((*it)->type == MessageType::TEXT || (*it)->type == MessageType::REACTION))
it = messages.erase(it);
else
++it;
@@ -3467,7 +3467,7 @@ namespace QuickMedia {
}
};
- chat_input.on_submit_callback = [this, &tabs, &me, &chat_input, &selected_tab, &current_room, &new_page, &chat_state, &currently_operating_on_item, &post_task_queue, &unreferenced_events, &find_body_item_by_event_id](std::string text) mutable {
+ chat_input.on_submit_callback = [this, &tabs, &me, &chat_input, &selected_tab, &current_room, &new_page, &chat_state, &currently_operating_on_item, &post_task_queue, &process_reactions, &find_body_item_by_event_id](std::string text) mutable {
if(!current_room)
return false;
@@ -3500,8 +3500,11 @@ namespace QuickMedia {
} else if(strncmp(text.c_str(), "/me ", 4) == 0) {
msgtype = "m.emote";
text.erase(text.begin(), text.begin() + 4);
+ } else if(strncmp(text.c_str(), "/react ", 7) == 0) {
+ msgtype = "m.reaction";
+ text.erase(text.begin(), text.begin() + 7);
} else {
- fprintf(stderr, "Error: invalid command: %s, expected /upload, /logout or /me\n", text.c_str());
+ fprintf(stderr, "Error: invalid command: %s, expected /upload, /logout, /me or /react\n", text.c_str());
return false;
}
}
@@ -3523,17 +3526,38 @@ namespace QuickMedia {
scroll_to_end = true;
if(chat_state == ChatState::TYPING_MESSAGE) {
- auto body_item = message_to_body_item(current_room, message.get(), current_room->get_user_avatar_url(me), me->user_id);
- body_item->set_description_color(provisional_message_color);
- tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps({body_item});
- post_task_queue.push([this, &current_room, text, msgtype, body_item, message]() {
- ProvisionalMessage provisional_message;
- provisional_message.body_item = body_item;
- provisional_message.message = message;
- if(matrix->post_message(current_room, text, provisional_message.event_id, std::nullopt, std::nullopt, msgtype) != PluginResult::OK)
- fprintf(stderr, "Failed to post matrix message\n");
- return provisional_message;
- });
+ BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected();
+ if(msgtype == "m.reaction" && selected_item) {
+ void *related_to_message = selected_item->userdata;
+ message->type = MessageType::REACTION;
+ message->related_event_type = RelatedEventType::REACTION;
+ message->related_event_id = static_cast<Message*>(related_to_message)->event_id;
+ 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});
+ Messages messages;
+ messages.push_back(message);
+ process_reactions(messages);
+ post_task_queue.push([this, &current_room, text, body_item, message, related_to_message]() {
+ ProvisionalMessage provisional_message;
+ provisional_message.body_item = body_item;
+ provisional_message.message = message;
+ if(matrix->post_reaction(current_room, text, related_to_message, provisional_message.event_id) != PluginResult::OK)
+ fprintf(stderr, "Failed to post matrix reaction\n");
+ return provisional_message;
+ });
+ } else {
+ auto body_item = message_to_body_item(current_room, message.get(), current_room->get_user_avatar_url(me), me->user_id);
+ body_item->set_description_color(provisional_message_color);
+ tabs[MESSAGES_TAB_INDEX].body->insert_items_by_timestamps({body_item});
+ post_task_queue.push([this, &current_room, text, msgtype, body_item, message]() {
+ ProvisionalMessage provisional_message;
+ provisional_message.body_item = body_item;
+ provisional_message.message = message;
+ if(matrix->post_message(current_room, text, provisional_message.event_id, std::nullopt, std::nullopt, msgtype) != PluginResult::OK)
+ fprintf(stderr, "Failed to post matrix message\n");
+ return provisional_message;
+ });
+ }
chat_input.set_editable(false);
chat_state = ChatState::NAVIGATING;
if(scroll_to_end)
@@ -4107,8 +4131,6 @@ namespace QuickMedia {
if((selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) && event.key.code == sf::Keyboard::Enter) {
BodyItem *selected = tabs[selected_tab].body->get_selected();
if(selected) {
- Message *mess = static_cast<Message*>(selected->userdata);
- fprintf(stderr, "Mess type: %d\n", mess->type);
if(!display_url_or_image(selected))
display_url_or_image(selected->embedded_item.get());
}