mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-01 17:43:03 +02:00
feat: repeater
This commit is contained in:
parent
f56b5ea03e
commit
1bf376ca20
8 changed files with 156 additions and 0 deletions
|
@ -7151,3 +7151,4 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"ayu_AboutText1" = "ToS breaking Telegram client based on {api_link}.";
|
"ayu_AboutText1" = "ToS breaking Telegram client based on {api_link}.";
|
||||||
"ayu_UpdateAyuGram" = "Update AyuGram";
|
"ayu_UpdateAyuGram" = "Update AyuGram";
|
||||||
"ayu_UtilityRestartRequired" = "The app will close in 5 seconds.";
|
"ayu_UtilityRestartRequired" = "The app will close in 5 seconds.";
|
||||||
|
"ayu_Repeater" = "+1 / Repeater";
|
||||||
|
|
|
@ -257,6 +257,7 @@ AyuGramSettings::AyuGramSettings() {
|
||||||
showHideMessageInContextMenu = 0;
|
showHideMessageInContextMenu = 0;
|
||||||
showUserMessagesInContextMenu = 2;
|
showUserMessagesInContextMenu = 2;
|
||||||
showMessageDetailsInContextMenu = 2;
|
showMessageDetailsInContextMenu = 2;
|
||||||
|
showRepeaterInContextMenu = 2;
|
||||||
|
|
||||||
showAttachButtonInMessageField = true;
|
showAttachButtonInMessageField = true;
|
||||||
showCommandsButtonInMessageField = true;
|
showCommandsButtonInMessageField = true;
|
||||||
|
@ -473,6 +474,10 @@ void set_showMessageDetailsInContextMenu(int val) {
|
||||||
settings->showMessageDetailsInContextMenu = val;
|
settings->showMessageDetailsInContextMenu = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_showRepeaterInContextMenu(int val) {
|
||||||
|
settings->showRepeaterInContextMenu = val;
|
||||||
|
}
|
||||||
|
|
||||||
void set_showAttachButtonInMessageField(bool val) {
|
void set_showAttachButtonInMessageField(bool val) {
|
||||||
settings->showAttachButtonInMessageField = val;
|
settings->showAttachButtonInMessageField = val;
|
||||||
triggerHistoryUpdate();
|
triggerHistoryUpdate();
|
||||||
|
|
|
@ -91,6 +91,7 @@ public:
|
||||||
int showHideMessageInContextMenu;
|
int showHideMessageInContextMenu;
|
||||||
int showUserMessagesInContextMenu;
|
int showUserMessagesInContextMenu;
|
||||||
int showMessageDetailsInContextMenu;
|
int showMessageDetailsInContextMenu;
|
||||||
|
int showRepeaterInContextMenu;
|
||||||
|
|
||||||
bool showAttachButtonInMessageField;
|
bool showAttachButtonInMessageField;
|
||||||
bool showCommandsButtonInMessageField;
|
bool showCommandsButtonInMessageField;
|
||||||
|
@ -175,6 +176,7 @@ void set_showViewsPanelInContextMenu(int val);
|
||||||
void set_showHideMessageInContextMenu(int val);
|
void set_showHideMessageInContextMenu(int val);
|
||||||
void set_showUserMessagesInContextMenu(int val);
|
void set_showUserMessagesInContextMenu(int val);
|
||||||
void set_showMessageDetailsInContextMenu(int val);
|
void set_showMessageDetailsInContextMenu(int val);
|
||||||
|
void set_showRepeaterInContextMenu(int val);
|
||||||
|
|
||||||
void set_showAttachButtonInMessageField(bool val);
|
void set_showAttachButtonInMessageField(bool val);
|
||||||
void set_showCommandsButtonInMessageField(bool val);
|
void set_showCommandsButtonInMessageField(bool val);
|
||||||
|
@ -245,6 +247,7 @@ inline void to_json(nlohmann::json &nlohmann_json_j, const AyuGramSettings &nloh
|
||||||
NLOHMANN_JSON_TO(showHideMessageInContextMenu)
|
NLOHMANN_JSON_TO(showHideMessageInContextMenu)
|
||||||
NLOHMANN_JSON_TO(showUserMessagesInContextMenu)
|
NLOHMANN_JSON_TO(showUserMessagesInContextMenu)
|
||||||
NLOHMANN_JSON_TO(showMessageDetailsInContextMenu)
|
NLOHMANN_JSON_TO(showMessageDetailsInContextMenu)
|
||||||
|
NLOHMANN_JSON_TO(showRepeaterInContextMenu)
|
||||||
NLOHMANN_JSON_TO(showAttachButtonInMessageField)
|
NLOHMANN_JSON_TO(showAttachButtonInMessageField)
|
||||||
NLOHMANN_JSON_TO(showCommandsButtonInMessageField)
|
NLOHMANN_JSON_TO(showCommandsButtonInMessageField)
|
||||||
NLOHMANN_JSON_TO(showEmojiButtonInMessageField)
|
NLOHMANN_JSON_TO(showEmojiButtonInMessageField)
|
||||||
|
@ -310,6 +313,7 @@ inline void from_json(const nlohmann::json &nlohmann_json_j, AyuGramSettings &nl
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showHideMessageInContextMenu)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showHideMessageInContextMenu)
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showUserMessagesInContextMenu)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showUserMessagesInContextMenu)
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showMessageDetailsInContextMenu)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showMessageDetailsInContextMenu)
|
||||||
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showRepeaterInContextMenu)
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showAttachButtonInMessageField)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showAttachButtonInMessageField)
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showCommandsButtonInMessageField)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showCommandsButtonInMessageField)
|
||||||
NLOHMANN_JSON_FROM_WITH_DEFAULT(showEmojiButtonInMessageField)
|
NLOHMANN_JSON_FROM_WITH_DEFAULT(showEmojiButtonInMessageField)
|
||||||
|
|
|
@ -42,6 +42,10 @@
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
|
||||||
|
#include "main/session/send_as_peers.h"
|
||||||
|
#include "api/api_sending.h"
|
||||||
|
#include "history/history_widget.h"
|
||||||
|
|
||||||
namespace AyuUi {
|
namespace AyuUi {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -631,6 +635,132 @@ void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Api::SendAction prepareSendAction(auto _history, Api::SendOptions options) {
|
||||||
|
auto result = Api::SendAction(_history, options);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddRepeaterAction(not_null<Ui::PopupMenu *> menu, HistoryItem *item) {
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
if (!needToShowItem(settings->showRepeaterInContextMenu)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto itemId = item->fullId();
|
||||||
|
const auto _history = item->history();
|
||||||
|
if ((item->history()->peer->isMegagroup() || item->history()->peer->isChat() || item->history()->peer->isUser())) {
|
||||||
|
if (item->allowsForward()) {
|
||||||
|
menu->addAction(
|
||||||
|
tr::ayu_Repeater(tr::now),
|
||||||
|
[=] {
|
||||||
|
if (item->id <= 0) return;
|
||||||
|
const auto api = &item->history()->peer->session().api();
|
||||||
|
auto action = Api::SendAction(
|
||||||
|
item->history()->peer->owner().history(item->history()->peer),
|
||||||
|
Api::SendOptions{.sendAs = _history->session().sendAsPeers().resolveChosen(_history->peer)});
|
||||||
|
action.clearDraft = false;
|
||||||
|
if (item->history()->peer->isUser() || item->history()->peer->isChat()) {
|
||||||
|
action.options.sendAs = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item->topic()) {
|
||||||
|
action.replyTo = FullReplyTo{
|
||||||
|
.messageId = item->fullId(),
|
||||||
|
.topicRootId = item->topicRootId(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto history = item->history()->peer->owner().history(item->history()->peer);
|
||||||
|
auto resolved = history->resolveForwardDraft(Data::ForwardDraft{.ids = MessageIdsList(1, itemId)});
|
||||||
|
|
||||||
|
api->forwardMessages(
|
||||||
|
std::move(resolved), action, [] {});
|
||||||
|
},
|
||||||
|
&st::menuIconDiscussion);
|
||||||
|
} else if (!item->isService() && !item->emptyText() && item->media() == nullptr) {
|
||||||
|
menu->addAction(
|
||||||
|
tr::ayu_Repeater(tr::now),
|
||||||
|
[=] {
|
||||||
|
if (item->id <= 0) return;
|
||||||
|
const auto api = &item->history()->peer->session().api();
|
||||||
|
auto message = ApiWrap::MessageToSend(prepareSendAction(
|
||||||
|
_history->peer->owner().history(item->history()->peer),
|
||||||
|
Api::SendOptions{.sendAs = _history->session().sendAsPeers().resolveChosen(_history->peer)}));
|
||||||
|
message.textWithTags = {item->originalText().text,
|
||||||
|
TextUtilities::ConvertEntitiesToTextTags(item->originalText().entities)};
|
||||||
|
if (item->history()->peer->isUser() || item->history()->peer->isChat()) {
|
||||||
|
message.action.options.sendAs = nullptr;
|
||||||
|
}
|
||||||
|
if (item->topic()) {
|
||||||
|
message.action.replyTo = FullReplyTo{
|
||||||
|
.messageId = item->fullId(),
|
||||||
|
.topicRootId = item->topicRootId(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
api->sendMessage(std::move(message));
|
||||||
|
},
|
||||||
|
&st::menuIconDiscussion);
|
||||||
|
} else if (!item->isService() && item->media()->document() != nullptr &&
|
||||||
|
item->media()->document()->sticker() != nullptr) {
|
||||||
|
if (item->allowsForward()) {
|
||||||
|
menu->addAction(
|
||||||
|
tr::ayu_Repeater(tr::now),
|
||||||
|
[=] {
|
||||||
|
if (item->id <= 0) return;
|
||||||
|
const auto api = &item->history()->peer->session().api();
|
||||||
|
auto action = Api::SendAction(
|
||||||
|
item->history()->peer->owner().history(item->history()->peer),
|
||||||
|
Api::SendOptions{.sendAs = _history->session().sendAsPeers().resolveChosen(_history->peer)});
|
||||||
|
action.clearDraft = false;
|
||||||
|
if (item->history()->peer->isUser() || item->history()->peer->isChat()) {
|
||||||
|
action.options.sendAs = nullptr;
|
||||||
|
}
|
||||||
|
if (item->topic()) {
|
||||||
|
action.replyTo = FullReplyTo{
|
||||||
|
.messageId = item->fullId(),
|
||||||
|
.topicRootId = item->topicRootId(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto history = item->history()->peer->owner().history(item->history()->peer);
|
||||||
|
auto resolved = history->resolveForwardDraft(Data::ForwardDraft{
|
||||||
|
.ids = MessageIdsList(1, itemId), .options = Data::ForwardOptions::NoSenderNames});
|
||||||
|
|
||||||
|
api->forwardMessages(
|
||||||
|
std::move(resolved), action, [] {});
|
||||||
|
},
|
||||||
|
&st::menuIconDiscussion);
|
||||||
|
} else {
|
||||||
|
menu->addAction(
|
||||||
|
tr::ayu_Repeater(tr::now),
|
||||||
|
[=] {
|
||||||
|
if (item->id <= 0) return;
|
||||||
|
const auto document = item->media()->document();
|
||||||
|
const auto history = item->history()->peer->owner().history(item->history()->peer);
|
||||||
|
auto message = ApiWrap::MessageToSend(prepareSendAction(
|
||||||
|
history,
|
||||||
|
Api::SendOptions{.sendAs = _history->session().sendAsPeers().resolveChosen(_history->peer)}));
|
||||||
|
if (item->history()->peer->isUser() || item->history()->peer->isChat()) {
|
||||||
|
message.action.options.sendAs = nullptr;
|
||||||
|
}
|
||||||
|
if (item->topic()) {
|
||||||
|
message.action.replyTo = FullReplyTo{
|
||||||
|
.messageId = item->fullId(),
|
||||||
|
.topicRootId = item->topicRootId(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Api::SendExistingDocument(std::move(message), document);
|
||||||
|
},
|
||||||
|
&st::menuIconDiscussion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
void AddReadUntilAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item) {
|
||||||
if (item->isLocal() || item->isService() || item->out() || item->isDeleted()) {
|
if (item->isLocal() || item->isService() || item->out() || item->isDeleted()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -37,6 +37,7 @@ void AddHistoryAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddHideMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddHideMessageAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddUserMessagesAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
void AddMessageDetailsAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
|
void AddRepeaterAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
void AddReadUntilAction(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 AddBurnAction(not_null<Ui::PopupMenu*> menu, HistoryItem *item);
|
||||||
|
|
||||||
|
|
|
@ -974,6 +974,19 @@ void SetupContextMenuElements(not_null<Ui::VerticalLayout*> container,
|
||||||
AyuSettings::set_showMessageDetailsInContextMenu(index);
|
AyuSettings::set_showMessageDetailsInContextMenu(index);
|
||||||
AyuSettings::save();
|
AyuSettings::save();
|
||||||
});
|
});
|
||||||
|
AddChooseButtonWithIconAndRightText(
|
||||||
|
container,
|
||||||
|
controller,
|
||||||
|
settings->showRepeaterInContextMenu,
|
||||||
|
options,
|
||||||
|
tr::ayu_Repeater(),
|
||||||
|
tr::ayu_SettingsContextMenuTitle(),
|
||||||
|
st::menuIconDiscussion,
|
||||||
|
[=](int index)
|
||||||
|
{
|
||||||
|
AyuSettings::set_showRepeaterInContextMenu(index);
|
||||||
|
AyuSettings::save();
|
||||||
|
});
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
AddDividerText(container, tr::ayu_SettingsContextMenuDescription());
|
AddDividerText(container, tr::ayu_SettingsContextMenuDescription());
|
||||||
|
|
|
@ -2549,6 +2549,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
AyuUi::AddHideMessageAction(_menu, item);
|
AyuUi::AddHideMessageAction(_menu, item);
|
||||||
AyuUi::AddUserMessagesAction(_menu, item);
|
AyuUi::AddUserMessagesAction(_menu, item);
|
||||||
AyuUi::AddMessageDetailsAction(_menu, item);
|
AyuUi::AddMessageDetailsAction(_menu, item);
|
||||||
|
AyuUi::AddRepeaterAction(_menu, item);
|
||||||
};
|
};
|
||||||
const auto addPhotoActions = [&](not_null<PhotoData*> photo, HistoryItem *item) {
|
const auto addPhotoActions = [&](not_null<PhotoData*> photo, HistoryItem *item) {
|
||||||
const auto media = photo->activeMediaView();
|
const auto media = photo->activeMediaView();
|
||||||
|
|
|
@ -1058,6 +1058,7 @@ void AddMessageActions(
|
||||||
AyuUi::AddHideMessageAction(menu, request.item);
|
AyuUi::AddHideMessageAction(menu, request.item);
|
||||||
AyuUi::AddUserMessagesAction(menu, request.item);
|
AyuUi::AddUserMessagesAction(menu, request.item);
|
||||||
AyuUi::AddMessageDetailsAction(menu, request.item);
|
AyuUi::AddMessageDetailsAction(menu, request.item);
|
||||||
|
AyuUi::AddRepeaterAction(menu, request.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPostLinkAction(menu, request);
|
AddPostLinkAction(menu, request);
|
||||||
|
|
Loading…
Add table
Reference in a new issue