Implement revoke of permanent link.
This commit is contained in:
		
							parent
							
								
									be1afb4781
								
							
						
					
					
						commit
						c7b1a37722
					
				
					 3 changed files with 42 additions and 18 deletions
				
			
		|  | @ -72,7 +72,10 @@ void InviteLinks::performCreate( | |||
| 
 | ||||
| 	using Flag = MTPmessages_ExportChatInvite::Flag; | ||||
| 	_api->request(MTPmessages_ExportChatInvite( | ||||
| 		MTP_flags((expireDate ? Flag::f_expire_date : Flag(0)) | ||||
| 		MTP_flags((revokeLegacyPermanent | ||||
| 			? Flag::f_legacy_revoke_permanent | ||||
| 			: Flag(0)) | ||||
| 			| (expireDate ? Flag::f_expire_date : Flag(0)) | ||||
| 			| (usageLimit ? Flag::f_usage_limit : Flag(0))), | ||||
| 		peer->input, | ||||
| 		MTP_int(expireDate), | ||||
|  | @ -118,14 +121,19 @@ auto InviteLinks::prepend( | |||
| 		i = _firstSlices.emplace(peer).first; | ||||
| 	} | ||||
| 	auto &links = i->second; | ||||
| 	const auto permanent = lookupPermanent(links); | ||||
| 	if (link.permanent) { | ||||
| 		if (const auto permanent = lookupPermanent(links)) { | ||||
| 		if (permanent) { | ||||
| 			permanent->revoked = true; | ||||
| 		} | ||||
| 		editPermanentLink(peer, link.link); | ||||
| 	} | ||||
| 	++links.count; | ||||
| 	if (permanent && !link.permanent) { | ||||
| 		links.links.insert(begin(links.links) + 1, link); | ||||
| 	} else { | ||||
| 		links.links.insert(begin(links.links), link); | ||||
| 	} | ||||
| 	notify(peer); | ||||
| 	return link; | ||||
| } | ||||
|  | @ -153,10 +161,6 @@ void InviteLinks::performEdit( | |||
| 		} | ||||
| 		return; | ||||
| 	} | ||||
| 	auto &callbacks = _editCallbacks[key]; | ||||
| 	if (done) { | ||||
| 		callbacks.push_back(std::move(done)); | ||||
| 	} | ||||
| 
 | ||||
| 	if (const auto permanent = revoke ? lookupPermanent(peer) : nullptr) { | ||||
| 		if (permanent->link == link) { | ||||
|  | @ -167,6 +171,11 @@ void InviteLinks::performEdit( | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	auto &callbacks = _editCallbacks[key]; | ||||
| 	if (done) { | ||||
| 		callbacks.push_back(std::move(done)); | ||||
| 	} | ||||
| 
 | ||||
| 	using Flag = MTPmessages_EditExportedChatInvite::Flag; | ||||
| 	const auto requestId = _api->request(MTPmessages_EditExportedChatInvite( | ||||
| 		MTP_flags((revoke ? Flag::f_revoked : Flag(0)) | ||||
|  |  | |||
|  | @ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | |||
| #include "ui/toast/toast.h" | ||||
| #include "history/view/history_view_group_call_tracker.h" // GenerateUs...
 | ||||
| #include "lang/lang_keys.h" | ||||
| #include "boxes/confirm_box.h" | ||||
| #include "apiwrap.h" | ||||
| #include "styles/style_info.h" | ||||
| 
 | ||||
|  | @ -45,24 +46,38 @@ void AddPermanentLinkBlock( | |||
| 	}) | rpl::distinct_until_changed( | ||||
| 	) | rpl::start_spawning(container->lifetime()); | ||||
| 
 | ||||
| 	const auto copyLink = [=] { | ||||
| 	const auto weak = Ui::MakeWeak(container); | ||||
| 	const auto copyLink = crl::guard(weak, [=] { | ||||
| 		if (const auto link = computePermanentLink()) { | ||||
| 			QGuiApplication::clipboard()->setText(link->link); | ||||
| 			Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); | ||||
| 		} | ||||
| 	}; | ||||
| 	const auto shareLink = [=] { | ||||
| 	}); | ||||
| 	const auto shareLink = crl::guard(weak, [=] { | ||||
| 		if (const auto link = computePermanentLink()) { | ||||
| 			QGuiApplication::clipboard()->setText(link->link); | ||||
| 			Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); | ||||
| 		} | ||||
| 	}; | ||||
| 	const auto revokeLink = [=] { | ||||
| 	}); | ||||
| 	const auto revokeLink = crl::guard(weak, [=] { | ||||
| 		const auto box = std::make_shared<QPointer<ConfirmBox>>(); | ||||
| 		const auto done = crl::guard(weak, [=] { | ||||
| 			if (const auto link = computePermanentLink()) { | ||||
| 			QGuiApplication::clipboard()->setText(link->link); | ||||
| 			Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); | ||||
| 				const auto close = [=](auto&&) { | ||||
| 					if (*box) { | ||||
| 						(*box)->closeBox(); | ||||
| 					} | ||||
| 				}; | ||||
| 				peer->session().api().inviteLinks().revoke( | ||||
| 					peer, | ||||
| 					link->link, | ||||
| 					close); | ||||
| 			} | ||||
| 		}); | ||||
| 		*box = Ui::show( | ||||
| 			Box<ConfirmBox>(tr::lng_group_invite_about_new(tr::now), done), | ||||
| 			Ui::LayerOption::KeepOther); | ||||
| 	}); | ||||
| 
 | ||||
| 	auto link = rpl::duplicate( | ||||
| 		value | ||||
|  |  | |||
|  | @ -874,4 +874,4 @@ inviteLinkUserpics: GroupCallUserpics { | |||
| } | ||||
| inviteLinkUserpicsSkip: 8px; | ||||
| inviteLinkJoinedFont: font(14px); | ||||
| inviteLinkJoinedRowPadding: margins(0px, 18px, 0px, 0px); | ||||
| inviteLinkJoinedRowPadding: margins(0px, 18px, 0px, 8px); | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston