feat: ability to disable save deleted messages in bot dialogs

This commit is contained in:
AlexeyZavar 2024-09-27 20:36:34 +03:00
parent 157b25ea43
commit b073810bab
8 changed files with 76 additions and 24 deletions

View file

@ -210,6 +210,8 @@ AyuGramSettings::AyuGramSettings() {
saveDeletedMessages = true; saveDeletedMessages = true;
saveMessagesHistory = true; saveMessagesHistory = true;
saveForBots = false;
// ~ Message filters // ~ Message filters
hideFromBlocked = false; hideFromBlocked = false;
@ -354,6 +356,10 @@ void AyuGramSettings::set_saveMessagesHistory(bool val) {
saveMessagesHistory = val; saveMessagesHistory = val;
} }
void AyuGramSettings::set_saveForBots(bool val) {
saveForBots = val;
}
void AyuGramSettings::set_hideFromBlocked(bool val) { void AyuGramSettings::set_hideFromBlocked(bool val) {
hideFromBlocked = val; hideFromBlocked = val;
hideFromBlockedReactive = val; hideFromBlockedReactive = val;

View file

@ -30,6 +30,8 @@ public:
bool saveDeletedMessages; bool saveDeletedMessages;
bool saveMessagesHistory; bool saveMessagesHistory;
bool saveForBots;
bool hideFromBlocked; bool hideFromBlocked;
bool disableAds; bool disableAds;
@ -105,6 +107,8 @@ public:
void set_saveDeletedMessages(bool val); void set_saveDeletedMessages(bool val);
void set_saveMessagesHistory(bool val); void set_saveMessagesHistory(bool val);
void set_saveForBots(bool val);
void set_hideFromBlocked(bool val); void set_hideFromBlocked(bool val);
void set_disableAds(bool val); void set_disableAds(bool val);
@ -178,6 +182,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
sendWithoutSound, sendWithoutSound,
saveDeletedMessages, saveDeletedMessages,
saveMessagesHistory, saveMessagesHistory,
saveForBots,
hideFromBlocked, hideFromBlocked,
disableAds, disableAds,
disableStories, disableStories,

View file

@ -59,6 +59,7 @@ void map(not_null<HistoryItem*> item, AyuMessageBase &message) {
message.fwdFlags = 0; message.fwdFlags = 0;
message.fwdFromId = 0; message.fwdFromId = 0;
// message.fwdName // message.fwdName
message.fwdDate = 0;
// message.fwdPostAuthor // message.fwdPostAuthor
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) { if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
message.postAuthor = msgsigned->author.toStdString(); message.postAuthor = msgsigned->author.toStdString();
@ -67,7 +68,7 @@ void map(not_null<HistoryItem*> item, AyuMessageBase &message) {
message.replyMessageId = 0; message.replyMessageId = 0;
message.replyPeerId = 0; message.replyPeerId = 0;
message.replyTopId = 0; message.replyTopId = 0;
message.replyForumTopic = 0; message.replyForumTopic = false;
// message.replySerialized // message.replySerialized
// message.replyMarkupSerialized // message.replyMarkupSerialized
message.entityCreateDate = base::unixtime::now(); message.entityCreateDate = base::unixtime::now();

View file

@ -76,9 +76,6 @@ void GenerateItems(
if (!from) { if (!from) {
from = reinterpret_cast<PeerData*>(history->owner().chatLoaded(message.fromId)); from = reinterpret_cast<PeerData*>(history->owner().chatLoaded(message.fromId));
} }
if (!from) {
return;
}
const auto date = message.entityCreateDate; const auto date = message.entityCreateDate;
const auto addPart = [&]( const auto addPart = [&](
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
@ -88,17 +85,28 @@ void GenerateItems(
return callback(OwnedItem(delegate, item), sentDate, realId); return callback(OwnedItem(delegate, item), sentDate, realId);
}; };
const auto fromName = from->name();
const auto fromLink = from->createOpenLink();
const auto fromLinkText = Ui::Text::Link(fromName, QString());
const auto makeSimpleTextMessage = [&](TextWithEntities &&text) const auto makeSimpleTextMessage = [&](TextWithEntities &&text)
{ {
base::flags<MessageFlag> flags = MessageFlag::AdminLogEntry;
if (from) {
flags |= MessageFlag::HasFromId;
} else {
flags |= MessageFlag::HasPostAuthor;
}
if (!message.postAuthor.empty()) {
flags |= MessageFlag::HasPostAuthor;
}
return history->makeMessage({ return history->makeMessage({
.id = history->nextNonHistoryEntryId(), .id = history->nextNonHistoryEntryId(),
.flags = MessageFlag::HasFromId | MessageFlag::AdminLogEntry, .flags = flags,
.from = from->id, .from = from ? from->id : 0,
.date = date, .date = date,
.postAuthor = !message.postAuthor.empty()
? QString::fromStdString(message.postAuthor)
: from
? QString()
: QString("unknown user: %1").arg(message.fromId),
}, },
std::move(text), std::move(text),
MTP_messageMediaEmpty()); MTP_messageMediaEmpty());

View file

@ -6,7 +6,6 @@
// Copyright @Radolyn, 2024 // Copyright @Radolyn, 2024
#include "settings_ayu.h" #include "settings_ayu.h"
#include "ayu/ayu_settings.h" #include "ayu/ayu_settings.h"
#include "ayu/ui/boxes/edit_deleted_mark.h" #include "ayu/ui/boxes/edit_deleted_mark.h"
#include "ayu/ui/boxes/edit_edited_mark.h" #include "ayu/ui/boxes/edit_edited_mark.h"
@ -508,7 +507,8 @@ void SetupGhostEssentials(not_null<Ui::VerticalLayout*> container) {
SetupGhostModeToggle(container); SetupGhostModeToggle(container);
auto markReadAfterActionVal = container->lifetime().make_state<rpl::variable<bool>>(settings->markReadAfterAction); auto markReadAfterActionVal = container->lifetime().make_state<rpl::variable<bool>>(settings->markReadAfterAction);
auto useScheduledMessagesVal = container->lifetime().make_state<rpl::variable<bool>>(settings->useScheduledMessages); auto useScheduledMessagesVal = container->lifetime().make_state<rpl::variable<
bool>>(settings->useScheduledMessages);
AddButtonWithIcon( AddButtonWithIcon(
container, container,
@ -628,6 +628,29 @@ void SetupSpyEssentials(not_null<Ui::VerticalLayout*> container) {
AyuSettings::save(); AyuSettings::save();
}, },
container->lifetime()); container->lifetime());
AddSkip(container);
AddDivider(container);
AddSkip(container);
AddButtonWithIcon(
container,
tr::ayu_MessageSavingSaveForBots(),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->saveForBots)
)->toggledValue(
) | rpl::filter(
[=](bool enabled)
{
return (enabled != settings->saveForBots);
}) | start_with_next(
[=](bool enabled)
{
settings->set_saveForBots(enabled);
AyuSettings::save();
},
container->lifetime());
} }
void SetupMessageFilters(not_null<Ui::VerticalLayout*> container) { void SetupMessageFilters(not_null<Ui::VerticalLayout*> container) {

View file

@ -213,6 +213,19 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
double(std::numeric_limits<int>::max()))); double(std::numeric_limits<int>::max())));
} }
bool NeedSaveMessage(not_null<HistoryItem *> item) {
const auto settings = &AyuSettings::getInstance();
if (!settings->saveDeletedMessages) {
return false;
}
if (const auto possiblyBot = item->history()->peer->asUser()) {
return !possiblyBot->isBot() || settings->saveForBots && possiblyBot->isBot();
}
return true;
}
} // namespace } // namespace
Session::Session(not_null<Main::Session*> session) Session::Session(not_null<Main::Session*> session)
@ -2549,25 +2562,23 @@ void Session::processMessagesDeleted(
return; return;
} }
const auto settings = &AyuSettings::getInstance();
auto historiesToCheck = base::flat_set<not_null<History*>>(); auto historiesToCheck = base::flat_set<not_null<History*>>();
for (const auto &messageId : data) { for (const auto &messageId : data) {
const auto i = list ? list->find(messageId.v) : Messages::iterator(); const auto i = list ? list->find(messageId.v) : Messages::iterator();
if (list && i != list->end()) { if (list && i != list->end()) {
const auto history = i->second->history(); const auto history = i->second->history();
if (!settings->saveDeletedMessages) { if (!NeedSaveMessage(i->second)) {
i->second->destroy(); i->second->destroy();
} else { } else {
i->second->setDeleted(); i->second->setDeleted();
AyuMessages::addDeletedMessage(i->second); AyuMessages::addDeletedMessage(i->second);
} }
if (!history->chatListMessageKnown() && !settings->saveDeletedMessages) { if (!history->chatListMessageKnown()) {
historiesToCheck.emplace(history); historiesToCheck.emplace(history);
} }
} else if (affected && !settings->saveDeletedMessages) { } else if (affected) {
affected->unknownMessageDeleted(messageId.v); affected->unknownMessageDeleted(messageId.v);
} }
} }
@ -2577,21 +2588,19 @@ void Session::processMessagesDeleted(
} }
void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) { void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) {
const auto settings = &AyuSettings::getInstance();
auto historiesToCheck = base::flat_set<not_null<History*>>(); auto historiesToCheck = base::flat_set<not_null<History*>>();
for (const auto &messageId : data) { for (const auto &messageId : data) {
if (const auto item = nonChannelMessage(messageId.v)) { if (const auto item = nonChannelMessage(messageId.v)) {
const auto history = item->history(); const auto history = item->history();
if (!settings->saveDeletedMessages) { if (!NeedSaveMessage(item)) {
item->destroy(); item->destroy();
} else { } else {
item->setDeleted(); item->setDeleted();
AyuMessages::addDeletedMessage(item); AyuMessages::addDeletedMessage(item);
} }
if (!history->chatListMessageKnown() && !settings->saveDeletedMessages) { if (!history->chatListMessageKnown()) {
historiesToCheck.emplace(history); historiesToCheck.emplace(history);
} }
} }

View file

@ -1359,7 +1359,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...)
{ {
const auto idText = IDString(peer); const auto idText = IDString(peer->forumTopicFor(topicRootId)->topicRootId());
if (!idText.isEmpty()) { if (!idText.isEmpty()) {
QGuiApplication::clipboard()->setText(idText); QGuiApplication::clipboard()->setText(idText);
const auto msg = tr::ayu_IDCopiedToast(tr::now); const auto msg = tr::ayu_IDCopiedToast(tr::now);

View file

@ -1431,7 +1431,7 @@ void Filler::fillHistoryActions() {
addExportChat(); addExportChat();
addTranslate(); addTranslate();
addReport(); addReport();
AyuUi::AddDeletedMessagesActions(_peer, _topic ? _topic : _thread, _controller, _addAction); AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
addClearHistory(); addClearHistory();
addDeleteChat(); addDeleteChat();
addLeaveChat(); addLeaveChat();
@ -1470,7 +1470,7 @@ void Filler::fillRepliesActions() {
addCreatePoll(); addCreatePoll();
addToggleTopicClosed(); addToggleTopicClosed();
addDeleteTopic(); addDeleteTopic();
AyuUi::AddDeletedMessagesActions(_peer, _topic ? _topic : _thread, _controller, _addAction); AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
} }
void Filler::fillScheduledActions() { void Filler::fillScheduledActions() {