mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
feat: try to rework saveDeletedMessages
This commit is contained in:
parent
fa8124cc1b
commit
c408c5fb87
3 changed files with 64 additions and 76 deletions
|
@ -2414,10 +2414,17 @@ void Session::unregisterMessageTTL(
|
|||
}
|
||||
|
||||
void Session::checkTTLs() {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
|
||||
_ttlCheckTimer.cancel();
|
||||
const auto now = base::unixtime::now();
|
||||
while (!_ttlMessages.empty() && _ttlMessages.begin()->first <= now) {
|
||||
_ttlMessages.begin()->second.front()->destroy();
|
||||
if (!settings->saveDeletedMessages) {
|
||||
_ttlMessages.begin()->second.front()->destroy();
|
||||
}
|
||||
else {
|
||||
_ttlMessages.begin()->second.front()->setAyuHint(settings->deletedMark);
|
||||
}
|
||||
}
|
||||
scheduleNextTTLs();
|
||||
}
|
||||
|
@ -2436,7 +2443,15 @@ void Session::processMessagesDeleted(
|
|||
const auto i = list ? list->find(messageId.v) : Messages::iterator();
|
||||
if (list && i != list->end()) {
|
||||
const auto history = i->second->history();
|
||||
i->second->destroy();
|
||||
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (!settings->saveDeletedMessages) {
|
||||
i->second->destroy();
|
||||
}
|
||||
else {
|
||||
i->second->setAyuHint(settings->deletedMark);
|
||||
}
|
||||
|
||||
if (!history->chatListMessageKnown()) {
|
||||
historiesToCheck.emplace(history);
|
||||
}
|
||||
|
@ -2454,7 +2469,15 @@ void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) {
|
|||
for (const auto &messageId : data) {
|
||||
if (const auto item = nonChannelMessage(messageId.v)) {
|
||||
const auto history = item->history();
|
||||
item->destroy();
|
||||
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (!settings->saveDeletedMessages) {
|
||||
item->destroy();
|
||||
}
|
||||
else {
|
||||
item->setAyuHint(settings->deletedMark);
|
||||
}
|
||||
|
||||
if (!history->chatListMessageKnown()) {
|
||||
historiesToCheck.emplace(history);
|
||||
}
|
||||
|
|
|
@ -481,56 +481,6 @@ not_null<HistoryItem*> History::insertItem(
|
|||
void History::destroyMessage(not_null<HistoryItem*> item) {
|
||||
Expects(item->isHistoryEntry() || !item->mainView());
|
||||
|
||||
// AyuGram saveDeletedMessages
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (settings->saveDeletedMessages && item->isRegular() && !item->isGroupMigrate()) {
|
||||
if (!item->isService()) {
|
||||
item->setAyuHint(settings->deletedMark);
|
||||
}
|
||||
else {
|
||||
const auto msg = TextWithEntities{
|
||||
"Message deleted",
|
||||
{
|
||||
EntityInText(
|
||||
EntityType::Italic,
|
||||
0,
|
||||
15,
|
||||
"Message deleted"
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
auto flags = MessageFlag::HasFromId
|
||||
| MessageFlag::HasReplyInfo
|
||||
| MessageFlag::HasPostAuthor;
|
||||
|
||||
if (item->isPost()) {
|
||||
flags |= MessageFlag::Post;
|
||||
}
|
||||
|
||||
FullReplyTo replyTo = {
|
||||
.messageId = item->fullId(),
|
||||
.storyId = {},
|
||||
.topicRootId = item->topicRootId(),
|
||||
};
|
||||
|
||||
addNewLocalMessage(
|
||||
session().data().nextLocalMessageId(),
|
||||
flags,
|
||||
UserId(),
|
||||
replyTo,
|
||||
base::unixtime::now(),
|
||||
item->author()->id,
|
||||
"AyuGram"_q,
|
||||
msg,
|
||||
MTP_messageMediaEmpty(),
|
||||
HistoryMessageMarkupData(),
|
||||
uint64(0));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const auto peerId = peer->id;
|
||||
if (item->isHistoryEntry()) {
|
||||
// All this must be done for all items manually in History::clear()!
|
||||
|
|
|
@ -2630,33 +2630,48 @@ void HistoryItem::setPostAuthor(const QString &postAuthor) {
|
|||
}
|
||||
|
||||
void HistoryItem::setAyuHint(const QString &hint) {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (!(_flags & MessageFlag::HasPostAuthor))
|
||||
{
|
||||
_flags |= MessageFlag::HasPostAuthor;
|
||||
}
|
||||
try {
|
||||
const auto settings = &AyuSettings::getInstance();
|
||||
if (!(_flags & MessageFlag::HasPostAuthor)) {
|
||||
_flags |= MessageFlag::HasPostAuthor;
|
||||
}
|
||||
|
||||
auto msgsigned = Get<HistoryMessageSigned>();
|
||||
if (hint.isEmpty()) {
|
||||
if (!msgsigned) {
|
||||
auto msgsigned = Get<HistoryMessageSigned>();
|
||||
if (hint.isEmpty()) {
|
||||
if (!msgsigned) {
|
||||
return;
|
||||
}
|
||||
RemoveComponents(HistoryMessageSigned::Bit());
|
||||
history()->owner().requestItemResize(this);
|
||||
return;
|
||||
}
|
||||
RemoveComponents(HistoryMessageSigned::Bit());
|
||||
history()->owner().requestItemResize(this);
|
||||
return;
|
||||
}
|
||||
if (!msgsigned) {
|
||||
AddComponents(HistoryMessageSigned::Bit());
|
||||
msgsigned = Get<HistoryMessageSigned>();
|
||||
} else if (msgsigned->postAuthor == hint) {
|
||||
return;
|
||||
}
|
||||
msgsigned->postAuthor = hint;
|
||||
msgsigned->isAnonymousRank = !isDiscussionPost()
|
||||
&& this->author()->isMegagroup();
|
||||
|
||||
history()->owner().requestItemViewRefresh(this);
|
||||
history()->owner().requestItemResize(this);
|
||||
if (!isService()) {
|
||||
if (!msgsigned) {
|
||||
AddComponents(HistoryMessageSigned::Bit());
|
||||
msgsigned = Get<HistoryMessageSigned>();
|
||||
}
|
||||
else if (msgsigned->postAuthor == hint) {
|
||||
return;
|
||||
}
|
||||
msgsigned->postAuthor = hint;
|
||||
msgsigned->isAnonymousRank = !isDiscussionPost()
|
||||
&& this->author()->isMegagroup();
|
||||
}
|
||||
else {
|
||||
const auto data = Get<HistoryServiceData>();
|
||||
auto prepared = PreparedServiceText{
|
||||
.text = _text.append(" ").append(hint),
|
||||
.links = data->textLinks
|
||||
};
|
||||
setServiceText(std::move(prepared));
|
||||
}
|
||||
|
||||
history()->owner().requestItemViewRefresh(this);
|
||||
history()->owner().requestItemResize(this);
|
||||
} catch (...) {
|
||||
LOG(("AyuGram: crash in setting hint"));
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::setReplies(HistoryMessageRepliesData &&data) {
|
||||
|
|
Loading…
Add table
Reference in a new issue