diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-26 22:41:37 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-26 22:41:37 +0100 |
commit | 36db818f77b8a69f6e585ddd1edb4b9cc6376596 (patch) | |
tree | d4bd0fb3583b074917670bdb861c35db8c47c82b /src | |
parent | a3a24393b77a9ac354cf9ce9572a3605a11a66b2 (diff) |
Matrix: add /id and /help commands
Diffstat (limited to 'src')
-rw-r--r-- | src/QuickMedia.cpp | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index a3952e7..f09ed89 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -5283,7 +5283,7 @@ namespace QuickMedia { bool frame_skip_text_entry = false; - chat_input.on_submit_callback = [this, &frame_skip_text_entry, &mention, &tabs, &me, &chat_input, &ui_tabs, MESSAGES_TAB_INDEX, USERS_TAB_INDEX, ¤t_room, &new_page, &chat_state, &pending_sent_replies, ¤tly_operating_on_item, &post_task_queue, &process_reactions](std::string text) mutable { + chat_input.on_submit_callback = [&](std::string text) mutable { if(mention.visible) { BodyItem *selected_mention_item = tabs[USERS_TAB_INDEX].body->get_selected(); if(selected_mention_item) { @@ -5299,6 +5299,11 @@ namespace QuickMedia { frame_skip_text_entry = true; const int selected_tab = ui_tabs.get_selected(); + + int num_items = tabs[MESSAGES_TAB_INDEX].body->get_num_items(); + bool scroll_to_end = num_items == 0; + if(tabs[MESSAGES_TAB_INDEX].body->is_selected_item_last_visible_item() && selected_tab == MESSAGES_TAB_INDEX) + scroll_to_end = true; if(selected_tab == MESSAGES_TAB_INDEX) { if(text.empty()) @@ -5349,6 +5354,46 @@ namespace QuickMedia { chat_state = ChatState::NAVIGATING; } return true; + } else if(text == "/help") { + auto message = std::make_shared<Message>(); + message->type = MessageType::SYSTEM; + message->user = me; + message->body = + "/upload: Bring up the file manager and select a file to upload to the room, `Esc` to cancel.\n" + "/join [room]: Join a room by name or id.\n" + "/invite: Invite a user to the room.\n" + "/logout: Logout.\n" + "/leave: Leave the current room.\n" + "/me [text]: Send a message of type \"m.emote\".\n" + "/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(); + + chat_input.set_editable(false); + chat_state = ChatState::NAVIGATING; + return true; + } else if(text == "/id") { + auto message = std::make_shared<Message>(); + message->type = MessageType::SYSTEM; + 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(); + + chat_input.set_editable(false); + chat_state = ChatState::NAVIGATING; + return true; } else if(strncmp(text.c_str(), "/me ", 4) == 0) { msgtype = "m.emote"; text.erase(text.begin(), text.begin() + 4); @@ -5356,7 +5401,7 @@ namespace QuickMedia { msgtype = "m.reaction"; text.erase(text.begin(), text.begin() + 7); } else { - show_notification("QuickMedia", "Error: invalid command: " + text + ", expected /upload, /join [room], /invite, /logout, /leave, /me [text] or /react [text]", Urgency::NORMAL); + show_notification("QuickMedia", "Error: invalid command: " + text + ", type /help to see a list of valid commands.", Urgency::NORMAL); return false; } } else if(chat_state == ChatState::REPLYING && text[0] == '/') { @@ -5375,11 +5420,6 @@ namespace QuickMedia { message->type = MessageType::TEXT; message->timestamp = time(NULL) * 1000; - int num_items = tabs[MESSAGES_TAB_INDEX].body->get_num_items(); - bool scroll_to_end = num_items == 0; - if(tabs[MESSAGES_TAB_INDEX].body->is_selected_item_last_visible_item() && selected_tab == MESSAGES_TAB_INDEX) - scroll_to_end = true; - if(chat_state == ChatState::TYPING_MESSAGE || (chat_state == ChatState::REPLYING && msgtype == "m.reaction")) { BodyItem *selected_item = tabs[MESSAGES_TAB_INDEX].body->get_selected(); if(chat_state == ChatState::REPLYING) |