From 5c3f93eee17a2afbec7c7806b636b6d92949922d Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Apr 2019 12:04:42 +0400 Subject: [PATCH] Fix crash in replies. Regression was introduced in b1df3c0ec4. --- Telegram/SourceFiles/data/data_session.cpp | 51 ++++++++----------- Telegram/SourceFiles/data/data_session.h | 2 +- Telegram/SourceFiles/history/history_item.cpp | 4 +- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 33c449d8a5..0fd45d0650 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1210,11 +1210,6 @@ rpl::producer> Session::animationPlayInlineRequest() cons return _animationPlayInlineRequest.events(); } -void Session::notifyItemRemoved(not_null item) { - _itemRemoved.fire_copy(item); - groups().unregisterMessage(item); -} - rpl::producer> Session::itemRemoved() const { return _itemRemoved.events(); } @@ -1646,16 +1641,30 @@ void Session::processMessagesDeleted( } } +void Session::removeDependencyMessage(not_null item) { + const auto i = _dependentMessages.find(item); + if (i == end(_dependentMessages)) { + return; + } + const auto items = std::move(i->second); + _dependentMessages.erase(i); + + for (const auto dependent : items) { + dependent->dependencyItemRemoved(item); + } +} + void Session::destroyMessage(not_null item) { Expects(!item->isLogEntry() || !item->mainView()); + const auto peerId = item->history()->peer->id; if (!item->isLogEntry()) { // All this must be done for all items manually in History::clear()! item->eraseFromUnreadMentions(); if (IsServerMsgId(item->id)) { if (const auto types = item->sharedMediaTypes()) { session().storage().remove(Storage::SharedMediaRemoveOne( - item->history()->peer->id, + peerId, types, item->id)); } @@ -1664,7 +1673,12 @@ void Session::destroyMessage(not_null item) { } item->history()->itemRemoved(item); } - const auto list = messagesListForInsert(item->history()->channelId()); + _itemRemoved.fire_copy(item); + groups().unregisterMessage(item); + removeDependencyMessage(item); + session().notifications().clearFromItem(item); + + const auto list = messagesListForInsert(peerToChannel(peerId)); list->erase(item->id); } @@ -1692,29 +1706,6 @@ HistoryItem *Session::message(FullMsgId itemId) const { return message(itemId.channel, itemId.msg); } -//void historyUnregItem(not_null item) { -// const auto data = fetchMsgsData(item->channelId(), false); -// if (!data) return; -// -// const auto i = data->find(item->id); -// if (i != data->cend()) { -// if (i.value() == item) { -// data->erase(i); -// } -// } -// const auto j = ::dependentItems.find(item); -// if (j != ::dependentItems.cend()) { -// DependentItemsSet items; -// std::swap(items, j.value()); -// ::dependentItems.erase(j); -// -// for_const (auto dependent, items) { -// dependent->dependencyItemRemoved(item); -// } -// } -// item->history()->session().notifications().clearFromItem(item); -//} - void Session::updateDependentMessages(not_null item) { const auto i = _dependentMessages.find(item); if (i != end(_dependentMessages)) { diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 355a4261dd..a6740c2d09 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -189,7 +189,6 @@ public: void notifyHistoryUnloaded(not_null history); [[nodiscard]] rpl::producer> historyUnloaded() const; - void notifyItemRemoved(not_null item); [[nodiscard]] rpl::producer> itemRemoved() const; void notifyViewRemoved(not_null view); [[nodiscard]] rpl::producer> viewRemoved() const; @@ -677,6 +676,7 @@ private: not_null messagesListForInsert(ChannelId channelId); HistoryItem *registerMessage(std::unique_ptr item); void changeMessageId(ChannelId channel, MsgId wasId, MsgId nowId); + void removeDependencyMessage(not_null item); void photoApplyFields( not_null photo, diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 743030d715..07c83fc056 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -736,9 +736,7 @@ void HistoryItem::drawInDialog( p.restoreTextPalette(); } -HistoryItem::~HistoryItem() { - _history->owner().notifyItemRemoved(this); -} +HistoryItem::~HistoryItem() = default; QDateTime ItemDateTime(not_null item) { return ParseDateTime(item->date());