| 47 | } |
| 48 | |
| 49 | void TopicsView::prepare(MsgId frontRootId, Fn<void()> customEmojiRepaint) { |
| 50 | Expects(_forum != nullptr); |
| 51 | |
| 52 | const auto &list = _forum->recentTopics(); |
| 53 | _version = _forum->recentTopicsListVersion(); |
| 54 | _titles.reserve(list.size()); |
| 55 | auto index = 0; |
| 56 | for (const auto &topic : list) { |
| 57 | const auto from = begin(_titles) + index; |
| 58 | const auto key = topic->rootId().bare; |
| 59 | const auto i = ranges::find( |
| 60 | from, |
| 61 | end(_titles), |
| 62 | key, |
| 63 | &Title::key); |
| 64 | if (i != end(_titles)) { |
| 65 | if (i != from) { |
| 66 | ranges::rotate(from, i, i + 1); |
| 67 | } |
| 68 | } else if (index >= _titles.size()) { |
| 69 | _titles.emplace_back(); |
| 70 | } |
| 71 | auto &title = _titles[index++]; |
| 72 | const auto unread = topic->chatListBadgesState().unread; |
| 73 | if (title.key == key |
| 74 | && title.unread == unread |
| 75 | && title.version == topic->titleVersion()) { |
| 76 | continue; |
| 77 | } |
| 78 | const auto context = Core::TextContext({ |
| 79 | .session = &topic->session(), |
| 80 | .repaint = customEmojiRepaint, |
| 81 | .customEmojiLoopLimit = kIconLoopCount, |
| 82 | }); |
| 83 | auto topicTitle = topic->titleWithIcon(); |
| 84 | title.key = key; |
| 85 | title.version = topic->titleVersion(); |
| 86 | title.unread = unread; |
| 87 | title.title.setMarkedText( |
| 88 | st::dialogsTextStyle, |
| 89 | (unread |
| 90 | ? Ui::Text::Colorized( |
| 91 | Ui::Text::Wrapped( |
| 92 | std::move(topicTitle), |
| 93 | EntityType::Bold)) |
| 94 | : std::move(topicTitle)), |
| 95 | DialogTextOptions(), |
| 96 | context); |
| 97 | } |
| 98 | while (_titles.size() > index) { |
| 99 | _titles.pop_back(); |
| 100 | } |
| 101 | const auto i = frontRootId |
| 102 | ? ranges::find(_titles, frontRootId.bare, &Title::key) |
| 103 | : end(_titles); |
| 104 | _jumpToTopic = (i != end(_titles)); |
| 105 | if (_jumpToTopic) { |
| 106 | if (i != begin(_titles)) { |
nothing calls this directly
no test coverage detected