mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Use "Feed" name for chats list index and search.
This commit is contained in:
@@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "dialogs/dialogs_key.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
||||
namespace Data {
|
||||
|
||||
@@ -24,7 +25,35 @@ MessagePosition FeedPositionFromMTP(const MTPFeedPosition &position) {
|
||||
|
||||
Feed::Feed(FeedId id)
|
||||
: Entry(this)
|
||||
, _id(id) {
|
||||
, _id(id)
|
||||
, _name(lang(lng_feed_name)) {
|
||||
indexNameParts();
|
||||
}
|
||||
|
||||
void Feed::indexNameParts() {
|
||||
_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 Feed::registerOne(not_null<ChannelData*> channel) {
|
||||
|
@@ -53,6 +53,16 @@ public:
|
||||
HistoryItem *chatsListItem() const override {
|
||||
return _lastMessage;
|
||||
}
|
||||
const QString &chatsListName() const override {
|
||||
return _name;
|
||||
}
|
||||
const base::flat_set<QString> &chatsListNameWords() const override {
|
||||
return _nameWords;
|
||||
}
|
||||
const base::flat_set<QChar> &chatsListFirstLetters() const override {
|
||||
return _nameFirstLetters;
|
||||
}
|
||||
|
||||
void loadUserpic() override;
|
||||
void paintUserpic(
|
||||
Painter &p,
|
||||
@@ -61,12 +71,16 @@ public:
|
||||
int size) const override;
|
||||
|
||||
private:
|
||||
void indexNameParts();
|
||||
void recountLastMessage();
|
||||
bool justSetLastMessage(not_null<HistoryItem*> item);
|
||||
|
||||
FeedId _id = 0;
|
||||
std::vector<not_null<History*>> _channels;
|
||||
|
||||
QString _name;
|
||||
base::flat_set<QString> _nameWords;
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
HistoryItem *_lastMessage = nullptr;
|
||||
|
||||
rpl::variable<MessagePosition> _unreadPosition;
|
||||
|
@@ -121,7 +121,7 @@ void PeerData::updateNameDelayed(
|
||||
|
||||
Notify::PeerUpdate update(this);
|
||||
update.flags |= UpdateFlag::NameChanged;
|
||||
update.oldNameFirstChars = nameFirstChars();
|
||||
update.oldNameFirstLetters = nameFirstLetters();
|
||||
|
||||
if (isUser()) {
|
||||
if (asUser()->username != newUsername) {
|
||||
@@ -304,7 +304,7 @@ void PeerData::setUserpicChecked(
|
||||
|
||||
void PeerData::fillNames() {
|
||||
_nameWords.clear();
|
||||
_nameFirstChars.clear();
|
||||
_nameFirstLetters.clear();
|
||||
auto toIndexList = QStringList();
|
||||
auto appendToIndex = [&](const QString &value) {
|
||||
if (!value.isEmpty()) {
|
||||
@@ -318,7 +318,7 @@ void PeerData::fillNames() {
|
||||
if (appendTranslit) {
|
||||
appendToIndex(translitRusEng(toIndexList.front()));
|
||||
}
|
||||
if (auto user = asUser()) {
|
||||
if (const auto user = asUser()) {
|
||||
if (user->nameOrPhone != name) {
|
||||
appendToIndex(user->nameOrPhone);
|
||||
}
|
||||
@@ -326,7 +326,7 @@ void PeerData::fillNames() {
|
||||
if (isSelf()) {
|
||||
appendToIndex(lang(lng_saved_messages));
|
||||
}
|
||||
} else if (auto channel = asChannel()) {
|
||||
} else if (const auto channel = asChannel()) {
|
||||
appendToIndex(channel->username);
|
||||
}
|
||||
auto toIndex = toIndexList.join(' ');
|
||||
@@ -335,7 +335,7 @@ void PeerData::fillNames() {
|
||||
const auto namesList = TextUtilities::PrepareSearchWords(toIndex);
|
||||
for (const auto &name : namesList) {
|
||||
_nameWords.insert(name);
|
||||
_nameFirstChars.insert(name[0]);
|
||||
_nameFirstLetters.insert(name[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -126,13 +126,11 @@ public:
|
||||
QString name;
|
||||
Text nameText;
|
||||
|
||||
using NameWords = base::flat_set<QString>;
|
||||
using NameFirstChars = base::flat_set<QChar>;
|
||||
const NameWords &nameWords() const {
|
||||
const base::flat_set<QString> &nameWords() const {
|
||||
return _nameWords;
|
||||
}
|
||||
const NameFirstChars &nameFirstChars() const {
|
||||
return _nameFirstChars;
|
||||
const base::flat_set<QChar> &nameFirstLetters() const {
|
||||
return _nameFirstLetters;
|
||||
}
|
||||
|
||||
enum LoadedStatus {
|
||||
@@ -243,8 +241,8 @@ private:
|
||||
Data::NotifySettings _notify;
|
||||
|
||||
ClickHandlerPtr _openLink;
|
||||
NameWords _nameWords; // for filtering
|
||||
NameFirstChars _nameFirstChars;
|
||||
base::flat_set<QString> _nameWords; // for filtering
|
||||
base::flat_set<QChar> _nameFirstLetters;
|
||||
|
||||
TimeMs _lastFullUpdate = 0;
|
||||
|
||||
|
Reference in New Issue
Block a user