2016-04-09 18:45:55 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-09 18:45:55 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-05 15:57:18 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
2016-04-09 18:45:55 +00:00
|
|
|
#include "dialogs/dialogs_list.h"
|
|
|
|
|
|
|
|
class History;
|
|
|
|
|
|
|
|
namespace Dialogs {
|
|
|
|
|
|
|
|
class IndexedList {
|
|
|
|
public:
|
2020-03-17 13:04:30 +00:00
|
|
|
IndexedList(SortMode sortMode, FilterId filterId = 0);
|
2016-04-09 18:45:55 +00:00
|
|
|
|
2018-01-04 17:15:04 +00:00
|
|
|
RowsByLetter addToEnd(Key key);
|
|
|
|
Row *addByName(Key key);
|
2019-04-16 11:37:50 +00:00
|
|
|
void adjustByDate(const RowsByLetter &links);
|
2018-01-04 17:15:04 +00:00
|
|
|
void moveToTop(Key key);
|
2022-11-29 17:36:34 +00:00
|
|
|
void updateHeight(const RowsByLetter &links);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2017-01-30 15:27:13 +00:00
|
|
|
// row must belong to this indexed list all().
|
|
|
|
void movePinned(Row *row, int deltaSign);
|
|
|
|
|
2020-03-09 11:17:56 +00:00
|
|
|
// For sortMode != SortMode::Date && != Complex
|
2018-01-04 17:15:04 +00:00
|
|
|
void peerNameChanged(
|
|
|
|
not_null<PeerData*> peer,
|
2018-01-22 09:33:09 +00:00
|
|
|
const base::flat_set<QChar> &oldChars);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2020-03-09 11:17:56 +00:00
|
|
|
//For sortMode == SortMode::Date || == Complex
|
2018-01-04 17:15:04 +00:00
|
|
|
void peerNameChanged(
|
2020-02-07 09:43:12 +00:00
|
|
|
FilterId filterId,
|
2018-01-04 17:15:04 +00:00
|
|
|
not_null<PeerData*> peer,
|
2018-01-22 09:33:09 +00:00
|
|
|
const base::flat_set<QChar> &oldChars);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2022-11-11 06:23:23 +00:00
|
|
|
void remove(Key key, Row *replacedBy = nullptr);
|
2016-04-09 18:45:55 +00:00
|
|
|
void clear();
|
|
|
|
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] const List &all() const {
|
2016-04-09 18:45:55 +00:00
|
|
|
return _list;
|
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] const List *filtered(QChar ch) const {
|
2019-04-16 14:05:56 +00:00
|
|
|
const auto i = _index.find(ch);
|
|
|
|
return (i != _index.end()) ? &i->second : nullptr;
|
2016-04-09 18:45:55 +00:00
|
|
|
}
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] std::vector<not_null<Row*>> filtered(
|
|
|
|
const QStringList &words) const;
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
// Part of List interface is duplicated here for all() list.
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] int size() const { return all().size(); }
|
|
|
|
[[nodiscard]] bool empty() const { return all().empty(); }
|
|
|
|
[[nodiscard]] int height() const { return all().height(); }
|
|
|
|
[[nodiscard]] bool contains(Key key) const {
|
|
|
|
return all().contains(key);
|
|
|
|
}
|
|
|
|
[[nodiscard]] Row *getRow(Key key) const { return all().getRow(key); }
|
|
|
|
[[nodiscard]] Row *rowAtY(int y) const { return all().rowAtY(y); }
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
using iterator = List::iterator;
|
|
|
|
using const_iterator = List::const_iterator;
|
2022-11-11 06:23:23 +00:00
|
|
|
[[nodiscard]] const_iterator cbegin() const { return all().cbegin(); }
|
|
|
|
[[nodiscard]] const_iterator cend() const { return all().cend(); }
|
|
|
|
[[nodiscard]] const_iterator begin() const { return all().cbegin(); }
|
|
|
|
[[nodiscard]] const_iterator end() const { return all().cend(); }
|
|
|
|
[[nodiscard]] iterator begin() { return all().begin(); }
|
|
|
|
[[nodiscard]] iterator end() { return all().end(); }
|
|
|
|
[[nodiscard]] const_iterator cfind(Row *value) const {
|
|
|
|
return all().cfind(value);
|
|
|
|
}
|
|
|
|
[[nodiscard]] const_iterator find(Row *value) const {
|
|
|
|
return all().cfind(value);
|
|
|
|
}
|
|
|
|
[[nodiscard]] iterator find(Row *value) { return all().find(value); }
|
|
|
|
[[nodiscard]] const_iterator findByY(int y) const {
|
|
|
|
return all().findByY(y);
|
|
|
|
}
|
|
|
|
[[nodiscard]] iterator findByY(int y) { return all().findByY(y); }
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-04 17:15:04 +00:00
|
|
|
void adjustByName(
|
|
|
|
Key key,
|
2018-01-22 09:33:09 +00:00
|
|
|
const base::flat_set<QChar> &oldChars);
|
2018-01-04 17:15:04 +00:00
|
|
|
void adjustNames(
|
2020-02-07 09:43:12 +00:00
|
|
|
FilterId filterId,
|
2018-01-05 15:57:18 +00:00
|
|
|
not_null<History*> history,
|
2018-01-22 09:33:09 +00:00
|
|
|
const base::flat_set<QChar> &oldChars);
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2019-04-16 14:05:56 +00:00
|
|
|
SortMode _sortMode = SortMode();
|
2020-03-17 13:04:30 +00:00
|
|
|
FilterId _filterId = 0;
|
2017-10-24 17:11:35 +00:00
|
|
|
List _list, _empty;
|
2019-04-16 14:05:56 +00:00
|
|
|
base::flat_map<QChar, List> _index;
|
2016-04-09 18:45:55 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Dialogs
|