Update bot menu attach in realtime.
This commit is contained in:
		
							parent
							
								
									c73eb5d791
								
							
						
					
					
						commit
						be6ee73a04
					
				
					 4 changed files with 37 additions and 14 deletions
				
			
		|  | @ -2010,6 +2010,17 @@ void Updates::feedUpdate(const MTPUpdate &update) { | ||||||
| 		session().data().webViewResultSent({ .queryId = d.vquery_id().v }); | 		session().data().webViewResultSent({ .queryId = d.vquery_id().v }); | ||||||
| 	} break; | 	} break; | ||||||
| 
 | 
 | ||||||
|  | 	case mtpc_updateBotMenuButton: { | ||||||
|  | 		const auto &d = update.c_updateBotMenuButton(); | ||||||
|  | 		if (const auto bot = session().data().userLoaded(d.vbot_id())) { | ||||||
|  | 			if (const auto info = bot->botInfo.get(); info && info->inited) { | ||||||
|  | 				if (Data::ApplyBotMenuButton(info, d.vbutton())) { | ||||||
|  | 					session().data().botCommandsChanged(bot); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} break; | ||||||
|  | 
 | ||||||
| 	case mtpc_updatePendingJoinRequests: { | 	case mtpc_updatePendingJoinRequests: { | ||||||
| 		const auto &d = update.c_updatePendingJoinRequests(); | 		const auto &d = update.c_updatePendingJoinRequests(); | ||||||
| 		if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) { | 		if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) { | ||||||
|  |  | ||||||
|  | @ -159,6 +159,25 @@ bool UpdateBotCommands( | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool ApplyBotMenuButton( | ||||||
|  | 		not_null<BotInfo*> info, | ||||||
|  | 		const MTPBotMenuButton &button) { | ||||||
|  | 	auto text = QString(); | ||||||
|  | 	auto url = QString(); | ||||||
|  | 	button.match([&](const MTPDbotMenuButton &data) { | ||||||
|  | 		text = qs(data.vtext()); | ||||||
|  | 		url = qs(data.vurl()); | ||||||
|  | 	}, [&](const auto &) { | ||||||
|  | 	}); | ||||||
|  | 	const auto changed = (info->botMenuButtonText != text) | ||||||
|  | 		|| (info->botMenuButtonUrl != url); | ||||||
|  | 
 | ||||||
|  | 	info->botMenuButtonText = text; | ||||||
|  | 	info->botMenuButtonUrl = url; | ||||||
|  | 
 | ||||||
|  | 	return changed; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace Data
 | } // namespace Data
 | ||||||
| 
 | 
 | ||||||
| PeerClickHandler::PeerClickHandler(not_null<PeerData*> peer) | PeerClickHandler::PeerClickHandler(not_null<PeerData*> peer) | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "data/notify/data_peer_notify_settings.h" | #include "data/notify/data_peer_notify_settings.h" | ||||||
| #include "data/data_cloud_file.h" | #include "data/data_cloud_file.h" | ||||||
| 
 | 
 | ||||||
|  | struct BotInfo; | ||||||
| class PeerData; | class PeerData; | ||||||
| class UserData; | class UserData; | ||||||
| class ChatData; | class ChatData; | ||||||
|  | @ -109,6 +110,9 @@ bool UpdateBotCommands( | ||||||
| bool UpdateBotCommands( | bool UpdateBotCommands( | ||||||
| 	base::flat_map<UserId, std::vector<BotCommand>> &commands, | 	base::flat_map<UserId, std::vector<BotCommand>> &commands, | ||||||
| 	const MTPVector<MTPBotInfo> &data); | 	const MTPVector<MTPBotInfo> &data); | ||||||
|  | bool ApplyBotMenuButton( | ||||||
|  | 	not_null<BotInfo*> info, | ||||||
|  | 	const MTPBotMenuButton &button); | ||||||
| 
 | 
 | ||||||
| } // namespace Data
 | } // namespace Data
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -133,20 +133,9 @@ void UserData::setBotInfo(const MTPBotInfo &info) { | ||||||
| 		const auto changedCommands = Data::UpdateBotCommands( | 		const auto changedCommands = Data::UpdateBotCommands( | ||||||
| 			botInfo->commands, | 			botInfo->commands, | ||||||
| 			d.vcommands()); | 			d.vcommands()); | ||||||
| 		auto text = QString(); | 		const auto changedButton = Data::ApplyBotMenuButton( | ||||||
| 		auto url = QString(); | 			botInfo.get(), | ||||||
| 		d.vmenu_button().match([&](const MTPDbotMenuButton &data) { | 			d.vmenu_button()); | ||||||
| 			text = qs(data.vtext()); |  | ||||||
| 			url = qs(data.vurl()); |  | ||||||
| 		}, [&](const auto &) { |  | ||||||
| 		}); |  | ||||||
| 		const auto changedButton = (botInfo->botMenuButtonText != text) |  | ||||||
| 			|| (botInfo->botMenuButtonUrl != url); |  | ||||||
| 		if (changedButton) { |  | ||||||
| 			botInfo->botMenuButtonText = text; |  | ||||||
| 			botInfo->botMenuButtonUrl = url; |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		botInfo->inited = true; | 		botInfo->inited = true; | ||||||
| 
 | 
 | ||||||
| 		if (changedCommands || changedButton) { | 		if (changedCommands || changedButton) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston