mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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() {
|
void Session::checkTTLs() {
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
|
||||||
_ttlCheckTimer.cancel();
|
_ttlCheckTimer.cancel();
|
||||||
const auto now = base::unixtime::now();
|
const auto now = base::unixtime::now();
|
||||||
while (!_ttlMessages.empty() && _ttlMessages.begin()->first <= 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();
|
scheduleNextTTLs();
|
||||||
}
|
}
|
||||||
|
@ -2436,7 +2443,15 @@ void Session::processMessagesDeleted(
|
||||||
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();
|
||||||
i->second->destroy();
|
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
if (!settings->saveDeletedMessages) {
|
||||||
|
i->second->destroy();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i->second->setAyuHint(settings->deletedMark);
|
||||||
|
}
|
||||||
|
|
||||||
if (!history->chatListMessageKnown()) {
|
if (!history->chatListMessageKnown()) {
|
||||||
historiesToCheck.emplace(history);
|
historiesToCheck.emplace(history);
|
||||||
}
|
}
|
||||||
|
@ -2454,7 +2469,15 @@ void Session::processNonChannelMessagesDeleted(const QVector<MTPint> &data) {
|
||||||
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();
|
||||||
item->destroy();
|
|
||||||
|
const auto settings = &AyuSettings::getInstance();
|
||||||
|
if (!settings->saveDeletedMessages) {
|
||||||
|
item->destroy();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item->setAyuHint(settings->deletedMark);
|
||||||
|
}
|
||||||
|
|
||||||
if (!history->chatListMessageKnown()) {
|
if (!history->chatListMessageKnown()) {
|
||||||
historiesToCheck.emplace(history);
|
historiesToCheck.emplace(history);
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,56 +481,6 @@ not_null<HistoryItem*> History::insertItem(
|
||||||
void History::destroyMessage(not_null<HistoryItem*> item) {
|
void History::destroyMessage(not_null<HistoryItem*> item) {
|
||||||
Expects(item->isHistoryEntry() || !item->mainView());
|
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;
|
const auto peerId = peer->id;
|
||||||
if (item->isHistoryEntry()) {
|
if (item->isHistoryEntry()) {
|
||||||
// All this must be done for all items manually in History::clear()!
|
// 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) {
|
void HistoryItem::setAyuHint(const QString &hint) {
|
||||||
const auto settings = &AyuSettings::getInstance();
|
try {
|
||||||
if (!(_flags & MessageFlag::HasPostAuthor))
|
const auto settings = &AyuSettings::getInstance();
|
||||||
{
|
if (!(_flags & MessageFlag::HasPostAuthor)) {
|
||||||
_flags |= MessageFlag::HasPostAuthor;
|
_flags |= MessageFlag::HasPostAuthor;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto msgsigned = Get<HistoryMessageSigned>();
|
auto msgsigned = Get<HistoryMessageSigned>();
|
||||||
if (hint.isEmpty()) {
|
if (hint.isEmpty()) {
|
||||||
if (!msgsigned) {
|
if (!msgsigned) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RemoveComponents(HistoryMessageSigned::Bit());
|
||||||
|
history()->owner().requestItemResize(this);
|
||||||
return;
|
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);
|
if (!isService()) {
|
||||||
history()->owner().requestItemResize(this);
|
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) {
|
void HistoryItem::setReplies(HistoryMessageRepliesData &&data) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue