diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index 422476289..852c00c3a 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -337,6 +337,7 @@ void EditForumTopicBox( const auto topic = (!creating && forum->peer->forum()) ? forum->peer->forum()->topicFor(rootId) : nullptr; + const auto created = topic && !topic->creating(); box->setTitle(creating ? tr::lng_forum_topic_new() : tr::lng_forum_topic_edit()); @@ -394,7 +395,7 @@ void EditForumTopicBox( ) | rpl::start_with_next([=](DocumentId iconId) { icon->setAttribute( Qt::WA_TransparentForMouseEvents, - !creating || (iconId != 0)); + created || (iconId != 0)); }, box->lifetime()); icon->setClickedCallback([=] { diff --git a/Telegram/SourceFiles/data/data_forum_topic.cpp b/Telegram/SourceFiles/data/data_forum_topic.cpp index b69926a9f..a8922b65a 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.cpp +++ b/Telegram/SourceFiles/data/data_forum_topic.cpp @@ -388,7 +388,9 @@ void ForumTopic::setLastServerMessage(HistoryItem *item) { if (_lastMessage && *_lastMessage && !(*_lastMessage)->isRegular() - && (!item || (*_lastMessage)->date() > item->date())) { + && (!item + || (*_lastMessage)->date() > item->date() + || (*_lastMessage)->isSending())) { return; } setLastMessage(item); @@ -566,7 +568,11 @@ void ForumTopic::applyColorId(int32 colorId) { } void ForumTopic::applyItemAdded(not_null item) { - setLastMessage(item); + if (item->isRegular()) { + setLastServerMessage(item); + } else { + setLastMessage(item); + } } void ForumTopic::maybeSetLastMessage(not_null item) { diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index 665e9030c..caace2997 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -946,11 +946,11 @@ void Histories::checkTopicCreated(FullMsgId rootId, MsgId realRoot) { _createdTopicIds.emplace(rootId, realRoot); - if (const auto forum = _owner->peer(rootId.peer)->forum()) { + const auto history = _owner->history(rootId.peer); + if (const auto forum = history->peer->forum()) { forum->created(rootId.msg, realRoot); } - const auto history = _owner->history(rootId.peer); for (auto &entry : scheduled) { _creatingTopicRequests.erase(entry.requestId); sendPreparedMessage( @@ -962,6 +962,7 @@ void Histories::checkTopicCreated(FullMsgId rootId, MsgId realRoot) { std::move(entry.done), std::move(entry.fail)); } + const auto topic = history->peer->forumTopicFor(realRoot); for (const auto &item : history->clientSideMessages()) { const auto replace = [&](MsgId nowId) { return (nowId == rootId.msg) ? realRoot : nowId; diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 8d038aac7..c3e68a8f3 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -131,7 +131,7 @@ rpl::producer RepliesList::source( _history->session().changes().historyUpdates( _history, - Data::HistoryUpdate::Flag::ClientSideMessages + HistoryUpdate::Flag::ClientSideMessages ) | rpl::start_with_next(pushDelayed, lifetime); _history->session().changes().messageUpdates( @@ -744,7 +744,7 @@ void RepliesList::setOutboxReadTill(MsgId readTillId) { _outboxReadTillId = newReadTillId; _history->session().changes().historyUpdated( _history, - Data::HistoryUpdate::Flag::OutboxRead); + HistoryUpdate::Flag::OutboxRead); } } @@ -792,7 +792,7 @@ std::optional RepliesList::computeUnreadCountLocally( const auto wasUnreadCountAfter = _unreadCount.current(); const auto readTillId = std::max(afterId, _rootId); - const auto wasReadTillId = std::max(_inboxReadTillId, _rootId); + const auto wasReadTillId = _inboxReadTillId; const auto backLoaded = (_skippedBefore == 0); const auto frontLoaded = (_skippedAfter == 0); const auto fullLoaded = backLoaded && frontLoaded; @@ -838,7 +838,7 @@ std::optional RepliesList::computeUnreadCountLocally( end(_list), wasReadTillId, std::greater<>()); - return std::max(*wasUnreadCountAfter - countIncoming(from, till), 0); + return std::max(*wasUnreadCountAfter - (till - from), 0); } return std::nullopt; } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index fe62d0bb0..c7eed9029 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1079,7 +1079,8 @@ bool HistoryItem::computeDropForwardedInfo() const { } bool HistoryItem::inThread(MsgId rootId) const { - return (replyToTop() == rootId); + return (replyToTop() == rootId) + || (topicRootId() == rootId); } not_null HistoryItem::author() const { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 1464ecfe2..023b4b782 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -661,7 +661,7 @@ void HistoryMessage::createComponentsHelper( const auto forum = history()->peer->forum(); config.replyIsTopicPost = LookupReplyIsTopicPost(to) || (to && to->Has()) - || (forum && forum->creating(replyToTop)); + || (forum && forum->creating(config.replyToTop)); } config.markup = std::move(markup); if (flags & MessageFlag::HasPostAuthor) config.author = postAuthor; @@ -1813,8 +1813,7 @@ void HistoryMessage::changeReplyToTopCounter( int delta) { if (!isRegular() || !_history->peer->isMegagroup()) { return; - } - if (!out() && delta > 0) { + } else if (delta > 0) { _history->session().changes().messageUpdated( this, Data::MessageUpdate::Flag::ReplyToTopAdded);