diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 7b058e531..584750123 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1989,45 +1989,49 @@ void ApiWrap::applyUpdatesNoPtsCheck(const MTPUpdates &updates) { case mtpc_updateShortMessage: { auto &d = updates.c_updateShortMessage(); auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id; - App::histories().addNewMessage(MTP_message( - MTP_flags(flags), - d.vid, - d.is_out() ? MTP_int(Auth().userId()) : d.vuser_id, - MTP_peerUser(d.is_out() ? d.vuser_id : MTP_int(Auth().userId())), - d.vfwd_from, - d.vvia_bot_id, - d.vreply_to_msg_id, - d.vdate, - d.vmessage, - MTP_messageMediaEmpty(), - MTPnullMarkup, - d.has_entities() ? d.ventities : MTPnullEntities, - MTPint(), - MTPint(), - MTPstring(), - MTPlong()), NewMessageUnread); + App::histories().addNewMessage( + MTP_message( + MTP_flags(flags), + d.vid, + d.is_out() ? MTP_int(Auth().userId()) : d.vuser_id, + MTP_peerUser(d.is_out() ? d.vuser_id : MTP_int(Auth().userId())), + d.vfwd_from, + d.vvia_bot_id, + d.vreply_to_msg_id, + d.vdate, + d.vmessage, + MTP_messageMediaEmpty(), + MTPnullMarkup, + d.has_entities() ? d.ventities : MTPnullEntities, + MTPint(), + MTPint(), + MTPstring(), + MTPlong()), + NewMessageUnread); } break; case mtpc_updateShortChatMessage: { auto &d = updates.c_updateShortChatMessage(); auto flags = mtpCastFlags(d.vflags.v) | MTPDmessage::Flag::f_from_id; - App::histories().addNewMessage(MTP_message( - MTP_flags(flags), - d.vid, - d.vfrom_id, - MTP_peerChat(d.vchat_id), - d.vfwd_from, - d.vvia_bot_id, - d.vreply_to_msg_id, - d.vdate, - d.vmessage, - MTP_messageMediaEmpty(), - MTPnullMarkup, - d.has_entities() ? d.ventities : MTPnullEntities, - MTPint(), - MTPint(), - MTPstring(), - MTPlong()), NewMessageUnread); + App::histories().addNewMessage( + MTP_message( + MTP_flags(flags), + d.vid, + d.vfrom_id, + MTP_peerChat(d.vchat_id), + d.vfwd_from, + d.vvia_bot_id, + d.vreply_to_msg_id, + d.vdate, + d.vmessage, + MTP_messageMediaEmpty(), + MTPnullMarkup, + d.has_entities() ? d.ventities : MTPnullEntities, + MTPint(), + MTPint(), + MTPstring(), + MTPlong()), + NewMessageUnread); } break; case mtpc_updateShortSentMessage: { diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 250fc5f5b..6f8fadea5 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -904,26 +904,22 @@ namespace { if (m.has_from_id() && peerId == Auth().userPeerId()) { peerId = peerFromUser(m.vfrom_id); } - if (auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) { + if (const auto existing = App::histItemById(peerToChannel(peerId), m.vid.v)) { auto text = qs(m.vmessage); - auto entities = m.has_entities() ? TextUtilities::EntitiesFromMTP(m.ventities.v) : EntitiesInText(); + auto entities = m.has_entities() + ? TextUtilities::EntitiesFromMTP(m.ventities.v) + : EntitiesInText(); existing->setText({ text, entities }); existing->updateMedia(m.has_media() ? (&m.vmedia) : nullptr); - existing->updateReplyMarkup(m.has_reply_markup() ? (&m.vreply_markup) : nullptr); + existing->updateReplyMarkup(m.has_reply_markup() + ? (&m.vreply_markup) + : nullptr); existing->setViewsCount(m.has_views() ? m.vviews.v : -1); - existing->addToUnreadMentions(AddToUnreadMentionsMethod::New); - if (auto sharedMediaTypes = existing->sharedMediaTypes()) { - Auth().storage().add(Storage::SharedMediaAddNew( - peerId, - sharedMediaTypes, - existing->id)); - } - + existing->indexAsNewItem(); if (!existing->detached()) { App::checkSavedGif(existing); return true; } - return false; } return false; diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 79b4c891d..5225afda3 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -544,27 +544,6 @@ const QDateTime &ChannelHistory::maxReadMessageDate() { return _maxReadMessageDate; } -HistoryItem *ChannelHistory::addNewChannelMessage(const MTPMessage &msg, NewMessageType type) { - if (type == NewMessageExisting) return addToHistory(msg); - - return addNewToBlocks(msg, type); -} - -HistoryItem *ChannelHistory::addNewToBlocks(const MTPMessage &msg, NewMessageType type) { - if (!loadedAtBottom()) { - HistoryItem *item = addToHistory(msg); - if (item) { - setLastMessage(item); - if (type == NewMessageUnread) { - newItemAdded(item); - } - } - return item; - } - - return addNewToLastBlock(msg, type); -} - void ChannelHistory::cleared(bool leaveItems) { _joinedMessage = nullptr; } @@ -1115,28 +1094,26 @@ not_null History::addNewService(MsgId msgId, QDateTime date, const } HistoryItem *History::addNewMessage(const MTPMessage &msg, NewMessageType type) { - if (isChannel()) { - return asChannelHistory()->addNewChannelMessage(msg, type); - } - if (type == NewMessageExisting) { return addToHistory(msg); } if (!loadedAtBottom() || peer->migrateTo()) { - const auto item = addToHistory(msg); - if (item) { + if (const auto item = addToHistory(msg)) { setLastMessage(item); if (type == NewMessageUnread) { newItemAdded(item); } + return item; } - return item; + return nullptr; } return addNewToLastBlock(msg, type); } HistoryItem *History::addNewToLastBlock(const MTPMessage &msg, NewMessageType type) { + Expects(type != NewMessageExisting); + const auto applyServiceAction = (type == NewMessageUnread); const auto detachExistingItem = (type != NewMessageLast); const auto item = createItem(msg, applyServiceAction, detachExistingItem); @@ -1187,15 +1164,17 @@ void History::setUnreadMentionsCount(int count) { bool History::addToUnreadMentions( MsgId msgId, - AddToUnreadMentionsMethod method) { - auto allLoaded = _unreadMentionsCount ? (_unreadMentions.size() >= *_unreadMentionsCount) : false; + UnreadMentionType type) { + auto allLoaded = _unreadMentionsCount + ? (_unreadMentions.size() >= *_unreadMentionsCount) + : false; if (allLoaded) { - if (method == AddToUnreadMentionsMethod::New) { + if (type == UnreadMentionType::New) { ++*_unreadMentionsCount; _unreadMentions.insert(msgId); return true; } - } else if (!_unreadMentions.empty() && method != AddToUnreadMentionsMethod::New) { + } else if (!_unreadMentions.empty() && type != UnreadMentionType::New) { _unreadMentions.insert(msgId); return true; } @@ -1274,24 +1253,15 @@ not_null History::addNewItem(not_null adding, bool n if (groupFrom != groupTill || groupFrom->groupId()) { recountGrouping(groupFrom, groupTill); } - - if (IsServerMsgId(adding->id)) { - adding->addToUnreadMentions(AddToUnreadMentionsMethod::New); - if (auto sharedMediaTypes = adding->sharedMediaTypes()) { - if (newMsg) { - Auth().storage().add(Storage::SharedMediaAddNew( - peer->id, - sharedMediaTypes, - adding->id)); - } else { - auto from = loadedAtTop() ? 0 : minMsgId(); - auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId(); - Auth().storage().add(Storage::SharedMediaAddExisting( - peer->id, - sharedMediaTypes, - adding->id, - { from, till })); - } + if (!newMsg && IsServerMsgId(adding->id)) { + if (const auto sharedMediaTypes = adding->sharedMediaTypes()) { + auto from = loadedAtTop() ? 0 : minMsgId(); + auto till = loadedAtBottom() ? ServerMaxMsgId : maxMsgId(); + Auth().storage().add(Storage::SharedMediaAddExisting( + peer->id, + sharedMediaTypes, + adding->id, + { from, till })); } } if (adding->from()->id) { @@ -1399,8 +1369,9 @@ void History::clearSendAction(not_null from) { } } -void History::newItemAdded(HistoryItem *item) { +void History::newItemAdded(not_null item) { App::checkImageCacheSize(); + item->indexAsNewItem(); if (const auto from = item->from() ? item->from()->asUser() : nullptr) { if (from == item->author()) { clearSendAction(from); @@ -1409,7 +1380,9 @@ void History::newItemAdded(HistoryItem *item) { from->madeAction(itemServerTime.v); } if (item->out()) { - if (unreadBar) unreadBar->destroyUnreadBar(); + if (unreadBar) { + unreadBar->destroyUnreadBar(); + } if (!item->unread()) { outboxRead(item); } @@ -1599,7 +1572,7 @@ void History::addOlderSlice(const QVector &slice) { } for (auto i = block->items.size(); i > 0; --i) { auto item = block->items[i - 1]; - item->addToUnreadMentions(AddToUnreadMentionsMethod::Front); + item->addToUnreadMentions(UnreadMentionType::Existing); if (item->from()->id) { if (lastAuthors) { // chats if (auto user = item->from()->asUser()) { @@ -1768,9 +1741,9 @@ void History::checkAddAllToUnreadMentions() { return; } - for_const (auto block, blocks) { - for_const (auto item, block->items) { - item->addToUnreadMentions(AddToUnreadMentionsMethod::Back); + for (const auto block : blocks) { + for (const auto item : block->items) { + item->addToUnreadMentions(UnreadMentionType::Existing); } } } @@ -2417,11 +2390,11 @@ int History::resizeGetHeight(int newWidth) { } ChannelHistory *History::asChannelHistory() { - return isChannel() ? static_cast(this) : 0; + return isChannel() ? static_cast(this) : nullptr; } const ChannelHistory *History::asChannelHistory() const { - return isChannel() ? static_cast(this) : 0; + return isChannel() ? static_cast(this) : nullptr; } not_null History::migrateToOrMe() const { diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 74a7a64ac..afad9794c 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -173,10 +173,9 @@ struct Draft; class HistoryMedia; class HistoryMessage; -enum class AddToUnreadMentionsMethod { +enum class UnreadMentionType { New, // when new message is added to history - Front, // when old messages slice was received - Back, // when new messages slice was received and it is the last one, we index all media + Existing, // when some messages slice was received }; namespace Dialogs { @@ -234,7 +233,7 @@ public: void addOlderSlice(const QVector &slice); void addNewerSlice(const QVector &slice); - void newItemAdded(HistoryItem *item); + void newItemAdded(not_null item); int countUnread(MsgId upTo); void updateShowFrom(); @@ -369,7 +368,7 @@ public: return (getUnreadMentionsCount() > 0); } void setUnreadMentionsCount(int count); - bool addToUnreadMentions(MsgId msgId, AddToUnreadMentionsMethod method); + bool addToUnreadMentions(MsgId msgId, UnreadMentionType type); void eraseFromUnreadMentions(MsgId msgId); void addUnreadMentionsSlice(const MTPmessages_Messages &result); @@ -609,11 +608,8 @@ public: private: friend class History; - HistoryItem* addNewChannelMessage(const MTPMessage &msg, NewMessageType type); - HistoryItem *addNewToBlocks(const MTPMessage &msg, NewMessageType type); void checkMaxReadMessageDate(); - void cleared(bool leaveItems); QDateTime _maxReadMessageDate; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index ff357b21c..0ed83adea 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -350,6 +350,18 @@ Storage::SharedMediaTypesMask HistoryItem::sharedMediaTypes() const { return {}; } +void HistoryItem::indexAsNewItem() { + if (IsServerMsgId(id)) { + addToUnreadMentions(UnreadMentionType::New); + if (const auto types = sharedMediaTypes()) { + Auth().storage().add(Storage::SharedMediaAddNew( + history()->peer->id, + types, + id)); + } + } +} + void HistoryItem::previousItemChanged() { Expects(!isLogEntry()); recountDisplayDate(); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 4b984c136..e746437bf 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -303,9 +303,6 @@ public: bool isPost() const { return _flags & MTPDmessage::Flag::f_post; } - bool indexInUnreadMentions() const { - return (id > 0); - } bool isSilent() const { return _flags & MTPDmessage::Flag::f_silent; } @@ -349,11 +346,12 @@ public: virtual void updateReplyMarkup(const MTPReplyMarkup *markup) { } - virtual void addToUnreadMentions(AddToUnreadMentionsMethod method) { + virtual void addToUnreadMentions(UnreadMentionType type) { } virtual void eraseFromUnreadMentions() { } virtual Storage::SharedMediaTypesMask sharedMediaTypes() const; + void indexAsNewItem(); virtual bool hasBubble() const { return false; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 188bf0beb..7a4bab905 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1375,9 +1375,9 @@ void HistoryMessage::updateMedia(const MTPMessageMedia *media) { setPendingInitDimensions(); } -void HistoryMessage::addToUnreadMentions(AddToUnreadMentionsMethod method) { - if (indexInUnreadMentions() && mentionsMe() && isMediaUnread()) { - if (history()->addToUnreadMentions(id, method)) { +void HistoryMessage::addToUnreadMentions(UnreadMentionType type) { + if (IsServerMsgId(id) && mentionsMe() && isMediaUnread()) { + if (history()->addToUnreadMentions(id, type)) { Notify::peerUpdatedDelayed( history()->peer, Notify::PeerUpdate::Flag::UnreadMentionsChanged); diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 7c3e69421..9cfdb2fac 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -207,7 +207,7 @@ public: setReplyMarkup(markup); } - void addToUnreadMentions(AddToUnreadMentionsMethod method) override; + void addToUnreadMentions(UnreadMentionType type) override; void eraseFromUnreadMentions() override; Storage::SharedMediaTypesMask sharedMediaTypes() const override; diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp index e70076e60..87bf3bc0a 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp @@ -36,9 +36,17 @@ QString SendData::getLayoutDescription(const Result *owner) const { return owner->_description; } -void SendDataCommon::addToHistory(const Result *owner, History *history, -MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { +void SendDataCommon::addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const { auto fields = getSentMessageFields(); if (!fields.entities.v.isEmpty()) { flags |= MTPDmessage::Flag::f_entities; @@ -64,8 +72,10 @@ UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarku NewMessageUnread); } -QString SendDataCommon::getErrorOnSend(const Result *owner, History *history) const { - if (auto megagroup = history->peer->asMegagroup()) { +QString SendDataCommon::getErrorOnSend( + const Result *owner, + not_null history) const { + if (const auto megagroup = history->peer->asMegagroup()) { if (megagroup->restricted(ChannelRestriction::f_send_messages)) { return lang(lng_restricted_send_message); } @@ -101,7 +111,11 @@ SendDataCommon::SentMTPMessageFields SendVenue::getSentMessageFields() const { SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const { SentMTPMessageFields result; - result.media = MTP_messageMediaContact(MTP_string(_phoneNumber), MTP_string(_firstName), MTP_string(_lastName), MTP_int(0)); + result.media = MTP_messageMediaContact( + MTP_string(_phoneNumber), + MTP_string(_firstName), + MTP_string(_lastName), + MTP_int(0)); return result; } @@ -113,14 +127,34 @@ QString SendContact::getLayoutDescription(const Result *owner) const { return result; } -void SendPhoto::addToHistory(const Result *owner, History *history, -MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { - history->addNewPhoto(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _photo, _caption, markup); +void SendPhoto::addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const { + history->addNewPhoto( + msgId, + flags, + viaBotId, + replyToId, + date(mtpDate), + fromId, + postAuthor, + _photo, + _caption, + markup); } -QString SendPhoto::getErrorOnSend(const Result *owner, History *history) const { - if (auto megagroup = history->peer->asMegagroup()) { +QString SendPhoto::getErrorOnSend( + const Result *owner, + not_null history) const { + if (const auto megagroup = history->peer->asMegagroup()) { if (megagroup->restricted(ChannelRestriction::f_send_media)) { return lang(lng_restricted_send_media); } @@ -128,14 +162,34 @@ QString SendPhoto::getErrorOnSend(const Result *owner, History *history) const { return QString(); } -void SendFile::addToHistory(const Result *owner, History *history, -MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, -UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { - history->addNewDocument(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _document, _caption, markup); +void SendFile::addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const { + history->addNewDocument( + msgId, + flags, + viaBotId, + replyToId, + date(mtpDate), + fromId, + postAuthor, + _document, + _caption, + markup); } -QString SendFile::getErrorOnSend(const Result *owner, History *history) const { - if (auto megagroup = history->peer->asMegagroup()) { +QString SendFile::getErrorOnSend( + const Result *owner, + not_null history) const { + if (const auto megagroup = history->peer->asMegagroup()) { if (megagroup->restricted(ChannelRestriction::f_send_media)) { return lang(lng_restricted_send_media); } else if (megagroup->restricted(ChannelRestriction::f_send_stickers) @@ -150,13 +204,32 @@ QString SendFile::getErrorOnSend(const Result *owner, History *history) const { return QString(); } -void SendGame::addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const { - history->addNewGame(msgId, flags, viaBotId, replyToId, date(mtpDate), fromId, postAuthor, _game, markup); +void SendGame::addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const { + history->addNewGame( + msgId, + flags, + viaBotId, + replyToId, + date(mtpDate), + fromId, + postAuthor, + _game, + markup); } -QString SendGame::getErrorOnSend(const Result *owner, History *history) const { +QString SendGame::getErrorOnSend( + const Result *owner, + not_null history) const { if (auto megagroup = history->peer->asMegagroup()) { if (megagroup->restricted(ChannelRestriction::f_send_games)) { return lang(lng_restricted_send_inline); diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h index 62f77e6cd..48b54787c 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.h @@ -41,10 +41,20 @@ public: virtual bool isValid() const = 0; - virtual void addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const = 0; - virtual QString getErrorOnSend(const Result *owner, History *history) const = 0; + virtual void addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const = 0; + virtual QString getErrorOnSend( + const Result *owner, + not_null history) const = 0; virtual bool hasLocationCoords() const { return false; @@ -69,11 +79,21 @@ public: }; virtual SentMTPMessageFields getSentMessageFields() const = 0; - void addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; + void addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const override; - QString getErrorOnSend(const Result *owner, History *history) const override; + QString getErrorOnSend( + const Result *owner, + not_null history) const override; }; @@ -190,11 +210,21 @@ public: return _photo != nullptr; } - void addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; + void addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const override; - QString getErrorOnSend(const Result *owner, History *history) const override; + QString getErrorOnSend( + const Result *owner, + not_null history) const override; private: PhotoData *_photo; @@ -214,11 +244,21 @@ public: return _document != nullptr; } - void addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; + void addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const override; - QString getErrorOnSend(const Result *owner, History *history) const override; + QString getErrorOnSend( + const Result *owner, + not_null history) const override; private: DocumentData *_document; @@ -237,11 +277,21 @@ public: return _game != nullptr; } - void addToHistory(const Result *owner, History *history, - MTPDmessage::Flags flags, MsgId msgId, UserId fromId, MTPint mtpDate, - UserId viaBotId, MsgId replyToId, const QString &postAuthor, const MTPReplyMarkup &markup) const override; + void addToHistory( + const Result *owner, + not_null history, + MTPDmessage::Flags flags, + MsgId msgId, + UserId fromId, + MTPint mtpDate, + UserId viaBotId, + MsgId replyToId, + const QString &postAuthor, + const MTPReplyMarkup &markup) const override; - QString getErrorOnSend(const Result *owner, History *history) const override; + QString getErrorOnSend( + const Result *owner, + not_null history) const override; private: GameData *_game; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index b9dc239db..ee1bf2190 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2018,7 +2018,8 @@ void MainWidget::insertCheckedServiceNotification(const TextWithEntities &messag MTPint(), MTPint(), MTPstring(), - MTPlong()), NewMessageUnread); + MTPlong()), + NewMessageUnread); } if (item) { _history->peerMessagesUpdated(item->history()->peer->id); @@ -4825,7 +4826,8 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { QString text; App::histSentDataByItem(randomId, peerId, text); - auto wasAlready = peerId && (App::histItemById(peerToChannel(peerId), d.vid.v) != nullptr); + const auto wasAlready = (peerId != 0) + && (App::histItemById(peerToChannel(peerId), d.vid.v) != nullptr); feedUpdate(MTP_updateMessageID(d.vid, MTP_long(randomId))); // ignore real date if (peerId) { if (auto item = App::histItemById(peerToChannel(peerId), d.vid.v)) { @@ -4835,17 +4837,13 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { item->id, ApiWrap::RequestMessageDataCallback()); } - auto entities = d.has_entities() ? TextUtilities::EntitiesFromMTP(d.ventities.v) : EntitiesInText(); + const auto entities = d.has_entities() + ? TextUtilities::EntitiesFromMTP(d.ventities.v) + : EntitiesInText(); item->setText({ text, entities }); item->updateMedia(d.has_media() ? (&d.vmedia) : nullptr); - item->addToUnreadMentions(AddToUnreadMentionsMethod::New); if (!wasAlready) { - if (auto sharedMediaTypes = item->sharedMediaTypes()) { - Auth().storage().add(Storage::SharedMediaAddNew( - peerId, - sharedMediaTypes, - item->id)); - } + item->indexAsNewItem(); } } } diff --git a/Telegram/SourceFiles/storage/storage_shared_media.cpp b/Telegram/SourceFiles/storage/storage_shared_media.cpp index cfd442a41..09ffd1aa8 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.cpp +++ b/Telegram/SourceFiles/storage/storage_shared_media.cpp @@ -86,9 +86,9 @@ void SharedMedia::remove(SharedMediaRemoveOne &&query) { auto type = static_cast(index); if (query.types.test(type)) { peerIt->second[index].removeOne(query.messageId); - _oneRemoved.fire(std::move(query)); } } + _oneRemoved.fire(std::move(query)); } }