From 36db818f77b8a69f6e585ddd1edb4b9cc6376596 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 26 Nov 2021 22:41:37 +0100 Subject: Matrix: add /id and /help commands --- README.md | 4 +++- src/QuickMedia.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index db33755..6fd692d 100644 --- a/README.md +++ b/README.md @@ -144,13 +144,15 @@ Type text and then wait and QuickMedia will automatically search.\ `Ctrl+Enter`/`Click on save`: Save the file.\ `Esc`/`Click on cancel`: Cancel download. ## Matrix text commands +`/help`: Show a list of valid commands.\ `/upload`: Bring up the file manager and select a file to upload to the room, `Esc` to cancel.\ `/join [room]`: Join a room by name or id.\ `/invite`: Invite a user to the room.\ `/logout`: Logout.\ `/leave`: Leave the current room.\ `/me [text]`: Send a message of type "m.emote".\ -`/react [text]`: React to the selected message (also works if you are replying to a message). +`/react [text]`: React to the selected message (also works if you are replying to a message).\ +`/id`: Show the room id. ## Config Config is loaded from `~/.config/quickmedia/config.json` if it exists. See [example-config.json](https://git.dec05eba.com/QuickMedia/plain/example-config.json) for an example config. All fields in the config file are optional.\ If `use_system_mpv_config` is set to `true` then your systems mpv config in `~/.config/mpv/mpv.conf` and plugins will be used. If you have a mpv plugin installed that uses `input-ipc-server` (such as `mpv-discord`) then it will break quickmedia integration with mpv (especially key inputs such as ctrl+r). 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->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->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) -- cgit v1.2.3