Moved opening peer from PeerClickHandler to SessionController.
This commit is contained in:
		
							parent
							
								
									51b259fdea
								
							
						
					
					
						commit
						d8fb5be9b5
					
				
					 4 changed files with 47 additions and 28 deletions
				
			
		|  | @ -29,7 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "main/main_app_config.h" | ||||
| #include "mtproto/mtproto_config.h" | ||||
| #include "core/application.h" | ||||
| #include "mainwindow.h" | ||||
| #include "core/click_handler_types.h" | ||||
| #include "window/window_session_controller.h" | ||||
| #include "ui/image/image.h" | ||||
| #include "ui/empty_userpic.h" | ||||
|  | @ -42,7 +42,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "storage/file_download.h" | ||||
| #include "storage/storage_facade.h" | ||||
| #include "storage/storage_shared_media.h" | ||||
| #include "facades.h" // Ui::showPeerProfile
 | ||||
| 
 | ||||
| namespace { | ||||
| 
 | ||||
|  | @ -168,33 +167,22 @@ void PeerClickHandler::onClick(ClickContext context) const { | |||
| 	if (context.button != Qt::LeftButton) { | ||||
| 		return; | ||||
| 	} | ||||
| 	const auto my = context.other.value<ClickHandlerContext>(); | ||||
| 	const auto window = [&]() -> Window::SessionController* { | ||||
| 		if (const auto controller = my.sessionWindow.get()) { | ||||
| 			return controller; | ||||
| 		} | ||||
| 		const auto &windows = _peer->session().windows(); | ||||
| 		if (windows.empty()) { | ||||
| 		Core::App().domain().activate(&_peer->session().account()); | ||||
| 			_peer->session().domain().activate(&_peer->session().account()); | ||||
| 			if (windows.empty()) { | ||||
| 			return; | ||||
| 				return nullptr; | ||||
| 			} | ||||
| 		} | ||||
| 	const auto window = windows.front(); | ||||
| 	const auto currentPeer = window->activeChatCurrent().peer(); | ||||
| 	if (_peer && _peer->isChannel() && currentPeer != _peer) { | ||||
| 		const auto clickedChannel = _peer->asChannel(); | ||||
| 		if (!clickedChannel->isPublic() | ||||
| 			&& !clickedChannel->amIn() | ||||
| 			&& (!currentPeer->isChannel() | ||||
| 				|| currentPeer->asChannel()->linkedChat() != clickedChannel)) { | ||||
| 			Ui::ShowMultilineToast({ | ||||
| 				.text = { _peer->isMegagroup() | ||||
| 					? tr::lng_group_not_accessible(tr::now) | ||||
| 					: tr::lng_channel_not_accessible(tr::now) }, | ||||
| 			}); | ||||
| 		} else { | ||||
| 			window->showPeerHistory( | ||||
| 				_peer, | ||||
| 				Window::SectionShow::Way::Forward); | ||||
| 		} | ||||
| 	} else { | ||||
| 		Ui::showPeerProfile(_peer); | ||||
| 		return windows.front(); | ||||
| 	}(); | ||||
| 	if (window) { | ||||
| 		window->showPeer(_peer); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -57,7 +57,12 @@ struct ViewButton::Inner { | |||
| 
 | ||||
| ViewButton::Inner::Inner(not_null<PeerData*> peer, Fn<void()> updateCallback) | ||||
| : margins(st::historyViewButtonMargins) | ||||
| , link(peer->openLink()) | ||||
| , link(std::make_shared<LambdaClickHandler>([=](ClickContext context) { | ||||
| 	const auto my = context.other.value<ClickHandlerContext>(); | ||||
| 	if (const auto controller = my.sessionWindow.get()) { | ||||
| 		controller->showPeer(peer); | ||||
| 	} | ||||
| })) | ||||
| , updateCallback(std::move(updateCallback)) | ||||
| , text(st::historyViewButtonTextStyle, PeerToPhrase(peer)) { | ||||
| } | ||||
|  |  | |||
|  | @ -1074,6 +1074,30 @@ void SessionController::closeThirdSection() { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| void SessionController::showPeer(not_null<PeerData*> peer, MsgId msgId) { | ||||
| 	const auto currentPeer = activeChatCurrent().peer(); | ||||
| 	if (peer && peer->isChannel() && currentPeer != peer) { | ||||
| 		const auto clickedChannel = peer->asChannel(); | ||||
| 		if (!clickedChannel->isPublic() | ||||
| 			&& !clickedChannel->amIn() | ||||
| 			&& (!currentPeer->isChannel() | ||||
| 				|| currentPeer->asChannel()->linkedChat() | ||||
| 					!= clickedChannel)) { | ||||
| 			Ui::ShowMultilineToast({ | ||||
| 				.text = { | ||||
| 					.text = peer->isMegagroup() | ||||
| 						? tr::lng_group_not_accessible(tr::now) | ||||
| 						: tr::lng_channel_not_accessible(tr::now) | ||||
| 				}, | ||||
| 			}); | ||||
| 		} else { | ||||
| 			showPeerHistory(peer->id, SectionShow(), msgId); | ||||
| 		} | ||||
| 	} else { | ||||
| 		showPeerInfo(peer, SectionShow()); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void SessionController::startOrJoinGroupCall( | ||||
| 		not_null<PeerData*> peer, | ||||
| 		QString joinHash, | ||||
|  |  | |||
|  | @ -322,6 +322,8 @@ public: | |||
| 	void resizeForThirdSection(); | ||||
| 	void closeThirdSection(); | ||||
| 
 | ||||
| 	void showPeer(not_null<PeerData*> peer, MsgId msgId = ShowAtUnreadMsgId); | ||||
| 
 | ||||
| 	enum class GroupCallJoinConfirm { | ||||
| 		None, | ||||
| 		IfNowInAnother, | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 23rd
						23rd