feat: implement read after actions

This commit is contained in:
ZavaruKitsu 2023-09-30 15:04:54 +03:00
parent 474de0cc46
commit 4090064561
5 changed files with 60 additions and 11 deletions

View file

@ -20,6 +20,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item_helpers.h" // ShouldSendSilent #include "history/history_item_helpers.h" // ShouldSendSilent
#include "main/main_session.h" #include "main/main_session.h"
// AyuGram includes
#include "ayu/ayu_state.h"
namespace Api { namespace Api {
namespace { namespace {
@ -148,6 +152,13 @@ void Polls::sendVotes(
_pollVotesRequestIds.erase(itemId); _pollVotesRequestIds.erase(itemId);
hideSending(); hideSending();
_session->updates().applyUpdates(result); _session->updates().applyUpdates(result);
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages && settings->markReadAfterPoll && item)
{
AyuState::setAllowSendReadPacket(true);
item->history()->session().data().histories().readInboxOnNewMessage(item);
}
}).fail([=] { }).fail([=] {
_pollVotesRequestIds.erase(itemId); _pollVotesRequestIds.erase(itemId);
hideSending(); hideSending();

View file

@ -210,6 +210,16 @@ void AyuGramSettings::set_markReadAfterSend(bool val)
markReadAfterSend = val; markReadAfterSend = val;
} }
void AyuGramSettings::set_markReadAfterReaction(bool val)
{
markReadAfterReaction = val;
}
void AyuGramSettings::set_markReadAfterPoll(bool val)
{
markReadAfterPoll = val;
}
void AyuGramSettings::set_useScheduledMessages(bool val) void AyuGramSettings::set_useScheduledMessages(bool val)
{ {
useScheduledMessages = val; useScheduledMessages = val;

View file

@ -87,6 +87,8 @@ public:
bool sendUploadProgress; bool sendUploadProgress;
bool sendOfflinePacketAfterOnline; bool sendOfflinePacketAfterOnline;
bool markReadAfterSend; bool markReadAfterSend;
bool markReadAfterReaction;
bool markReadAfterPoll;
bool useScheduledMessages; bool useScheduledMessages;
bool saveDeletedMessages; bool saveDeletedMessages;
bool saveMessagesHistory; bool saveMessagesHistory;
@ -124,6 +126,10 @@ public:
void set_markReadAfterSend(bool val); void set_markReadAfterSend(bool val);
void set_markReadAfterReaction(bool val);
void set_markReadAfterPoll(bool val);
void set_useScheduledMessages(bool val); void set_useScheduledMessages(bool val);
void set_keepDeletedMessages(bool val); void set_keepDeletedMessages(bool val);
@ -175,6 +181,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
sendUploadProgress, sendUploadProgress,
sendOfflinePacketAfterOnline, sendOfflinePacketAfterOnline,
markReadAfterSend, markReadAfterSend,
markReadAfterReaction,
markReadAfterPoll,
useScheduledMessages, useScheduledMessages,
saveDeletedMessages, saveDeletedMessages,
saveMessagesHistory, saveMessagesHistory,

View file

@ -69,6 +69,7 @@ not_null<Ui::RpWidget *> AddInnerToggle(
not_null<Ui::SlideWrap<> *> wrap, not_null<Ui::SlideWrap<> *> wrap,
rpl::producer<QString> buttonLabel, rpl::producer<QString> buttonLabel,
std::optional<QString> locked, std::optional<QString> locked,
bool toggledWhenAll,
Settings::IconDescriptor &&icon) Settings::IconDescriptor &&icon)
{ {
const auto button = container->add(object_ptr<Ui::SettingsButton>( const auto button = container->add(object_ptr<Ui::SettingsButton>(
@ -165,8 +166,14 @@ not_null<Ui::RpWidget *> AddInnerToggle(
rpl::empty_value() rpl::empty_value()
) | rpl::map(countChecked) | start_with_next([=](int count) ) | rpl::map(countChecked) | start_with_next([=](int count)
{ {
checkView->setChecked(count == totalInnerChecks, if (toggledWhenAll) {
anim::type::normal); checkView->setChecked(count == totalInnerChecks,
anim::type::normal);
}
else {
checkView->setChecked(count != 0,
anim::type::normal);
}
}, toggleButton->lifetime()); }, toggleButton->lifetime());
checkView->setLocked(locked.has_value()); checkView->setLocked(locked.has_value());
checkView->finishAnimating(); checkView->finishAnimating();
@ -470,6 +477,7 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
raw, raw,
tr::ayu_GhostModeToggle(), tr::ayu_GhostModeToggle(),
std::nullopt, std::nullopt,
true,
{}); {});
container->add(std::move(wrap)); container->add(std::move(wrap));
container->widthValue( container->widthValue(
@ -545,24 +553,24 @@ void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
std::vector checkboxes{ std::vector checkboxes{
NestedEntry{ NestedEntry{
tr::ayu_MarkReadAfterSend(tr::now), false, [=](bool enabled) tr::ayu_MarkReadAfterSend(tr::now), settings->markReadAfterSend, [=](bool enabled)
{ {
// settings->set_sendReadMessages(!enabled); settings->set_markReadAfterSend(enabled);
// AyuSettings::save(); AyuSettings::save();
} }
}, },
NestedEntry{ NestedEntry{
tr::ayu_MarkReadAfterReaction(tr::now), false, [=](bool enabled) tr::ayu_MarkReadAfterReaction(tr::now), settings->markReadAfterReaction, [=](bool enabled)
{ {
// settings->set_sendReadStories(!enabled); settings->set_markReadAfterReaction(enabled);
// AyuSettings::save(); AyuSettings::save();
} }
}, },
NestedEntry{ NestedEntry{
tr::ayu_MarkReadAfterPoll(tr::now), false, [=](bool enabled) tr::ayu_MarkReadAfterPoll(tr::now), settings->markReadAfterPoll, [=](bool enabled)
{ {
// settings->set_sendOnlinePackets(!enabled); settings->set_markReadAfterPoll(enabled);
// AyuSettings::save(); AyuSettings::save();
} }
}, },
}; };
@ -591,6 +599,7 @@ void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
raw, raw,
tr::ayu_MarkReadAfterAction(), tr::ayu_MarkReadAfterAction(),
std::nullopt, std::nullopt,
false,
{}); {});
container->add(std::move(wrap)); container->add(std::move(wrap));
container->widthValue( container->widthValue(

View file

@ -30,6 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h" #include "apiwrap.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
// AyuGram includes
#include "ayu/ayu_state.h"
namespace Data { namespace Data {
namespace { namespace {
@ -821,6 +825,13 @@ void Reactions::send(not_null<HistoryItem*> item, bool addToRecent) {
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
_sentRequests.remove(id); _sentRequests.remove(id);
_owner->session().api().applyUpdates(result); _owner->session().api().applyUpdates(result);
const auto settings = &AyuSettings::getInstance();
if (!settings->sendReadMessages && settings->markReadAfterReaction && item)
{
AyuState::setAllowSendReadPacket(true);
item->history()->session().data().histories().readInboxOnNewMessage(item);
}
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
_sentRequests.remove(id); _sentRequests.remove(id);
}).send(); }).send();