mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-04 11:03:14 +02:00
Add local message feature to context menu with settings option
Co-authored-by: g6582566 <g6582566@morris.umn.edu>
This commit is contained in:
parent
31cb5f620b
commit
683aef44f9
7 changed files with 133 additions and 0 deletions
|
@ -6905,3 +6905,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"ayu_AboutText1" = "ToS breaking Telegram client based on {api_link}.";
|
||||
"ayu_UpdateAyuGram" = "Update AyuGram";
|
||||
"ayu_UtilityRestartRequired" = "The app will close in 5 seconds.";
|
||||
"ayu_AddLocalMessage" = "Add Local Message";
|
||||
"ayu_AddLocalMessageTitle" = "Add Local Message";
|
||||
"ayu_AddLocalMessagePlaceholder" = "Message text...";
|
||||
"ayu_AddLocalMessageFromPlaceholder" = "From user (optional)...";
|
||||
|
|
|
@ -255,6 +255,7 @@ AyuGramSettings::AyuGramSettings() {
|
|||
showHideMessageInContextMenu = 0;
|
||||
showUserMessagesInContextMenu = 2;
|
||||
showMessageDetailsInContextMenu = 2;
|
||||
showAddLocalMessageInContextMenu = 2;
|
||||
|
||||
showAttachButtonInMessageField = true;
|
||||
showCommandsButtonInMessageField = true;
|
||||
|
@ -463,6 +464,10 @@ void set_showMessageDetailsInContextMenu(int val) {
|
|||
settings->showMessageDetailsInContextMenu = val;
|
||||
}
|
||||
|
||||
void set_showAddLocalMessageInContextMenu(int val) {
|
||||
settings->showAddLocalMessageInContextMenu = val;
|
||||
}
|
||||
|
||||
void set_showAttachButtonInMessageField(bool val) {
|
||||
settings->showAttachButtonInMessageField = val;
|
||||
triggerHistoryUpdate();
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
int showHideMessageInContextMenu;
|
||||
int showUserMessagesInContextMenu;
|
||||
int showMessageDetailsInContextMenu;
|
||||
int showAddLocalMessageInContextMenu;
|
||||
|
||||
bool showAttachButtonInMessageField;
|
||||
bool showCommandsButtonInMessageField;
|
||||
|
@ -144,6 +145,7 @@ void set_showViewsPanelInContextMenu(int val);
|
|||
void set_showHideMessageInContextMenu(int val);
|
||||
void set_showUserMessagesInContextMenu(int val);
|
||||
void set_showMessageDetailsInContextMenu(int val);
|
||||
void set_showAddLocalMessageInContextMenu(int val);
|
||||
|
||||
void set_showAttachButtonInMessageField(bool val);
|
||||
void set_showCommandsButtonInMessageField(bool val);
|
||||
|
@ -215,6 +217,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
|
|||
showHideMessageInContextMenu,
|
||||
showUserMessagesInContextMenu,
|
||||
showMessageDetailsInContextMenu,
|
||||
showAddLocalMessageInContextMenu,
|
||||
showAttachButtonInMessageField,
|
||||
showCommandsButtonInMessageField,
|
||||
showEmojiButtonInMessageField,
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "styles/style_menu_icons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||
#include "ui/widgets/fields/input_field.h"
|
||||
#include "ui/boxes/generic_box.h"
|
||||
#include "window/window_peer_menu.h"
|
||||
|
||||
#include "ayu/ui/message_history/history_section.h"
|
||||
|
@ -34,8 +36,10 @@
|
|||
#include "data/data_session.h"
|
||||
#include "history/view/history_view_context_menu.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/history.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "base/unixtime.h"
|
||||
|
||||
namespace AyuUi {
|
||||
|
||||
|
@ -542,4 +546,106 @@ void AddBurnAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
|||
&st::menuIconTTLAny);
|
||||
}
|
||||
|
||||
void AddLocalMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& settings = AyuSettings::getInstance();
|
||||
if (!needToShowItem(settings.showAddLocalMessageInContextMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto history = item->history();
|
||||
const auto controller = history->session().tryResolveWindow();
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu->addAction(
|
||||
tr::ayu_AddLocalMessage(tr::now),
|
||||
[=]() {
|
||||
const auto showBox = [=](const QString &text, PeerId fromId) {
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Создаем локальное сообщение
|
||||
const auto localId = history->session().data().nextLocalMessageId();
|
||||
const auto localItem = history->addNewLocalMessage({
|
||||
.id = localId,
|
||||
.flags = MessageFlag::HasFromId,
|
||||
.from = fromId,
|
||||
.date = base::unixtime::now(),
|
||||
}, TextWithEntities{ text }, MTP_messageMediaEmpty());
|
||||
|
||||
// Добавляем в базу данных локальных сообщений
|
||||
AyuMessages::addLocalMessage(localItem);
|
||||
};
|
||||
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
box->setTitle(tr::ayu_AddLocalMessageTitle());
|
||||
|
||||
// Поле для ввода текста сообщения
|
||||
const auto textField = box->addRow(object_ptr<Ui::InputField>(
|
||||
box,
|
||||
st::defaultInputField,
|
||||
tr::ayu_AddLocalMessagePlaceholder(),
|
||||
QString()));
|
||||
textField->setMaxLength(4096);
|
||||
|
||||
// Поле для выбора отправителя
|
||||
const auto fromField = box->addRow(object_ptr<Ui::InputField>(
|
||||
box,
|
||||
st::defaultInputField,
|
||||
tr::ayu_AddLocalMessageFromPlaceholder(),
|
||||
QString()));
|
||||
|
||||
box->setFocusCallback([=] {
|
||||
textField->setFocusFast();
|
||||
});
|
||||
|
||||
box->addButton(tr::lng_box_ok(), [=] {
|
||||
const auto text = textField->getLastText().trimmed();
|
||||
const auto fromText = fromField->getLastText().trimmed();
|
||||
|
||||
PeerId fromId = history->peer->id;
|
||||
if (!fromText.isEmpty()) {
|
||||
// Пытаемся найти пользователя по имени или username
|
||||
const auto session = &history->session();
|
||||
const auto &owner = session->data();
|
||||
|
||||
// Сначала пытаемся найти по username
|
||||
if (const auto user = owner.userByUsername(fromText)) {
|
||||
fromId = user->id;
|
||||
} else {
|
||||
// Затем ищем по имени среди участников чата
|
||||
if (const auto chat = history->peer->asChat()) {
|
||||
for (const auto &participant : chat->participants) {
|
||||
if (const auto user = owner.user(participant.userId())) {
|
||||
if (user->name().toLower().contains(fromText.toLower())) {
|
||||
fromId = user->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const auto channel = history->peer->asChannel()) {
|
||||
// Для каналов используем текущего пользователя, если не найден
|
||||
// В реальном приложении можно было бы реализовать поиск по участникам
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showBox(text, fromId);
|
||||
box->closeBox();
|
||||
});
|
||||
|
||||
box->addButton(tr::lng_cancel(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
}));
|
||||
},
|
||||
&st::menuIconEdit);
|
||||
}
|
||||
|
||||
} // namespace AyuUi
|
||||
|
|
|
@ -35,5 +35,6 @@ void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
|||
void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||
void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||
void AddBurnAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||
void AddLocalMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||
|
||||
}
|
||||
|
|
|
@ -933,6 +933,19 @@ void SetupContextMenuElements(not_null<Ui::VerticalLayout*> container,
|
|||
AyuSettings::set_showMessageDetailsInContextMenu(index);
|
||||
AyuSettings::save();
|
||||
});
|
||||
AddChooseButtonWithIconAndRightText(
|
||||
container,
|
||||
controller,
|
||||
settings.showAddLocalMessageInContextMenu,
|
||||
options,
|
||||
tr::ayu_AddLocalMessage(),
|
||||
tr::ayu_SettingsContextMenuTitle(),
|
||||
st::menuIconEdit,
|
||||
[=](int index)
|
||||
{
|
||||
AyuSettings::set_showAddLocalMessageInContextMenu(index);
|
||||
AyuSettings::save();
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
AddDividerText(container, tr::ayu_SettingsContextMenuDescription());
|
||||
|
|
|
@ -1031,6 +1031,7 @@ void AddMessageActions(
|
|||
AyuUi::AddHideMessageAction(menu, request.item);
|
||||
AyuUi::AddUserMessagesAction(menu, request.item);
|
||||
AyuUi::AddMessageDetailsAction(menu, request.item);
|
||||
AyuUi::AddLocalMessageAction(menu, request.item);
|
||||
}
|
||||
|
||||
AddPostLinkAction(menu, request);
|
||||
|
|
Loading…
Add table
Reference in a new issue