2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Return not_null<History*> in App::history().

This commit is contained in:
John Preston
2017-08-31 20:53:03 +03:00
parent 5a20014b1a
commit 48e2a5472e
13 changed files with 44 additions and 22 deletions

View File

@@ -589,7 +589,7 @@ History *Histories::find(const PeerId &peerId) {
return (i == map.cend()) ? 0 : i.value();
}
History *Histories::findOrInsert(const PeerId &peerId) {
not_null<History*> Histories::findOrInsert(const PeerId &peerId) {
auto i = map.constFind(peerId);
if (i == map.cend()) {
auto history = peerIsChannel(peerId) ? static_cast<History*>(new ChannelHistory(peerId)) : (new History(peerId));
@@ -598,7 +598,7 @@ History *Histories::findOrInsert(const PeerId &peerId) {
return i.value();
}
History *Histories::findOrInsert(const PeerId &peerId, int32 unreadCount, int32 maxInboxRead, int32 maxOutboxRead) {
not_null<History*> Histories::findOrInsert(const PeerId &peerId, int32 unreadCount, int32 maxInboxRead, int32 maxOutboxRead) {
auto i = map.constFind(peerId);
if (i == map.cend()) {
auto history = peerIsChannel(peerId) ? static_cast<History*>(new ChannelHistory(peerId)) : (new History(peerId));
@@ -2099,6 +2099,21 @@ const ChannelHistory *History::asChannelHistory() const {
return isChannel() ? static_cast<const ChannelHistory*>(this) : 0;
}
not_null<History*> History::migrateToOrMe() const {
if (auto to = peer->migrateTo()) {
return App::history(to);
}
// We could get it by App::history(peer), but we optimize.
return const_cast<History*>(this);
}
History *History::migrateFrom() const {
if (auto from = peer->migrateFrom()) {
return App::history(from);
}
return nullptr;
}
bool History::isDisplayedEmpty() const {
return isEmpty() || ((blocks.size() == 1) && blocks.front()->items.size() == 1 && blocks.front()->items.front()->isEmpty());
}