mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Add "Send when online" to the send button context menu.
This commit is contained in:
parent
4201a0193c
commit
e285b22398
24 changed files with 80 additions and 31 deletions
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "api/api_common.h"
|
||||
|
||||
#include "base/qt/qt_key_modifiers.h"
|
||||
#include "data/data_thread.h"
|
||||
|
||||
namespace Api {
|
||||
|
@ -20,4 +21,11 @@ SendAction::SendAction(
|
|||
, topicRootId(replyTo) {
|
||||
}
|
||||
|
||||
SendOptions DefaultSendWhenOnlineOptions() {
|
||||
return {
|
||||
.scheduled = kScheduledUntilOnlineTimestamp,
|
||||
.silent = base::IsCtrlPressed(),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -15,6 +15,8 @@ class Thread;
|
|||
|
||||
namespace Api {
|
||||
|
||||
inline constexpr auto kScheduledUntilOnlineTimestamp = TimeId(0x7FFFFFFE);
|
||||
|
||||
struct SendOptions {
|
||||
PeerData *sendAs = nullptr;
|
||||
TimeId scheduled = 0;
|
||||
|
@ -23,6 +25,7 @@ struct SendOptions {
|
|||
bool removeWebPageId = false;
|
||||
bool hideViaBot = false;
|
||||
};
|
||||
[[nodiscard]] SendOptions DefaultSendWhenOnlineOptions();
|
||||
|
||||
enum class SendType {
|
||||
Normal,
|
||||
|
|
|
@ -1102,6 +1102,9 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
|
|||
send),
|
||||
Ui::LayerOption::KeepOther);
|
||||
};
|
||||
const auto sendWhenOnline = [=] {
|
||||
send(Api::DefaultSendWhenOnlineOptions());
|
||||
};
|
||||
|
||||
options->scrollToWidget(
|
||||
) | rpl::start_with_next([=](not_null<QWidget*> widget) {
|
||||
|
@ -1130,7 +1133,8 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
|
|||
submit.data(),
|
||||
sendMenuType,
|
||||
sendSilent,
|
||||
sendScheduled);
|
||||
sendScheduled,
|
||||
sendWhenOnline);
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
|
||||
return result;
|
||||
|
|
|
@ -508,7 +508,8 @@ void SendFilesBox::refreshButtons() {
|
|||
_send,
|
||||
[=] { return _sendMenuType; },
|
||||
[=] { sendSilent(); },
|
||||
[=] { sendScheduled(); });
|
||||
[=] { sendScheduled(); },
|
||||
[=] { sendWhenOnline(); });
|
||||
}
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
_addFile = addLeftButton(
|
||||
|
@ -584,7 +585,8 @@ void SendFilesBox::addMenuButton() {
|
|||
_menu.get(),
|
||||
_sendMenuType,
|
||||
[=] { sendSilent(); },
|
||||
[=] { sendScheduled(); });
|
||||
[=] { sendScheduled(); },
|
||||
[=] { sendWhenOnline(); });
|
||||
}
|
||||
_menu->popup(QCursor::pos());
|
||||
return true;
|
||||
|
@ -1390,4 +1392,8 @@ void SendFilesBox::sendScheduled() {
|
|||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void SendFilesBox::sendWhenOnline() {
|
||||
send(Api::DefaultSendWhenOnlineOptions());
|
||||
}
|
||||
|
||||
SendFilesBox::~SendFilesBox() = default;
|
||||
|
|
|
@ -179,6 +179,7 @@ private:
|
|||
void send(Api::SendOptions options, bool ctrlShiftEnter = false);
|
||||
void sendSilent();
|
||||
void sendScheduled();
|
||||
void sendWhenOnline();
|
||||
void captionResized();
|
||||
void saveSendWaySettings();
|
||||
|
||||
|
|
|
@ -502,7 +502,8 @@ void ShareBox::showMenu(not_null<Ui::RpWidget*> parent) {
|
|||
_menu.get(),
|
||||
sendMenuType(),
|
||||
[=] { submitSilent(); },
|
||||
[=] { submitScheduled(); });
|
||||
[=] { submitScheduled(); },
|
||||
[=] { submitWhenOnline(); });
|
||||
const auto success = (result == SendMenu::FillMenuResult::Success);
|
||||
if (_descriptor.forwardOptions.show || success) {
|
||||
_menu->setForcedVerticalOrigin(Ui::PopupMenu::VerticalOrigin::Bottom);
|
||||
|
@ -599,6 +600,10 @@ void ShareBox::submitScheduled() {
|
|||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void ShareBox::submitWhenOnline() {
|
||||
submit(Api::DefaultSendWhenOnlineOptions());
|
||||
}
|
||||
|
||||
void ShareBox::copyLink() {
|
||||
if (const auto onstack = _descriptor.copyCallback) {
|
||||
onstack();
|
||||
|
|
|
@ -118,6 +118,7 @@ private:
|
|||
void submit(Api::SendOptions options);
|
||||
void submitSilent();
|
||||
void submitScheduled();
|
||||
void submitWhenOnline();
|
||||
void copyLink();
|
||||
bool searchByUsername(bool useCache = false);
|
||||
|
||||
|
|
|
@ -1023,7 +1023,8 @@ void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) {
|
|||
_menu.get(),
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(sendSelected),
|
||||
SendMenu::DefaultScheduleCallback(this, type, sendSelected));
|
||||
SendMenu::DefaultScheduleCallback(this, type, sendSelected),
|
||||
SendMenu::DefaultWhenOnlineCallback(sendSelected));
|
||||
|
||||
const auto controller = _controller;
|
||||
const auto toggleFavedSticker = [=] {
|
||||
|
|
|
@ -1283,7 +1283,8 @@ void FieldAutocomplete::Inner::contextMenuEvent(QContextMenuEvent *e) {
|
|||
_menu,
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
SendMenu::DefaultScheduleCallback(this, type, send),
|
||||
SendMenu::DefaultWhenOnlineCallback(send));
|
||||
|
||||
if (!_menu->empty()) {
|
||||
_menu->popup(QCursor::pos());
|
||||
|
|
|
@ -381,7 +381,8 @@ base::unique_qptr<Ui::PopupMenu> GifsListWidget::fillContextMenu(
|
|||
menu,
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
SendMenu::DefaultScheduleCallback(this, type, send),
|
||||
SendMenu::DefaultWhenOnlineCallback(send));
|
||||
|
||||
if (const auto item = _mosaic.maybeItemAt(_selected)) {
|
||||
const auto document = item->getDocument()
|
||||
|
|
|
@ -1608,7 +1608,8 @@ base::unique_qptr<Ui::PopupMenu> StickersListWidget::fillContextMenu(
|
|||
menu,
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
SendMenu::DefaultScheduleCallback(this, type, send),
|
||||
SendMenu::DefaultWhenOnlineCallback(send));
|
||||
|
||||
const auto window = _controller;
|
||||
const auto toggleFavedSticker = [=] {
|
||||
|
|
|
@ -40,7 +40,7 @@ constexpr auto kRequestTimeLimit = 60 * crl::time(1000);
|
|||
}
|
||||
|
||||
[[nodiscard]] bool HasScheduledDate(not_null<HistoryItem*> item) {
|
||||
return (item->date() != ScheduledMessages::kScheduledUntilOnlineTimestamp)
|
||||
return (item->date() != Api::kScheduledUntilOnlineTimestamp)
|
||||
&& (item->date() > base::unixtime::now());
|
||||
}
|
||||
|
||||
|
|
|
@ -53,8 +53,6 @@ public:
|
|||
[[nodiscard]] rpl::producer<> updates(not_null<History*> history);
|
||||
[[nodiscard]] Data::MessagesSlice list(not_null<History*> history);
|
||||
|
||||
static constexpr auto kScheduledUntilOnlineTimestamp = TimeId(0x7FFFFFFE);
|
||||
|
||||
private:
|
||||
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
||||
struct List {
|
||||
|
|
|
@ -50,7 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "dialogs/ui/dialogs_message_view.h"
|
||||
#include "data/notify/data_notify_settings.h"
|
||||
#include "data/data_bot_app.h"
|
||||
#include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
|
||||
#include "data/data_scheduled_messages.h"
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_message_reactions.h"
|
||||
|
|
|
@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_media_types.h"
|
||||
#include "data/data_message_reactions.h"
|
||||
#include "data/data_scheduled_messages.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "history/history.h"
|
||||
|
@ -230,8 +229,7 @@ QString ItemDateText(not_null<const HistoryItem*> item, bool isUntilOnline) {
|
|||
|
||||
bool IsItemScheduledUntilOnline(not_null<const HistoryItem*> item) {
|
||||
return item->isScheduled()
|
||||
&& (item->date() ==
|
||||
Data::ScheduledMessages::kScheduledUntilOnlineTimestamp);
|
||||
&& (item->date() == Api::kScheduledUntilOnlineTimestamp);
|
||||
}
|
||||
|
||||
ClickHandlerPtr JumpToMessageClickHandler(
|
||||
|
|
|
@ -305,7 +305,8 @@ HistoryWidget::HistoryWidget(
|
|||
_send.get(),
|
||||
[=] { return sendButtonMenuType(); },
|
||||
[=] { sendSilent(); },
|
||||
[=] { sendScheduled(); });
|
||||
[=] { sendScheduled(); },
|
||||
[=] { sendWhenOnline(); });
|
||||
|
||||
_unblock->addClickHandler([=] { unblockUser(); });
|
||||
_botStart->addClickHandler([=] { sendBotStartCommand(); });
|
||||
|
@ -3934,6 +3935,10 @@ void HistoryWidget::sendScheduled() {
|
|||
Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void HistoryWidget::sendWhenOnline() {
|
||||
send(Api::DefaultSendWhenOnlineOptions());
|
||||
}
|
||||
|
||||
SendMenu::Type HistoryWidget::sendMenuType() const {
|
||||
return !_peer
|
||||
? SendMenu::Type::Disabled
|
||||
|
|
|
@ -379,6 +379,7 @@ private:
|
|||
void sendWithModifiers(Qt::KeyboardModifiers modifiers);
|
||||
void sendSilent();
|
||||
void sendScheduled();
|
||||
void sendWhenOnline();
|
||||
[[nodiscard]] SendMenu::Type sendButtonMenuType() const;
|
||||
void handlePendingHistoryUpdate();
|
||||
void fullInfoUpdated();
|
||||
|
|
|
@ -2075,7 +2075,8 @@ void ComposeControls::initSendButton() {
|
|||
_send.get(),
|
||||
[=] { return sendButtonMenuType(); },
|
||||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(_wrap.get(), sendMenuType(), send));
|
||||
SendMenu::DefaultScheduleCallback(_wrap.get(), sendMenuType(), send),
|
||||
SendMenu::DefaultWhenOnlineCallback(send));
|
||||
}
|
||||
|
||||
void ComposeControls::initSendAsButton(not_null<PeerData*> peer) {
|
||||
|
|
|
@ -52,7 +52,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_channel.h"
|
||||
#include "data/data_file_click_handler.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_scheduled_messages.h"
|
||||
#include "data/data_message_reactions.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "core/file_utilities.h"
|
||||
|
@ -555,9 +554,8 @@ bool AddRescheduleAction(
|
|||
? SendMenu::Type::ScheduledToUser
|
||||
: SendMenu::Type::Scheduled;
|
||||
|
||||
using S = Data::ScheduledMessages;
|
||||
const auto itemDate = firstItem->date();
|
||||
const auto date = (itemDate == S::kScheduledUntilOnlineTimestamp)
|
||||
const auto date = (itemDate == Api::kScheduledUntilOnlineTimestamp)
|
||||
? HistoryView::DefaultScheduleTime()
|
||||
: itemDate + 600;
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "api/api_common.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
|
||||
#include "lang/lang_keys.h"
|
||||
#include "base/event_filter.h"
|
||||
#include "base/qt/qt_key_modifiers.h"
|
||||
|
@ -98,12 +97,12 @@ void ScheduleBox(
|
|||
descriptor.submit.data(),
|
||||
[=] { return SendMenu::Type::SilentOnly; },
|
||||
[=] { save(true, descriptor.collect()); },
|
||||
nullptr,
|
||||
nullptr);
|
||||
|
||||
if (type == SendMenu::Type::ScheduledToUser) {
|
||||
const auto sendUntilOnline = box->addTopButton(*style.topButtonStyle);
|
||||
const auto timestamp
|
||||
= Data::ScheduledMessages::kScheduledUntilOnlineTimestamp;
|
||||
const auto timestamp = Api::kScheduledUntilOnlineTimestamp;
|
||||
FillSendUntilOnlineMenu(
|
||||
sendUntilOnline.data(),
|
||||
[=] { save(false, timestamp); },
|
||||
|
|
|
@ -344,7 +344,8 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) {
|
|||
_menu,
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(send),
|
||||
SendMenu::DefaultScheduleCallback(this, type, send));
|
||||
SendMenu::DefaultScheduleCallback(this, type, send),
|
||||
SendMenu::DefaultWhenOnlineCallback(send));
|
||||
|
||||
const auto item = _mosaic.itemAt(_selected);
|
||||
if (const auto previewDocument = item->getPreviewDocument()) {
|
||||
|
|
|
@ -47,11 +47,16 @@ Fn<void()> DefaultScheduleCallback(
|
|||
};
|
||||
}
|
||||
|
||||
Fn<void()> DefaultWhenOnlineCallback(Fn<void(Api::SendOptions)> send) {
|
||||
return [=] { send(Api::DefaultSendWhenOnlineOptions()); };
|
||||
}
|
||||
|
||||
FillMenuResult FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Type type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
Fn<void()> schedule,
|
||||
Fn<void()> whenOnline) {
|
||||
if (!silent && !schedule) {
|
||||
return FillMenuResult::None;
|
||||
}
|
||||
|
@ -75,6 +80,12 @@ FillMenuResult FillSendMenu(
|
|||
schedule,
|
||||
&st::menuIconSchedule);
|
||||
}
|
||||
if (whenOnline && now == Type::ScheduledToUser) {
|
||||
menu->addAction(
|
||||
tr::lng_scheduled_send_until_online(tr::now),
|
||||
whenOnline,
|
||||
&st::menuIconWhenOnline);
|
||||
}
|
||||
return FillMenuResult::Success;
|
||||
}
|
||||
|
||||
|
@ -82,8 +93,9 @@ void SetupMenuAndShortcuts(
|
|||
not_null<Ui::RpWidget*> button,
|
||||
Fn<Type()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule) {
|
||||
if (!silent && !schedule) {
|
||||
Fn<void()> schedule,
|
||||
Fn<void()> whenOnline) {
|
||||
if (!silent && !schedule && !whenOnline) {
|
||||
return;
|
||||
}
|
||||
const auto menu = std::make_shared<base::unique_qptr<Ui::PopupMenu>>();
|
||||
|
@ -91,7 +103,7 @@ void SetupMenuAndShortcuts(
|
|||
*menu = base::make_unique_q<Ui::PopupMenu>(
|
||||
button,
|
||||
st::popupMenuWithIcons);
|
||||
const auto result = FillSendMenu(*menu, type(), silent, schedule);
|
||||
const auto result = FillSendMenu(*menu, type(), silent, schedule, whenOnline);
|
||||
const auto success = (result == FillMenuResult::Success);
|
||||
if (success) {
|
||||
(*menu)->popup(QCursor::pos());
|
||||
|
|
|
@ -40,18 +40,21 @@ Fn<void()> DefaultScheduleCallback(
|
|||
not_null<Ui::RpWidget*> parent,
|
||||
Type type,
|
||||
Fn<void(Api::SendOptions)> send);
|
||||
Fn<void()> DefaultWhenOnlineCallback(Fn<void(Api::SendOptions)> send);
|
||||
|
||||
FillMenuResult FillSendMenu(
|
||||
not_null<Ui::PopupMenu*> menu,
|
||||
Type type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
Fn<void()> schedule,
|
||||
Fn<void()> whenOnline);
|
||||
|
||||
void SetupMenuAndShortcuts(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
Fn<Type()> type,
|
||||
Fn<void()> silent,
|
||||
Fn<void()> schedule);
|
||||
Fn<void()> schedule,
|
||||
Fn<void()> whenOnline);
|
||||
|
||||
void SetupUnreadMentionsMenu(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
|
|
|
@ -1885,7 +1885,8 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
|
|||
state->menu.get(),
|
||||
type,
|
||||
SendMenu::DefaultSilentCallback(submit),
|
||||
SendMenu::DefaultScheduleCallback(state->box, type, submit));
|
||||
SendMenu::DefaultScheduleCallback(state->box, type, submit),
|
||||
SendMenu::DefaultWhenOnlineCallback(submit));
|
||||
const auto success = (result == SendMenu::FillMenuResult::Success);
|
||||
if (showForwardOptions || success) {
|
||||
state->menu->setForcedVerticalOrigin(
|
||||
|
|
Loading…
Add table
Reference in a new issue