mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 21:27:07 +02:00
feat: ability to disable save deleted messages in bot dialogs
This commit is contained in:
parent
157b25ea43
commit
b073810bab
8 changed files with 76 additions and 24 deletions
|
@ -210,6 +210,8 @@ AyuGramSettings::AyuGramSettings() {
|
|||
saveDeletedMessages = true;
|
||||
saveMessagesHistory = true;
|
||||
|
||||
saveForBots = false;
|
||||
|
||||
// ~ Message filters
|
||||
hideFromBlocked = false;
|
||||
|
||||
|
@ -354,6 +356,10 @@ void AyuGramSettings::set_saveMessagesHistory(bool val) {
|
|||
saveMessagesHistory = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_saveForBots(bool val) {
|
||||
saveForBots = val;
|
||||
}
|
||||
|
||||
void AyuGramSettings::set_hideFromBlocked(bool val) {
|
||||
hideFromBlocked = val;
|
||||
hideFromBlockedReactive = val;
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
bool saveDeletedMessages;
|
||||
bool saveMessagesHistory;
|
||||
|
||||
bool saveForBots;
|
||||
|
||||
bool hideFromBlocked;
|
||||
|
||||
bool disableAds;
|
||||
|
@ -105,6 +107,8 @@ public:
|
|||
void set_saveDeletedMessages(bool val);
|
||||
void set_saveMessagesHistory(bool val);
|
||||
|
||||
void set_saveForBots(bool val);
|
||||
|
||||
void set_hideFromBlocked(bool val);
|
||||
|
||||
void set_disableAds(bool val);
|
||||
|
@ -178,6 +182,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
|
|||
sendWithoutSound,
|
||||
saveDeletedMessages,
|
||||
saveMessagesHistory,
|
||||
saveForBots,
|
||||
hideFromBlocked,
|
||||
disableAds,
|
||||
disableStories,
|
||||
|
|
|
@ -59,6 +59,7 @@ void map(not_null<HistoryItem*> item, AyuMessageBase &message) {
|
|||
message.fwdFlags = 0;
|
||||
message.fwdFromId = 0;
|
||||
// message.fwdName
|
||||
message.fwdDate = 0;
|
||||
// message.fwdPostAuthor
|
||||
if (const auto msgsigned = item->Get<HistoryMessageSigned>()) {
|
||||
message.postAuthor = msgsigned->author.toStdString();
|
||||
|
@ -67,7 +68,7 @@ void map(not_null<HistoryItem*> item, AyuMessageBase &message) {
|
|||
message.replyMessageId = 0;
|
||||
message.replyPeerId = 0;
|
||||
message.replyTopId = 0;
|
||||
message.replyForumTopic = 0;
|
||||
message.replyForumTopic = false;
|
||||
// message.replySerialized
|
||||
// message.replyMarkupSerialized
|
||||
message.entityCreateDate = base::unixtime::now();
|
||||
|
|
|
@ -76,9 +76,6 @@ void GenerateItems(
|
|||
if (!from) {
|
||||
from = reinterpret_cast<PeerData*>(history->owner().chatLoaded(message.fromId));
|
||||
}
|
||||
if (!from) {
|
||||
return;
|
||||
}
|
||||
const auto date = message.entityCreateDate;
|
||||
const auto addPart = [&](
|
||||
not_null<HistoryItem*> item,
|
||||
|
@ -88,17 +85,28 @@ void GenerateItems(
|
|||
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)
|
||||
{
|
||||
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({
|
||||
.id = history->nextNonHistoryEntryId(),
|
||||
.flags = MessageFlag::HasFromId | MessageFlag::AdminLogEntry,
|
||||
.from = from->id,
|
||||
.flags = flags,
|
||||
.from = from ? from->id : 0,
|
||||
.date = date,
|
||||
.postAuthor = !message.postAuthor.empty()
|
||||
? QString::fromStdString(message.postAuthor)
|
||||
: from
|
||||
? QString()
|
||||
: QString("unknown user: %1").arg(message.fromId),
|
||||
},
|
||||
std::move(text),
|
||||
MTP_messageMediaEmpty());
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
// Copyright @Radolyn, 2024
|
||||
#include "settings_ayu.h"
|
||||
|
||||
|
||||
#include "ayu/ayu_settings.h"
|
||||
#include "ayu/ui/boxes/edit_deleted_mark.h"
|
||||
#include "ayu/ui/boxes/edit_edited_mark.h"
|
||||
|
@ -508,7 +507,8 @@ 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);
|
||||
auto useScheduledMessagesVal = container->lifetime().make_state<rpl::variable<
|
||||
bool>>(settings->useScheduledMessages);
|
||||
|
||||
AddButtonWithIcon(
|
||||
container,
|
||||
|
@ -628,6 +628,29 @@ void SetupSpyEssentials(not_null<Ui::VerticalLayout*> container) {
|
|||
AyuSettings::save();
|
||||
},
|
||||
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) {
|
||||
|
|
|
@ -213,6 +213,19 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
|
|||
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
|
||||
|
||||
Session::Session(not_null<Main::Session*> session)
|
||||
|
@ -2549,25 +2562,23 @@ void Session::processMessagesDeleted(
|
|||
return;
|
||||
}
|
||||
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
|
||||
auto historiesToCheck = base::flat_set<not_null<History*>>();
|
||||
for (const auto &messageId : data) {
|
||||
const auto i = list ? list->find(messageId.v) : Messages::iterator();
|
||||
if (list && i != list->end()) {
|
||||
const auto history = i->second->history();
|
||||
|
||||
if (!settings->saveDeletedMessages) {
|
||||
if (!NeedSaveMessage(i->second)) {
|
||||
i->second->destroy();
|
||||
} else {
|
||||
i->second->setDeleted();
|
||||
AyuMessages::addDeletedMessage(i->second);
|
||||
}
|
||||
|
||||
if (!history->chatListMessageKnown() && !settings->saveDeletedMessages) {
|
||||
if (!history->chatListMessageKnown()) {
|
||||
historiesToCheck.emplace(history);
|
||||
}
|
||||
} else if (affected && !settings->saveDeletedMessages) {
|
||||
} else if (affected) {
|
||||
affected->unknownMessageDeleted(messageId.v);
|
||||
}
|
||||
}
|
||||
|
@ -2577,21 +2588,19 @@ void Session::processMessagesDeleted(
|
|||
}
|
||||
|
||||
void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
|
||||
auto historiesToCheck = base::flat_set<not_null<History*>>();
|
||||
for (const auto &messageId : data) {
|
||||
if (const auto item = nonChannelMessage(messageId.v)) {
|
||||
const auto history = item->history();
|
||||
|
||||
if (!settings->saveDeletedMessages) {
|
||||
if (!NeedSaveMessage(item)) {
|
||||
item->destroy();
|
||||
} else {
|
||||
item->setDeleted();
|
||||
AyuMessages::addDeletedMessage(item);
|
||||
}
|
||||
|
||||
if (!history->chatListMessageKnown() && !settings->saveDeletedMessages) {
|
||||
if (!history->chatListMessageKnown()) {
|
||||
historiesToCheck.emplace(history);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1359,7 +1359,7 @@ object_ptr<Ui::RpWidget> DetailsFiller::setupInfo() {
|
|||
|
||||
idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...)
|
||||
{
|
||||
const auto idText = IDString(peer);
|
||||
const auto idText = IDString(peer->forumTopicFor(topicRootId)->topicRootId());
|
||||
if (!idText.isEmpty()) {
|
||||
QGuiApplication::clipboard()->setText(idText);
|
||||
const auto msg = tr::ayu_IDCopiedToast(tr::now);
|
||||
|
|
|
@ -1431,7 +1431,7 @@ void Filler::fillHistoryActions() {
|
|||
addExportChat();
|
||||
addTranslate();
|
||||
addReport();
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _topic ? _topic : _thread, _controller, _addAction);
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
||||
addClearHistory();
|
||||
addDeleteChat();
|
||||
addLeaveChat();
|
||||
|
@ -1470,7 +1470,7 @@ void Filler::fillRepliesActions() {
|
|||
addCreatePoll();
|
||||
addToggleTopicClosed();
|
||||
addDeleteTopic();
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _topic ? _topic : _thread, _controller, _addAction);
|
||||
AyuUi::AddDeletedMessagesActions(_peer, _thread, _controller, _addAction);
|
||||
}
|
||||
|
||||
void Filler::fillScheduledActions() {
|
||||
|
|
Loading…
Add table
Reference in a new issue