mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
feat: implement useScheduleMessages
fully
This commit is contained in:
parent
6fd0fb9704
commit
fe463ab8fb
9 changed files with 84 additions and 36 deletions
|
@ -3619,9 +3619,8 @@ void ApiWrap::sendUploadedPhoto(
|
|||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling message"));
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 18; // using 18 seconds because photo can be big
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
|
||||
const auto media = Api::PrepareUploadedPhoto(item, std::move(info));
|
||||
|
@ -3645,9 +3644,8 @@ void ApiWrap::sendUploadedDocument(
|
|||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling message"));
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 60; // well, a document can be really big...
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
|
||||
const auto media = Api::PrepareUploadedDocument(
|
||||
|
@ -4162,7 +4160,6 @@ void ApiWrap::sendMediaWithRandomId(
|
|||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling message"));
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
|
@ -4261,15 +4258,6 @@ void ApiWrap::sendAlbumIfReady(not_null<SendingAlbum*> album) {
|
|||
_sendingAlbums.remove(groupId);
|
||||
return;
|
||||
}
|
||||
|
||||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !album->options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling message"));
|
||||
auto current = base::unixtime::now();
|
||||
album->options.scheduled = current + 12;
|
||||
}
|
||||
|
||||
auto sample = (HistoryItem*)nullptr;
|
||||
auto medias = QVector<MTPInputSingleMedia>();
|
||||
medias.reserve(album->items.size());
|
||||
|
@ -4294,6 +4282,14 @@ void ApiWrap::sendAlbumIfReady(not_null<SendingAlbum*> album) {
|
|||
_sendingAlbums.remove(groupId);
|
||||
return;
|
||||
}
|
||||
|
||||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !album->options.scheduled) {
|
||||
auto current = base::unixtime::now();
|
||||
album->options.scheduled = current + 12;
|
||||
}
|
||||
|
||||
const auto history = sample->history();
|
||||
const auto replyTo = sample->replyTo();
|
||||
const auto sendAs = album->options.sendAs;
|
||||
|
|
|
@ -462,12 +462,15 @@ void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
SetupGhostModeToggle(container);
|
||||
|
||||
auto markReadAfterActionVal = container->lifetime().make_state<rpl::variable<bool>>(settings->markReadAfterAction);
|
||||
auto useScheduledMessagesVal = container->lifetime().make_state<rpl::variable<bool>>(settings->useScheduledMessages);
|
||||
|
||||
AddButtonWithIcon(
|
||||
container,
|
||||
tr::ayu_MarkReadAfterAction(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->markReadAfterAction)
|
||||
markReadAfterActionVal->value()
|
||||
)->toggledValue(
|
||||
) | rpl::filter(
|
||||
[=](bool enabled)
|
||||
|
@ -477,6 +480,11 @@ void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
[=](bool enabled)
|
||||
{
|
||||
settings->set_markReadAfterAction(enabled);
|
||||
if (enabled) {
|
||||
settings->set_useScheduledMessages(false);
|
||||
useScheduledMessagesVal->force_assign(false);
|
||||
}
|
||||
|
||||
AyuSettings::save();
|
||||
},
|
||||
container->lifetime());
|
||||
|
@ -486,14 +494,10 @@ void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
AddSkip(container);
|
||||
AddButtonWithIcon(
|
||||
container,
|
||||
tr::ayu_UseScheduledMessages() | rpl::map(
|
||||
[=](QString val)
|
||||
{
|
||||
return val + " β";
|
||||
}),
|
||||
tr::ayu_UseScheduledMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->useScheduledMessages)
|
||||
useScheduledMessagesVal->value()
|
||||
)->toggledValue(
|
||||
) | rpl::filter(
|
||||
[=](bool enabled)
|
||||
|
@ -503,6 +507,11 @@ void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
[=](bool enabled)
|
||||
{
|
||||
settings->set_useScheduledMessages(enabled);
|
||||
if (enabled) {
|
||||
settings->set_markReadAfterAction(false);
|
||||
markReadAfterActionVal->force_assign(false);
|
||||
}
|
||||
|
||||
AyuSettings::save();
|
||||
},
|
||||
container->lifetime());
|
||||
|
@ -517,11 +526,7 @@ void SetupSpyEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
|
||||
AddButtonWithIcon(
|
||||
container,
|
||||
tr::ayu_SaveDeletedMessages() | rpl::map(
|
||||
[=](QString val)
|
||||
{
|
||||
return val + " β";
|
||||
}),
|
||||
tr::ayu_SaveDeletedMessages(),
|
||||
st::settingsButtonNoIcon
|
||||
)->toggleOn(
|
||||
rpl::single(settings->saveDeletedMessages)
|
||||
|
|
|
@ -346,9 +346,9 @@ QString formatDateTime(const QDateTime &date) {
|
|||
return datePart + getLocalizedAt() + timePart;
|
||||
}
|
||||
|
||||
QString getMediaSize(not_null<HistoryItem*> message) {
|
||||
int getMediaSizeBytes(not_null<HistoryItem*> message) {
|
||||
if (!message->media()) {
|
||||
return {};
|
||||
return -1;
|
||||
}
|
||||
|
||||
const auto media = message->media();
|
||||
|
@ -380,6 +380,12 @@ QString getMediaSize(not_null<HistoryItem*> message) {
|
|||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
QString getMediaSize(not_null<HistoryItem*> message) {
|
||||
const auto size = getMediaSizeBytes(message);
|
||||
|
||||
if (size == -1) {
|
||||
return {};
|
||||
}
|
||||
|
@ -481,6 +487,14 @@ QString getMediaDC(not_null<HistoryItem*> message) {
|
|||
return {};
|
||||
}
|
||||
|
||||
int getScheduleTime(int64 sumSize) {
|
||||
auto time = 12;
|
||||
|
||||
time += (int) std::ceil(std::max(6.0, std::ceil(sumSize / 1024.0 / 1024.0 * 4.5))) + 1;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
void resolveUser(ID userId, const QString &username, Main::Session *session, const Callback &callback) {
|
||||
auto normalized = username.trimmed().toLower();
|
||||
if (normalized.isEmpty()) {
|
||||
|
|
|
@ -41,5 +41,7 @@ QString getMediaName(not_null<HistoryItem*> message);
|
|||
QString getMediaResolution(not_null<HistoryItem*> message);
|
||||
QString getMediaDC(not_null<HistoryItem*> message);
|
||||
|
||||
int getScheduleTime(int64 sumSize);
|
||||
|
||||
void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback);
|
||||
void searchById(ID userId, Main::Session *session, const Callback &callback);
|
||||
|
|
|
@ -59,6 +59,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ayu/ayu_settings.h"
|
||||
#include "base/unixtime.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "ayu/utils/telegram_helpers.h"
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
|
@ -1463,8 +1464,14 @@ void SendFilesBox::send(
|
|||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling files"));
|
||||
const auto sumSize = ranges::accumulate(
|
||||
_list.files,
|
||||
0,
|
||||
[](int sum, const auto &file) {
|
||||
return sum + file.size;
|
||||
});
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 60; // well, files can be huge...
|
||||
options.scheduled = current + getScheduleTime(sumSize);
|
||||
}
|
||||
|
||||
if ((_sendType == Api::SendType::Scheduled
|
||||
|
|
|
@ -48,6 +48,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ayu/ayu_settings.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "base/unixtime.h"
|
||||
|
||||
|
||||
namespace ChatHelpers {
|
||||
|
@ -460,6 +461,12 @@ void GifsListWidget::selectInlineResult(
|
|||
return;
|
||||
}
|
||||
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages) {
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
|
||||
const auto messageSendingFrom = [&] {
|
||||
if (options.scheduled) {
|
||||
return Ui::MessageSendingAnimationFrom();
|
||||
|
@ -491,7 +498,6 @@ void GifsListWidget::selectInlineResult(
|
|||
const auto media = document->activeMediaView();
|
||||
const auto preview = Data::VideoPreviewState(media.get());
|
||||
if (forceSend || (media && preview.loaded())) {
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
auto from = messageSendingFrom();
|
||||
auto sendGIFCallback = crl::guard(
|
||||
this,
|
||||
|
|
|
@ -58,6 +58,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
// AyuGram includes
|
||||
#include "ayu/ayu_settings.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "base/unixtime.h"
|
||||
|
||||
|
||||
namespace ChatHelpers {
|
||||
|
@ -1758,12 +1759,18 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
|||
sticker->index,
|
||||
document
|
||||
);
|
||||
auto options = Api::SendOptions();
|
||||
if (settings->useScheduledMessages) {
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
auto sendStickerCallback = crl::guard(
|
||||
this,
|
||||
[=, this]
|
||||
{
|
||||
_chosen.fire({
|
||||
.document = document,
|
||||
.options = options,
|
||||
.messageSendingFrom = from,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -934,10 +934,14 @@ HistoryWidget::HistoryWidget(
|
|||
if (action.replaceMediaOf) {
|
||||
} else if (action.options.scheduled) {
|
||||
cancelReply(lastKeyboardUsed);
|
||||
crl::on_main(this, [=, history = action.history] {
|
||||
controller->showSection(
|
||||
std::make_shared<HistoryView::ScheduledMemento>(history));
|
||||
});
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (!settings->useScheduledMessages) {
|
||||
crl::on_main(this, [=, history = action.history]
|
||||
{
|
||||
controller->showSection(
|
||||
std::make_shared<HistoryView::ScheduledMemento>(history));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
fastShowAtEnd(action.history);
|
||||
if (!_justMarkingAsRead
|
||||
|
@ -4136,7 +4140,6 @@ void HistoryWidget::send(Api::SendOptions options) {
|
|||
// AyuGram useScheduledMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages && !options.scheduled) {
|
||||
DEBUG_LOG(("[AyuGram] Scheduling message"));
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12;
|
||||
}
|
||||
|
|
|
@ -1798,13 +1798,17 @@ void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) {
|
|||
|
||||
window()->raise();
|
||||
window()->activateWindow();
|
||||
const auto options = Api::SendOptions{
|
||||
auto options = Api::SendOptions{
|
||||
.ttlSeconds = (ttlBeforeHide
|
||||
? std::numeric_limits<int>::max()
|
||||
: 0),
|
||||
};
|
||||
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages) {
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12 + 5;
|
||||
}
|
||||
auto sendVoiceCallback = crl::guard(
|
||||
this,
|
||||
[=, this](Fn<void()> &&close)
|
||||
|
@ -1893,6 +1897,10 @@ void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) {
|
|||
}
|
||||
|
||||
auto settings = &AyuSettings::getInstance();
|
||||
if (settings->useScheduledMessages) {
|
||||
auto current = base::unixtime::now();
|
||||
options.scheduled = current + 12 + 5;
|
||||
}
|
||||
auto sendVoiceCallback = crl::guard(
|
||||
this,
|
||||
[=, this](Fn<void()> &&close)
|
||||
|
|
Loading…
Add table
Reference in a new issue