2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Prepare dialogs to hold a history or a feed.

This commit is contained in:
John Preston
2018-01-04 20:15:04 +03:00
parent 6a9556d42c
commit a2891807f8
24 changed files with 727 additions and 419 deletions

View File

@@ -8,10 +8,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "ui/text/text.h"
#include "base/value_ordering.h"
class History;
class HistoryItem;
namespace Data {
class Feed;
} // namespace Data
namespace Ui {
class RippleAnimation;
} // namespace Ui
@@ -21,6 +26,79 @@ namespace Layout {
class RowPainter;
} // namespace Layout
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;
};
class RippleRow {
public:
RippleRow();
@@ -39,27 +117,44 @@ private:
class List;
class Row : public RippleRow {
public:
Row(History *history, Row *prev, Row *next, int pos)
: _history(history)
, _prev(prev)
, _next(next)
, _pos(pos) {
explicit Row(std::nullptr_t) {
}
Row(Key key, Row *prev, Row *next, int pos)
: _id(key)
, _prev(prev)
, _next(next)
, _pos(pos) {
}
void *attached = nullptr; // for any attached data, for example View in contacts list
Key key() const {
return _id;
}
History *history() const {
return _history;
return _id.history();
}
Data::Feed *feed() const {
return _id.feed();
}
QString name() const {
return _id.name();
}
int pos() const {
return _pos;
}
uint64 sortKey() const {
return _id.sortKey();
}
// for any attached data, for example View in contacts list
void *attached = nullptr;
private:
friend class List;
History *_history;
Row *_prev, *_next;
int _pos;
Key _id;
Row *_prev = nullptr;
Row *_next = nullptr;
int _pos = 0;
};