diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 67e1a52e2..1185501f0 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -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 &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); } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index a77b0ed6e..3e998600b 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -481,56 +481,6 @@ not_null History::insertItem( void History::destroyMessage(not_null 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()! diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 4f8672f3f..16bc9a674 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -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(); - if (hint.isEmpty()) { - if (!msgsigned) { + auto msgsigned = Get(); + 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(); - } 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(); + } + else if (msgsigned->postAuthor == hint) { + return; + } + msgsigned->postAuthor = hint; + msgsigned->isAnonymousRank = !isDiscussionPost() + && this->author()->isMegagroup(); + } + else { + const auto data = Get(); + 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) {