2016-04-09 22:45:55 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-09 22:45:55 +04:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-09 22:45:55 +04:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-14 14:00:23 +03:00
|
|
|
#include "ui/text/text.h"
|
2018-01-04 20:15:04 +03:00
|
|
|
#include "base/value_ordering.h"
|
2016-04-09 22:45:55 +04:00
|
|
|
|
|
|
|
class History;
|
|
|
|
class HistoryItem;
|
|
|
|
|
2018-01-04 20:15:04 +03:00
|
|
|
namespace Data {
|
|
|
|
class Feed;
|
|
|
|
} // namespace Data
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
namespace Ui {
|
|
|
|
class RippleAnimation;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-04-09 22:45:55 +04:00
|
|
|
namespace Dialogs {
|
|
|
|
namespace Layout {
|
|
|
|
class RowPainter;
|
|
|
|
} // namespace Layout
|
|
|
|
|
2018-01-04 20:15:04 +03:00
|
|
|
struct Key {
|
|
|
|
Key() = default;
|
|
|
|
Key(History *history) : value(history) {
|
|
|
|
}
|
|
|
|
Key(not_null<History*> history) : value(history) {
|
|
|
|
}
|
|
|
|
Key(Data::Feed *feed) : value(feed) {
|
|
|
|
}
|
|
|
|
Key(not_null<Data::Feed*> feed) : value(feed) {
|
|
|
|
}
|
|
|
|
const QString &name() const {
|
|
|
|
if (const auto p = base::get_if<not_null<History*>>(&value)) {
|
|
|
|
return (*p)->peer->name;
|
|
|
|
}
|
|
|
|
// #TODO feeds name
|
|
|
|
static const auto empty = QString();
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
const PeerData::NameFirstChars &nameFirstChars() const {
|
|
|
|
if (const auto p = base::get_if<not_null<History*>>(&value)) {
|
|
|
|
return (*p)->peer->nameFirstChars();
|
|
|
|
}
|
|
|
|
// #TODO feeds name
|
|
|
|
static const auto empty = PeerData::NameFirstChars();
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
uint64 sortKey() const {
|
|
|
|
if (const auto p = base::get_if<not_null<History*>>(&value)) {
|
|
|
|
return (*p)->sortKeyInChatList();
|
|
|
|
}
|
|
|
|
// #TODO feeds sort in chats list
|
|
|
|
return 0ULL;
|
|
|
|
}
|
|
|
|
History *history() const {
|
|
|
|
if (const auto p = base::get_if<not_null<History*>>(&value)) {
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Data::Feed *feed() const {
|
|
|
|
if (const auto p = base::get_if<not_null<Data::Feed*>>(&value)) {
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<(const Key &other) const {
|
|
|
|
return value < other.value;
|
|
|
|
}
|
|
|
|
inline bool operator==(const Key &other) const {
|
|
|
|
return value == other.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not working :(
|
|
|
|
//friend inline auto value_ordering_helper(const Key &key) {
|
|
|
|
// return key.value;
|
|
|
|
//}
|
|
|
|
|
|
|
|
base::optional_variant<
|
|
|
|
not_null<History*>,
|
|
|
|
not_null<Data::Feed*>> value;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RowDescriptor {
|
|
|
|
RowDescriptor() = default;
|
|
|
|
RowDescriptor(Key key, MsgId msgId) : key(key), msgId(msgId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Key key;
|
|
|
|
MsgId msgId = 0;
|
|
|
|
};
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
class RippleRow {
|
|
|
|
public:
|
|
|
|
RippleRow();
|
|
|
|
~RippleRow();
|
|
|
|
|
2017-02-26 14:32:13 +03:00
|
|
|
void addRipple(QPoint origin, QSize size, base::lambda<void()> updateCallback);
|
2016-12-05 14:01:08 +03:00
|
|
|
void stopLastRipple();
|
|
|
|
|
|
|
|
void paintRipple(Painter &p, int x, int y, int outerWidth, TimeMs ms, const QColor *colorOverride = nullptr) const;
|
|
|
|
|
|
|
|
private:
|
2017-02-21 16:45:56 +03:00
|
|
|
mutable std::unique_ptr<Ui::RippleAnimation> _ripple;
|
2016-12-05 14:01:08 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-09 22:45:55 +04:00
|
|
|
class List;
|
2016-12-05 14:01:08 +03:00
|
|
|
class Row : public RippleRow {
|
2016-04-09 22:45:55 +04:00
|
|
|
public:
|
2018-01-04 20:15:04 +03:00
|
|
|
explicit Row(std::nullptr_t) {
|
|
|
|
}
|
|
|
|
Row(Key key, Row *prev, Row *next, int pos)
|
|
|
|
: _id(key)
|
|
|
|
, _prev(prev)
|
|
|
|
, _next(next)
|
|
|
|
, _pos(pos) {
|
2016-04-09 22:45:55 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 20:15:04 +03:00
|
|
|
Key key() const {
|
|
|
|
return _id;
|
|
|
|
}
|
2016-04-09 22:45:55 +04:00
|
|
|
History *history() const {
|
2018-01-04 20:15:04 +03:00
|
|
|
return _id.history();
|
|
|
|
}
|
|
|
|
Data::Feed *feed() const {
|
|
|
|
return _id.feed();
|
|
|
|
}
|
|
|
|
QString name() const {
|
|
|
|
return _id.name();
|
2016-04-09 22:45:55 +04:00
|
|
|
}
|
|
|
|
int pos() const {
|
|
|
|
return _pos;
|
|
|
|
}
|
2018-01-04 20:15:04 +03:00
|
|
|
uint64 sortKey() const {
|
|
|
|
return _id.sortKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
// for any attached data, for example View in contacts list
|
|
|
|
void *attached = nullptr;
|
2016-04-09 22:45:55 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class List;
|
|
|
|
|
2018-01-04 20:15:04 +03:00
|
|
|
Key _id;
|
|
|
|
Row *_prev = nullptr;
|
|
|
|
Row *_next = nullptr;
|
|
|
|
int _pos = 0;
|
2016-04-09 22:45:55 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
class FakeRow : public RippleRow {
|
2016-04-09 22:45:55 +04:00
|
|
|
public:
|
2017-09-05 20:21:56 +03:00
|
|
|
FakeRow(PeerData *searchInPeer, not_null<HistoryItem*> item);
|
2016-04-09 22:45:55 +04:00
|
|
|
|
2017-09-05 20:21:56 +03:00
|
|
|
PeerData *searchInPeer() const {
|
|
|
|
return _searchInPeer;
|
|
|
|
}
|
|
|
|
not_null<HistoryItem*> item() const {
|
2016-04-09 22:45:55 +04:00
|
|
|
return _item;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class Layout::RowPainter;
|
|
|
|
|
2017-09-05 20:21:56 +03:00
|
|
|
PeerData *_searchInPeer = nullptr;
|
|
|
|
not_null<HistoryItem*> _item;
|
2016-04-09 22:45:55 +04:00
|
|
|
mutable const HistoryItem *_cacheFor = nullptr;
|
2016-06-07 22:59:39 +03:00
|
|
|
mutable Text _cache;
|
2016-04-09 22:45:55 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Dialogs
|