mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-28 19:40:54 +00:00
Ignore accents in contacts list sorting.
This commit is contained in:
parent
0a678ae8bd
commit
f9f52302bb
@ -50,7 +50,8 @@ Folder::Folder(not_null<Data::Session*> owner, FolderId id)
|
|||||||
&owner->session(),
|
&owner->session(),
|
||||||
FilterId(),
|
FilterId(),
|
||||||
owner->session().serverConfig().pinnedDialogsInFolderMax.value())
|
owner->session().serverConfig().pinnedDialogsInFolderMax.value())
|
||||||
, _name(tr::lng_archived_name(tr::now)) {
|
, _name(tr::lng_archived_name(tr::now))
|
||||||
|
, _chatListNameSortKey(owner->nameSortKey(_name)) {
|
||||||
indexNameParts();
|
indexNameParts();
|
||||||
|
|
||||||
session().changes().peerUpdates(
|
session().changes().peerUpdates(
|
||||||
@ -408,4 +409,8 @@ const base::flat_set<QChar> &Folder::chatListFirstLetters() const {
|
|||||||
return _nameFirstLetters;
|
return _nameFirstLetters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &Folder::chatListNameSortKey() const {
|
||||||
|
return _chatListNameSortKey;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
@ -58,6 +58,7 @@ public:
|
|||||||
bool chatListMessageKnown() const override;
|
bool chatListMessageKnown() const override;
|
||||||
void requestChatListMessage() override;
|
void requestChatListMessage() override;
|
||||||
const QString &chatListName() const override;
|
const QString &chatListName() const override;
|
||||||
|
const QString &chatListNameSortKey() const override;
|
||||||
const base::flat_set<QString> &chatListNameWords() const override;
|
const base::flat_set<QString> &chatListNameWords() const override;
|
||||||
const base::flat_set<QChar> &chatListFirstLetters() const override;
|
const base::flat_set<QChar> &chatListFirstLetters() const override;
|
||||||
|
|
||||||
@ -102,6 +103,7 @@ private:
|
|||||||
QString _name;
|
QString _name;
|
||||||
base::flat_set<QString> _nameWords;
|
base::flat_set<QString> _nameWords;
|
||||||
base::flat_set<QChar> _nameFirstLetters;
|
base::flat_set<QChar> _nameFirstLetters;
|
||||||
|
QString _chatListNameSortKey;
|
||||||
|
|
||||||
std::vector<not_null<History*>> _lastHistories;
|
std::vector<not_null<History*>> _lastHistories;
|
||||||
HistoryItem *_chatListMessage = nullptr;
|
HistoryItem *_chatListMessage = nullptr;
|
||||||
|
@ -1156,6 +1156,10 @@ void Session::forgetPassportCredentials() {
|
|||||||
_passportCredentials = nullptr;
|
_passportCredentials = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Session::nameSortKey(const QString &name) const {
|
||||||
|
return TextUtilities::RemoveAccents(name).toLower();
|
||||||
|
}
|
||||||
|
|
||||||
void Session::setupMigrationViewer() {
|
void Session::setupMigrationViewer() {
|
||||||
session().changes().peerUpdates(
|
session().changes().peerUpdates(
|
||||||
PeerUpdate::Flag::Migration
|
PeerUpdate::Flag::Migration
|
||||||
@ -1203,9 +1207,13 @@ void Session::setupPeerNameViewer() {
|
|||||||
session().changes().realtimeNameUpdates(
|
session().changes().realtimeNameUpdates(
|
||||||
) | rpl::start_with_next([=](const NameUpdate &update) {
|
) | rpl::start_with_next([=](const NameUpdate &update) {
|
||||||
const auto peer = update.peer;
|
const auto peer = update.peer;
|
||||||
|
if (const auto history = historyLoaded(peer)) {
|
||||||
|
history->refreshChatListNameSortKey();
|
||||||
|
}
|
||||||
const auto &oldLetters = update.oldFirstLetters;
|
const auto &oldLetters = update.oldFirstLetters;
|
||||||
_contactsNoChatsList.peerNameChanged(peer, oldLetters);
|
_contactsNoChatsList.peerNameChanged(peer, oldLetters);
|
||||||
_contactsList.peerNameChanged(peer, oldLetters);
|
_contactsList.peerNameChanged(peer, oldLetters);
|
||||||
|
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,8 @@ public:
|
|||||||
return *_session;
|
return *_session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString nameSortKey(const QString &name) const;
|
||||||
|
|
||||||
[[nodiscard]] Groups &groups() {
|
[[nodiscard]] Groups &groups() {
|
||||||
return _groups;
|
return _groups;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,7 @@ public:
|
|||||||
virtual bool chatListMessageKnown() const = 0;
|
virtual bool chatListMessageKnown() const = 0;
|
||||||
virtual void requestChatListMessage() = 0;
|
virtual void requestChatListMessage() = 0;
|
||||||
virtual const QString &chatListName() const = 0;
|
virtual const QString &chatListName() const = 0;
|
||||||
|
virtual const QString &chatListNameSortKey() const = 0;
|
||||||
virtual const base::flat_set<QString> &chatListNameWords() const = 0;
|
virtual const base::flat_set<QString> &chatListNameWords() const = 0;
|
||||||
virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
|
virtual const base::flat_set<QChar> &chatListFirstLetters() const = 0;
|
||||||
|
|
||||||
|
@ -62,20 +62,18 @@ not_null<Row*> List::addByName(Key key) {
|
|||||||
void List::adjustByName(not_null<Row*> row) {
|
void List::adjustByName(not_null<Row*> row) {
|
||||||
Expects(row->pos() >= 0 && row->pos() < _rows.size());
|
Expects(row->pos() >= 0 && row->pos() < _rows.size());
|
||||||
|
|
||||||
const auto &name = row->entry()->chatListName();
|
const auto &key = row->entry()->chatListNameSortKey();
|
||||||
const auto index = row->pos();
|
const auto index = row->pos();
|
||||||
const auto i = _rows.begin() + index;
|
const auto i = _rows.begin() + index;
|
||||||
const auto before = std::find_if(i + 1, _rows.end(), [&](Row *row) {
|
const auto before = std::find_if(i + 1, _rows.end(), [&](Row *row) {
|
||||||
const auto &greater = row->entry()->chatListName();
|
return row->entry()->chatListNameSortKey().compare(key) >= 0;
|
||||||
return greater.compare(name, Qt::CaseInsensitive) >= 0;
|
|
||||||
});
|
});
|
||||||
if (before != i + 1) {
|
if (before != i + 1) {
|
||||||
rotate(i, i + 1, before);
|
rotate(i, i + 1, before);
|
||||||
} else if (i != _rows.begin()) {
|
} else if (i != _rows.begin()) {
|
||||||
const auto from = std::make_reverse_iterator(i);
|
const auto from = std::make_reverse_iterator(i);
|
||||||
const auto after = std::find_if(from, _rows.rend(), [&](Row *row) {
|
const auto after = std::find_if(from, _rows.rend(), [&](Row *row) {
|
||||||
const auto &less = row->entry()->chatListName();
|
return row->entry()->chatListNameSortKey().compare(key) <= 0;
|
||||||
return less.compare(name, Qt::CaseInsensitive) <= 0;
|
|
||||||
}).base();
|
}).base();
|
||||||
if (after != i) {
|
if (after != i) {
|
||||||
rotate(after, i, i + 1);
|
rotate(after, i, i + 1);
|
||||||
|
@ -62,6 +62,7 @@ History::History(not_null<Data::Session*> owner, PeerId peerId)
|
|||||||
, peer(owner->peer(peerId))
|
, peer(owner->peer(peerId))
|
||||||
, cloudDraftTextCache(st::dialogsTextWidthMin)
|
, cloudDraftTextCache(st::dialogsTextWidthMin)
|
||||||
, _mute(owner->notifyIsMuted(peer))
|
, _mute(owner->notifyIsMuted(peer))
|
||||||
|
, _chatListNameSortKey(owner->nameSortKey(peer->name))
|
||||||
, _sendActionPainter(this) {
|
, _sendActionPainter(this) {
|
||||||
if (const auto user = peer->asUser()) {
|
if (const auto user = peer->asUser()) {
|
||||||
if (user->isBot()) {
|
if (user->isBot()) {
|
||||||
@ -2019,6 +2020,14 @@ const QString &History::chatListName() const {
|
|||||||
return peer->name;
|
return peer->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &History::chatListNameSortKey() const {
|
||||||
|
return _chatListNameSortKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
void History::refreshChatListNameSortKey() {
|
||||||
|
_chatListNameSortKey = owner().nameSortKey(peer->name);
|
||||||
|
}
|
||||||
|
|
||||||
const base::flat_set<QString> &History::chatListNameWords() const {
|
const base::flat_set<QString> &History::chatListNameWords() const {
|
||||||
return peer->nameWords();
|
return peer->nameWords();
|
||||||
}
|
}
|
||||||
|
@ -365,6 +365,7 @@ public:
|
|||||||
bool chatListMessageKnown() const override;
|
bool chatListMessageKnown() const override;
|
||||||
void requestChatListMessage() override;
|
void requestChatListMessage() override;
|
||||||
const QString &chatListName() const override;
|
const QString &chatListName() const override;
|
||||||
|
const QString &chatListNameSortKey() const override;
|
||||||
const base::flat_set<QString> &chatListNameWords() const override;
|
const base::flat_set<QString> &chatListNameWords() const override;
|
||||||
const base::flat_set<QChar> &chatListFirstLetters() const override;
|
const base::flat_set<QChar> &chatListFirstLetters() const override;
|
||||||
void loadUserpic() override;
|
void loadUserpic() override;
|
||||||
@ -375,6 +376,8 @@ public:
|
|||||||
int y,
|
int y,
|
||||||
int size) const override;
|
int size) const override;
|
||||||
|
|
||||||
|
void refreshChatListNameSortKey();
|
||||||
|
|
||||||
void setFakeChatListMessageFrom(const MTPmessages_Messages &data);
|
void setFakeChatListMessageFrom(const MTPmessages_Messages &data);
|
||||||
void checkChatListMessageRemoved(not_null<HistoryItem*> item);
|
void checkChatListMessageRemoved(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
@ -566,6 +569,8 @@ private:
|
|||||||
// be a migrate message, but _chatListMessage should be the one before.
|
// be a migrate message, but _chatListMessage should be the one before.
|
||||||
std::optional<HistoryItem*> _chatListMessage;
|
std::optional<HistoryItem*> _chatListMessage;
|
||||||
|
|
||||||
|
QString _chatListNameSortKey;
|
||||||
|
|
||||||
bool _unreadMark = false;
|
bool _unreadMark = false;
|
||||||
bool _fakeUnreadWhileOpened = false;
|
bool _fakeUnreadWhileOpened = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user