Fix crash in theme changing.

This commit is contained in:
John Preston 2019-06-18 14:13:07 +02:00
parent 9ca4f0975a
commit 42798d466f
1 changed files with 8 additions and 4 deletions

View File

@ -99,8 +99,11 @@ inline bool IsSelfPeer(PeerData *peer) {
return (peer && peer->isSelf());
}
inline int UnreadCount(PeerData *peer) {
return (peer && peer->owner().history(peer->id)->unreadCountForBadge());
inline int UnreadCount(not_null<PeerData*> peer) {
if (const auto history = peer->owner().historyLoaded(peer)) {
return history->unreadCountForBadge();
}
return 0;
}
NSString *FormatTime(int time) {
@ -259,7 +262,8 @@ void SendKeyEvent(int command) {
std::move(
themeChanged
) | rpl::filter([=](const Update &update) {
return update.type == Update::Type::ApplyingTheme
return (update.type == Update::Type::ApplyingTheme)
&& (_peer != nullptr)
&& (UnreadCount(_peer) || Data::IsPeerAnOnlineUser(_peer));
}) | rpl::start_with_next([=] {
[self updateBadge];
@ -286,8 +290,8 @@ void SendKeyEvent(int command) {
if (_peer == newPeer) {
return;
}
_peer = newPeer;
_peerChangedLifetime.destroy();
_peer = newPeer;
if (!_peer) {
return;
}