mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-02 07:25:46 +00:00
Display jump to last topic message bubble.
This commit is contained in:
@@ -16,6 +16,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "storage/storage_facade.h"
|
||||
#include "core/application.h"
|
||||
@@ -33,9 +35,67 @@ namespace {
|
||||
constexpr auto kLoadedChatsMinCount = 20;
|
||||
constexpr auto kShowChatNamesCount = 8;
|
||||
|
||||
[[nodiscard]] TextWithEntities ComposeFolderListEntryText(
|
||||
not_null<Folder*> folder) {
|
||||
const auto &list = folder->lastHistories();
|
||||
if (list.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto count = std::max(
|
||||
int(list.size()),
|
||||
folder->chatsList()->fullSize().current());
|
||||
|
||||
const auto throwAwayLastName = (list.size() > 1)
|
||||
&& (count == list.size() + 1);
|
||||
auto &&peers = ranges::views::all(
|
||||
list
|
||||
) | ranges::views::take(
|
||||
list.size() - (throwAwayLastName ? 1 : 0)
|
||||
);
|
||||
const auto wrapName = [](not_null<History*> history) {
|
||||
const auto name = history->peer->name();
|
||||
return TextWithEntities{
|
||||
.text = name,
|
||||
.entities = (history->chatListBadgesState().unread
|
||||
? EntitiesInText{
|
||||
{ EntityType::Semibold, 0, int(name.size()), QString() },
|
||||
{ EntityType::PlainLink, 0, int(name.size()), QString() },
|
||||
}
|
||||
: EntitiesInText{}),
|
||||
};
|
||||
};
|
||||
const auto shown = int(peers.size());
|
||||
const auto accumulated = [&] {
|
||||
Expects(shown > 0);
|
||||
|
||||
auto i = peers.begin();
|
||||
auto result = wrapName(*i);
|
||||
for (++i; i != peers.end(); ++i) {
|
||||
result = tr::lng_archived_last_list(
|
||||
tr::now,
|
||||
lt_accumulated,
|
||||
result,
|
||||
lt_chat,
|
||||
wrapName(*i),
|
||||
Ui::Text::WithEntities);
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
return (shown < count)
|
||||
? tr::lng_archived_last(
|
||||
tr::now,
|
||||
lt_count,
|
||||
(count - shown),
|
||||
lt_chats,
|
||||
accumulated,
|
||||
Ui::Text::WithEntities)
|
||||
: accumulated;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Folder::Folder(not_null<Data::Session*> owner, FolderId id)
|
||||
Folder::Folder(not_null<Session*> owner, FolderId id)
|
||||
: Entry(owner, Type::Folder)
|
||||
, _id(id)
|
||||
, _chatsList(
|
||||
@@ -76,29 +136,6 @@ FolderId Folder::id() const {
|
||||
|
||||
void Folder::indexNameParts() {
|
||||
// We don't want archive to be filtered in the chats list.
|
||||
//_nameWords.clear();
|
||||
//_nameFirstLetters.clear();
|
||||
//auto toIndexList = QStringList();
|
||||
//auto appendToIndex = [&](const QString &value) {
|
||||
// if (!value.isEmpty()) {
|
||||
// toIndexList.push_back(TextUtilities::RemoveAccents(value));
|
||||
// }
|
||||
//};
|
||||
|
||||
//appendToIndex(_name);
|
||||
//const auto appendTranslit = !toIndexList.isEmpty()
|
||||
// && cRussianLetters().match(toIndexList.front()).hasMatch();
|
||||
//if (appendTranslit) {
|
||||
// appendToIndex(translitRusEng(toIndexList.front()));
|
||||
//}
|
||||
//auto toIndex = toIndexList.join(' ');
|
||||
//toIndex += ' ' + rusKeyboardLayoutSwitch(toIndex);
|
||||
|
||||
//const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
|
||||
//for (const auto &name : namesList) {
|
||||
// _nameWords.insert(name);
|
||||
// _nameFirstLetters.insert(name[0]);
|
||||
//}
|
||||
}
|
||||
|
||||
void Folder::registerOne(not_null<History*> history) {
|
||||
@@ -110,7 +147,6 @@ void Folder::registerOne(not_null<History*> history) {
|
||||
} else {
|
||||
updateChatListEntry();
|
||||
}
|
||||
applyChatListMessage(history->chatListMessage());
|
||||
reorderLastHistories();
|
||||
}
|
||||
|
||||
@@ -118,9 +154,6 @@ void Folder::unregisterOne(not_null<History*> history) {
|
||||
if (_chatsList.empty()) {
|
||||
updateChatListExistence();
|
||||
}
|
||||
if (_chatListMessage && _chatListMessage->history() == history) {
|
||||
computeChatListMessage();
|
||||
}
|
||||
reorderLastHistories();
|
||||
}
|
||||
|
||||
@@ -129,47 +162,11 @@ int Folder::chatListNameVersion() const {
|
||||
}
|
||||
|
||||
void Folder::oneListMessageChanged(HistoryItem *from, HistoryItem *to) {
|
||||
if (!applyChatListMessage(to) && _chatListMessage == from) {
|
||||
computeChatListMessage();
|
||||
}
|
||||
if (from || to) {
|
||||
reorderLastHistories();
|
||||
}
|
||||
}
|
||||
|
||||
bool Folder::applyChatListMessage(HistoryItem *item) {
|
||||
if (!item) {
|
||||
return false;
|
||||
} else if (_chatListMessage
|
||||
&& _chatListMessage->date() >= item->date()) {
|
||||
return false;
|
||||
}
|
||||
_chatListMessage = item;
|
||||
updateChatListEntry();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Folder::computeChatListMessage() {
|
||||
auto &&items = ranges::views::all(
|
||||
*_chatsList.indexed()
|
||||
) | ranges::views::filter([](not_null<Dialogs::Row*> row) {
|
||||
return row->entry()->chatListMessage() != nullptr;
|
||||
});
|
||||
const auto chatListDate = [](not_null<Dialogs::Row*> row) {
|
||||
return row->entry()->chatListMessage()->date();
|
||||
};
|
||||
const auto top = ranges::max_element(
|
||||
items,
|
||||
ranges::less(),
|
||||
chatListDate);
|
||||
if (top == items.end()) {
|
||||
_chatListMessage = nullptr;
|
||||
} else {
|
||||
_chatListMessage = (*top)->entry()->chatListMessage();
|
||||
}
|
||||
updateChatListEntry();
|
||||
}
|
||||
|
||||
void Folder::reorderLastHistories() {
|
||||
// We want first kShowChatNamesCount histories, by last message date.
|
||||
const auto pred = [](not_null<History*> a, not_null<History*> b) {
|
||||
@@ -219,7 +216,7 @@ void Folder::loadUserpic() {
|
||||
|
||||
void Folder::paintUserpic(
|
||||
Painter &p,
|
||||
std::shared_ptr<Data::CloudImageView> &view,
|
||||
std::shared_ptr<CloudImageView> &view,
|
||||
const Dialogs::Ui::PaintContext &context) const {
|
||||
paintUserpic(
|
||||
p,
|
||||
@@ -288,8 +285,16 @@ const std::vector<not_null<History*>> &Folder::lastHistories() const {
|
||||
return _lastHistories;
|
||||
}
|
||||
|
||||
uint32 Folder::chatListViewVersion() const {
|
||||
return _chatListViewVersion;
|
||||
void Folder::validateListEntryCache() {
|
||||
if (_listEntryCacheVersion == _chatListViewVersion) {
|
||||
return;
|
||||
}
|
||||
_listEntryCacheVersion = _chatListViewVersion;
|
||||
_listEntryCache.setMarkedText(
|
||||
st::dialogsTextStyle,
|
||||
ComposeFolderListEntryText(this),
|
||||
// Use rich options as long as the entry text does not have user text.
|
||||
Ui::ItemTextDefaultOptions());
|
||||
}
|
||||
|
||||
void Folder::requestChatListMessage() {
|
||||
@@ -299,7 +304,7 @@ void Folder::requestChatListMessage() {
|
||||
}
|
||||
|
||||
TimeId Folder::adjustedChatListTimeId() const {
|
||||
return _chatListMessage ? _chatListMessage->date() : chatListTimeId();
|
||||
return chatListTimeId();
|
||||
}
|
||||
|
||||
void Folder::applyDialog(const MTPDdialogFolder &data) {
|
||||
@@ -350,7 +355,7 @@ Dialogs::BadgesState Folder::chatListBadgesState() const {
|
||||
}
|
||||
|
||||
HistoryItem *Folder::chatListMessage() const {
|
||||
return _chatListMessage;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Folder::chatListMessageKnown() const {
|
||||
|
Reference in New Issue
Block a user