2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-10-25 15:16:15 +00:00

Support basic feed display in chats list.

This commit is contained in:
John Preston
2018-01-05 18:57:18 +03:00
parent 9d2239291d
commit 782e70b171
28 changed files with 1092 additions and 527 deletions

View File

@@ -7,17 +7,126 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "data/data_feed.h"
#include "dialogs/dialogs_key.h"
namespace Data {
Feed::Feed(FeedId id) : _id(id) {
FeedPosition::FeedPosition(const MTPFeedPosition &position)
: date(position.c_feedPosition().vdate.v)
, peerId(peerFromMTP(position.c_feedPosition().vpeer))
, msgId(position.c_feedPosition().vid.v) {
}
FeedPosition::FeedPosition(not_null<HistoryItem*> item)
: date(toServerTime(item->date.toTime_t()).v)
, peerId(item->history()->peer->id)
, msgId(item->id) {
}
bool FeedPosition::operator<(const FeedPosition &other) const {
if (date < other.date) {
return true;
} else if (other.date < date) {
return false;
}
const auto peer = peerToBareInt(peerId);
const auto otherPeer = peerToBareInt(other.peerId);
if (peer < otherPeer) {
return true;
} else if (otherPeer < peer) {
return false;
}
return (msgId < other.msgId);
}
Feed::Feed(FeedId id)
: Entry(this)
, _id(id) {
}
void Feed::registerOne(not_null<ChannelData*> channel) {
_channels.emplace(channel);
const auto history = App::history(channel);
if (!base::contains(_channels, history)) {
_channels.push_back(history);
if (history->lastMsg) {
updateLastMessage(history->lastMsg);
}
}
}
void Feed::unregisterOne(not_null<ChannelData*> channel) {
_channels.remove(channel);
const auto history = App::history(channel);
_channels.erase(ranges::remove(_channels, history), end(_channels));
if (_lastMessage->history() == history) {
messageRemoved(_lastMessage);
}
}
void Feed::updateLastMessage(not_null<HistoryItem*> item) {
if (justSetLastMessage(item)) {
setChatsListDate(_lastMessage->date);
}
}
void Feed::loadUserpic() {
constexpr auto kPaintUserpicsCount = 4;
auto load = kPaintUserpicsCount;
for (const auto channel : _channels) {
channel->peer->loadUserpic();
if (!--load) {
break;
}
}
}
void Feed::paintUserpic(
Painter &p,
int x,
int y,
int size) const {
const auto small = (size - st::lineWidth) / 2;
const auto delta = size - small;
auto index = 0;
for (const auto channel : _channels) {
channel->peer->paintUserpic(p, x, y, small);
switch (++index) {
case 1:
case 3: x += delta; break;
case 2: x -= delta; y += delta; break;
}
}
}
bool Feed::justSetLastMessage(not_null<HistoryItem*> item) {
if (_lastMessage && FeedPosition(item) <= FeedPosition(_lastMessage)) {
return false;
}
_lastMessage = item;
return true;
}
void Feed::messageRemoved(not_null<HistoryItem*> item) {
if (_lastMessage == item) {
recountLastMessage();
}
}
void Feed::historyCleared(not_null<History*> history) {
if (_lastMessage->history() == history) {
recountLastMessage();
}
}
void Feed::recountLastMessage() {
_lastMessage = nullptr;
for (const auto history : _channels) {
if (const auto last = history->lastMsg) {
justSetLastMessage(last);
}
}
if (_lastMessage) {
setChatsListDate(_lastMessage->date);
}
}
void Feed::setUnreadCounts(int unreadCount, int unreadMutedCount) {
@@ -25,14 +134,8 @@ void Feed::setUnreadCounts(int unreadCount, int unreadMutedCount) {
_unreadMutedCount = unreadMutedCount;
}
void Feed::cachePinnedIndex(int index) {
_pinnedIndex = index;
}
uint64 Feed::sortKeyInChatList() const {
return 0ULL;/* isPinnedDialog()
? pinnedDialogPos(_pinnedIndex)
: dialogPosFromDate(chatListDate());*/
void Feed::setUnreadPosition(const FeedPosition &position) {
_unreadPosition = position;
}
} // namespace Data