mirror of https://github.com/procxx/kepka.git
				
				
				
			Return not_null<History*> in App::history().
This commit is contained in:
		
							parent
							
								
									5a20014b1a
								
							
						
					
					
						commit
						48e2a5472e
					
				|  | @ -1858,7 +1858,7 @@ namespace { | ||||||
| 		return ::histories; | 		return ::histories; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	History *history(const PeerId &peer) { | 	not_null<History*> history(const PeerId &peer) { | ||||||
| 		return ::histories.findOrInsert(peer); | 		return ::histories.findOrInsert(peer); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -156,11 +156,11 @@ namespace App { | ||||||
| 	MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo); | 	MTPPhoto photoFromUserPhoto(MTPint userId, MTPint date, const MTPUserProfilePhoto &photo); | ||||||
| 
 | 
 | ||||||
| 	Histories &histories(); | 	Histories &histories(); | ||||||
| 	History *history(const PeerId &peer); | 	not_null<History*> history(const PeerId &peer); | ||||||
| 	History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead); | 	History *historyFromDialog(const PeerId &peer, int32 unreadCnt, int32 maxInboxRead, int32 maxOutboxRead); | ||||||
| 	History *historyLoaded(const PeerId &peer); | 	History *historyLoaded(const PeerId &peer); | ||||||
| 	HistoryItem *histItemById(ChannelId channelId, MsgId itemId); | 	HistoryItem *histItemById(ChannelId channelId, MsgId itemId); | ||||||
| 	inline History *history(const PeerData *peer) { | 	inline not_null<History*> history(const PeerData *peer) { | ||||||
| 		Assert(peer != nullptr); | 		Assert(peer != nullptr); | ||||||
| 		return history(peer->id); | 		return history(peer->id); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -589,7 +589,7 @@ History *Histories::find(const PeerId &peerId) { | ||||||
| 	return (i == map.cend()) ? 0 : i.value(); | 	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); | 	auto i = map.constFind(peerId); | ||||||
| 	if (i == map.cend()) { | 	if (i == map.cend()) { | ||||||
| 		auto history = peerIsChannel(peerId) ? static_cast<History*>(new ChannelHistory(peerId)) : (new History(peerId)); | 		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(); | 	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); | 	auto i = map.constFind(peerId); | ||||||
| 	if (i == map.cend()) { | 	if (i == map.cend()) { | ||||||
| 		auto history = peerIsChannel(peerId) ? static_cast<History*>(new ChannelHistory(peerId)) : (new History(peerId)); | 		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; | 	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 { | bool History::isDisplayedEmpty() const { | ||||||
| 	return isEmpty() || ((blocks.size() == 1) && blocks.front()->items.size() == 1 && blocks.front()->items.front()->isEmpty()); | 	return isEmpty() || ((blocks.size() == 1) && blocks.front()->items.size() == 1 && blocks.front()->items.front()->isEmpty()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -53,8 +53,8 @@ public: | ||||||
| 	void step_typings(TimeMs ms, bool timer); | 	void step_typings(TimeMs ms, bool timer); | ||||||
| 
 | 
 | ||||||
| 	History *find(const PeerId &peerId); | 	History *find(const PeerId &peerId); | ||||||
| 	History *findOrInsert(const PeerId &peerId); | 	not_null<History*> findOrInsert(const PeerId &peerId); | ||||||
| 	History *findOrInsert(const PeerId &peerId, int32 unreadCount, int32 maxInboxRead, int32 maxOutboxRead); | 	not_null<History*> findOrInsert(const PeerId &peerId, int32 unreadCount, int32 maxInboxRead, int32 maxOutboxRead); | ||||||
| 
 | 
 | ||||||
| 	void clear(); | 	void clear(); | ||||||
| 	void remove(const PeerId &peer); | 	void remove(const PeerId &peer); | ||||||
|  | @ -210,6 +210,9 @@ public: | ||||||
| 	ChannelHistory *asChannelHistory(); | 	ChannelHistory *asChannelHistory(); | ||||||
| 	const ChannelHistory *asChannelHistory() const; | 	const ChannelHistory *asChannelHistory() const; | ||||||
| 
 | 
 | ||||||
|  | 	not_null<History*> migrateToOrMe() const; | ||||||
|  | 	History *migrateFrom() const; | ||||||
|  | 
 | ||||||
| 	bool isEmpty() const { | 	bool isEmpty() const { | ||||||
| 		return blocks.isEmpty(); | 		return blocks.isEmpty(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -87,7 +87,7 @@ int BinarySearchBlocksOrItems(const T &list, int edge) { | ||||||
| HistoryInner::HistoryInner(HistoryWidget *historyWidget, not_null<Window::Controller*> controller, Ui::ScrollArea *scroll, History *history) : TWidget(nullptr) | HistoryInner::HistoryInner(HistoryWidget *historyWidget, not_null<Window::Controller*> controller, Ui::ScrollArea *scroll, History *history) : TWidget(nullptr) | ||||||
| , _controller(controller) | , _controller(controller) | ||||||
| , _peer(history->peer) | , _peer(history->peer) | ||||||
| , _migrated(history->peer->migrateFrom() ? App::history(history->peer->migrateFrom()->id) : nullptr) | , _migrated(history->migrateFrom()) | ||||||
| , _history(history) | , _history(history) | ||||||
| , _widget(historyWidget) | , _widget(historyWidget) | ||||||
| , _scroll(scroll) | , _scroll(scroll) | ||||||
|  | @ -2333,7 +2333,7 @@ void HistoryInner::notifyIsBotChanged() { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void HistoryInner::notifyMigrateUpdated() { | void HistoryInner::notifyMigrateUpdated() { | ||||||
| 	_migrated = _peer->migrateFrom() ? App::history(_peer->migrateFrom()->id) : 0; | 	_migrated = _history->migrateFrom(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int HistoryInner::moveScrollFollowingInlineKeyboard(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { | int HistoryInner::moveScrollFollowingInlineKeyboard(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { | ||||||
|  |  | ||||||
|  | @ -1526,7 +1526,7 @@ void HistoryWidget::notify_migrateUpdated(PeerData *peer) { | ||||||
| 			if (peer->migrateTo()) { | 			if (peer->migrateTo()) { | ||||||
| 				showHistory(peer->migrateTo()->id, (_showAtMsgId > 0) ? (-_showAtMsgId) : _showAtMsgId, true); | 				showHistory(peer->migrateTo()->id, (_showAtMsgId > 0) ? (-_showAtMsgId) : _showAtMsgId, true); | ||||||
| 			} else if ((_migrated ? _migrated->peer : 0) != peer->migrateFrom()) { | 			} else if ((_migrated ? _migrated->peer : 0) != peer->migrateFrom()) { | ||||||
| 				History *migrated = peer->migrateFrom() ? App::history(peer->migrateFrom()->id) : 0; | 				auto migrated = _history->migrateFrom(); | ||||||
| 				if (_migrated || (migrated && migrated->unreadCount() > 0)) { | 				if (_migrated || (migrated && migrated->unreadCount() > 0)) { | ||||||
| 					showHistory(peer->id, peer->migrateFrom() ? _showAtMsgId : ((_showAtMsgId < 0 && -_showAtMsgId < ServerMaxMsgId) ? ShowAtUnreadMsgId : _showAtMsgId), true); | 					showHistory(peer->id, peer->migrateFrom() ? _showAtMsgId : ((_showAtMsgId < 0 && -_showAtMsgId < ServerMaxMsgId) ? ShowAtUnreadMsgId : _showAtMsgId), true); | ||||||
| 				} else { | 				} else { | ||||||
|  | @ -1864,8 +1864,8 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re | ||||||
| 		_serviceImageCacheSize = imageCacheSize(); | 		_serviceImageCacheSize = imageCacheSize(); | ||||||
| 		Auth().downloader().clearPriorities(); | 		Auth().downloader().clearPriorities(); | ||||||
| 
 | 
 | ||||||
| 		_history = App::history(_peer->id); | 		_history = App::history(_peer); | ||||||
| 		_migrated = _peer->migrateFrom() ? App::history(_peer->migrateFrom()->id) : 0; | 		_migrated = _history->migrateFrom(); | ||||||
| 
 | 
 | ||||||
| 		if (_channel) { | 		if (_channel) { | ||||||
| 			updateNotifySettings(); | 			updateNotifySettings(); | ||||||
|  |  | ||||||
|  | @ -1645,7 +1645,7 @@ void MainWidget::checkLastUpdate(bool afterSleep) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainWidget::overviewLoaded(History *history, const MTPmessages_Messages &result, mtpRequestId req) { | void MainWidget::overviewLoaded(not_null<History*> history, const MTPmessages_Messages &result, mtpRequestId req) { | ||||||
| 	OverviewsPreload::iterator it; | 	OverviewsPreload::iterator it; | ||||||
| 	MediaOverviewType type = OverviewCount; | 	MediaOverviewType type = OverviewCount; | ||||||
| 	for (int32 i = 0; i < OverviewCount; ++i) { | 	for (int32 i = 0; i < OverviewCount; ++i) { | ||||||
|  | @ -4009,7 +4009,10 @@ void MainWidget::onSelfParticipantUpdated(ChannelData *channel) { | ||||||
| 	auto history = App::historyLoaded(channel->id); | 	auto history = App::historyLoaded(channel->id); | ||||||
| 	if (_updatedChannels.contains(channel)) { | 	if (_updatedChannels.contains(channel)) { | ||||||
| 		_updatedChannels.remove(channel); | 		_updatedChannels.remove(channel); | ||||||
| 		if ((history ? history : App::history(channel->id))->isEmpty()) { | 		if (!history) { | ||||||
|  | 			history = App::history(channel); | ||||||
|  | 		} | ||||||
|  | 		if (history->isEmpty()) { | ||||||
| 			checkPeerHistory(channel); | 			checkPeerHistory(channel); | ||||||
| 		} else { | 		} else { | ||||||
| 			history->asChannelHistory()->checkJoinedMessage(true); | 			history->asChannelHistory()->checkJoinedMessage(true); | ||||||
|  |  | ||||||
|  | @ -515,7 +515,7 @@ private: | ||||||
| 	void readRequestDone(PeerData *peer); | 	void readRequestDone(PeerData *peer); | ||||||
| 
 | 
 | ||||||
| 	void messagesAffected(PeerData *peer, const MTPmessages_AffectedMessages &result); | 	void messagesAffected(PeerData *peer, const MTPmessages_AffectedMessages &result); | ||||||
| 	void overviewLoaded(History *history, const MTPmessages_Messages &result, mtpRequestId req); | 	void overviewLoaded(not_null<History*> history, const MTPmessages_Messages &result, mtpRequestId req); | ||||||
| 	void mediaOverviewUpdated(const Notify::PeerUpdate &update); | 	void mediaOverviewUpdated(const Notify::PeerUpdate &update); | ||||||
| 
 | 
 | ||||||
| 	Window::SectionSlideParams prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection); | 	Window::SectionSlideParams prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection); | ||||||
|  |  | ||||||
|  | @ -267,7 +267,7 @@ void MainWindow::setupIntro() { | ||||||
| 
 | 
 | ||||||
| void MainWindow::serviceNotification(const TextWithEntities &message, const MTPMessageMedia &media, int32 date, bool force) { | void MainWindow::serviceNotification(const TextWithEntities &message, const MTPMessageMedia &media, int32 date, bool force) { | ||||||
| 	if (date <= 0) date = unixtime(); | 	if (date <= 0) date = unixtime(); | ||||||
| 	auto h = (_main && App::userLoaded(ServiceUserId)) ? App::history(ServiceUserId) : nullptr; | 	auto h = (_main && App::userLoaded(ServiceUserId)) ? App::history(ServiceUserId).get() : nullptr; | ||||||
| 	if (!h || (!force && h->isEmpty())) { | 	if (!h || (!force && h->isEmpty())) { | ||||||
| 		_delayedServiceMsgs.push_back(DelayedServiceMsg(message, media, date)); | 		_delayedServiceMsgs.push_back(DelayedServiceMsg(message, media, date)); | ||||||
| 		return sendServiceHistoryRequest(); | 		return sendServiceHistoryRequest(); | ||||||
|  |  | ||||||
|  | @ -131,8 +131,8 @@ void Instance::setCurrent(const AudioMsgId &audioId) { | ||||||
| 			auto migrated = data->migrated; | 			auto migrated = data->migrated; | ||||||
| 			auto item = data->current ? App::histItemById(data->current.contextId()) : nullptr; | 			auto item = data->current ? App::histItemById(data->current.contextId()) : nullptr; | ||||||
| 			if (item) { | 			if (item) { | ||||||
| 				data->history = item->history()->peer->migrateTo() ? App::history(item->history()->peer->migrateTo()) : item->history(); | 				data->history = item->history()->migrateToOrMe(); | ||||||
| 				data->migrated = data->history->peer->migrateFrom() ? App::history(data->history->peer->migrateFrom()) : nullptr; | 				data->migrated = data->history->migrateFrom(); | ||||||
| 			} else { | 			} else { | ||||||
| 				data->history = nullptr; | 				data->history = nullptr; | ||||||
| 				data->migrated = nullptr; | 				data->migrated = nullptr; | ||||||
|  |  | ||||||
|  | @ -55,8 +55,8 @@ OverviewInner::OverviewInner(OverviewWidget *overview, Ui::ScrollArea *scroll, P | ||||||
| , _peer(peer->migrateTo() ? peer->migrateTo() : peer) | , _peer(peer->migrateTo() ? peer->migrateTo() : peer) | ||||||
| , _type(type) | , _type(type) | ||||||
| , _reversed(_type != OverviewFiles && _type != OverviewLinks) | , _reversed(_type != OverviewFiles && _type != OverviewLinks) | ||||||
| , _migrated(_peer->migrateFrom() ? App::history(_peer->migrateFrom()->id) : 0) | , _history(App::history(_peer)) | ||||||
| , _history(App::history(_peer->id)) | , _migrated(_history->migrateFrom()) | ||||||
| , _channel(peerToChannel(_peer->id)) | , _channel(peerToChannel(_peer->id)) | ||||||
| , _rowWidth(st::msgMinWidth) | , _rowWidth(st::msgMinWidth) | ||||||
| , _search(this, st::overviewFilter, langFactory(lng_dlg_filter)) | , _search(this, st::overviewFilter, langFactory(lng_dlg_filter)) | ||||||
|  |  | ||||||
|  | @ -177,7 +177,8 @@ private: | ||||||
| 	PeerData *_peer; | 	PeerData *_peer; | ||||||
| 	MediaOverviewType _type; | 	MediaOverviewType _type; | ||||||
| 	bool _reversed; | 	bool _reversed; | ||||||
| 	History *_migrated, *_history; | 	History *_history; | ||||||
|  | 	History *_migrated; | ||||||
| 	ChannelId _channel; | 	ChannelId _channel; | ||||||
| 
 | 
 | ||||||
| 	bool _selMode = false; | 	bool _selMode = false; | ||||||
|  |  | ||||||
|  | @ -51,7 +51,7 @@ QString getButtonText(MediaOverviewType type, int count) { | ||||||
| 
 | 
 | ||||||
| SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media)) | SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media)) | ||||||
| , _history(App::history(peer)) | , _history(App::history(peer)) | ||||||
| , _migrated(peer->migrateFrom() ? App::history(peer->migrateFrom()) : nullptr) { | , _migrated(_history->migrateFrom()) { | ||||||
| 	auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged | 	auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged | ||||||
| 		| Notify::PeerUpdate::Flag::UserCommonChatsChanged; | 		| Notify::PeerUpdate::Flag::UserCommonChatsChanged; | ||||||
| 	subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) { | 	subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue