Add voice chat invite link sharing for non-participants in public groups

This commit is contained in:
Ilya Laktyushin 2021-03-25 00:13:08 +05:00
parent 5f3bab6261
commit 1fd84c653b
4 changed files with 3830 additions and 3806 deletions

View File

@ -6317,3 +6317,6 @@ Sorry for the inconvenience.";
"VoiceChat.EditBioText" = "Any details such as age, occupation or city.";
"VoiceChat.EditBioPlaceholder" = "Bio";
"VoiceChat.EditBioSave" = "Save";
"VoiceChat.SendPublicLinkText" = "%1$@ isn't a member of \"%2$@\" yet. Send them a public invite link instead?";
"VoiceChat.SendPublicLinkSend" = "Send";

View File

@ -945,12 +945,11 @@ public final class VoiceChatController: ViewController {
}
if let groupPeer = groupPeer as? TelegramChannel {
var canInvite = true
var canInviteMembers = true
if case .broadcast = groupPeer.info, !(groupPeer.addressName?.isEmpty ?? true) {
canInvite = false
canInviteMembers = false
}
if !canInvite {
if !canInviteMembers {
if let inviteLinks = inviteLinks {
strongSelf.presentShare(inviteLinks)
}
@ -963,7 +962,7 @@ public final class VoiceChatController: ViewController {
filters.append(.disable(Array(currentCallMembers.map { $0.peer.id })))
}
if let groupPeer = groupPeer as? TelegramChannel {
if !groupPeer.hasPermission(.inviteMembers) {
if !groupPeer.hasPermission(.inviteMembers) && inviteLinks?.listenerLink == nil {
filters.append(.excludeNonMembers)
}
} else if let groupPeer = groupPeer as? TelegramGroup {
@ -981,7 +980,6 @@ public final class VoiceChatController: ViewController {
}
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
if peer.id == strongSelf.callState?.myPeerId {
return
}
@ -991,6 +989,22 @@ public final class VoiceChatController: ViewController {
if strongSelf.call.invitePeer(participant.peer.id) {
strongSelf.presentUndoOverlay(content: .invitedToVoiceChat(context: strongSelf.context, peer: participant.peer, text: strongSelf.presentationData.strings.VoiceChat_InvitedPeerText(peer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0), action: { _ in return false })
}
} else {
if let groupPeer = groupPeer as? TelegramChannel, let listenerLink = inviteLinks?.listenerLink, !groupPeer.hasPermission(.inviteMembers) {
let text = strongSelf.presentationData.strings.VoiceChat_SendPublicLinkText(peer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder), groupPeer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0
strongSelf.controller?.present(textAlertController(context: strongSelf.context, forceTheme: strongSelf.darkTheme, title: nil, text: text, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .defaultAction, title: presentationData.strings.VoiceChat_SendPublicLinkSend, action: { [weak self] in
dismissController?()
if let strongSelf = self {
let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: listenerLink, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)])
|> deliverOnMainQueue).start(next: { [weak self] _ in
if let strongSelf = self {
strongSelf.presentUndoOverlay(content: .forward(savedMessages: false, text: strongSelf.presentationData.strings.UserInfo_LinkForwardTooltip_Chat_One(peer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0), action: { _ in return true })
}
})
}
})]), in: .window(.root))
} else {
let text: String
if let groupPeer = groupPeer as? TelegramChannel, case .broadcast = groupPeer.info {
@ -1141,6 +1155,7 @@ public final class VoiceChatController: ViewController {
}
})]), in: .window(.root))
}
}
})
controller.copyInviteLink = {
dismissController?()
@ -1151,7 +1166,9 @@ public final class VoiceChatController: ViewController {
let callPeerId = strongSelf.call.peerId
let _ = (strongSelf.context.account.postbox.transaction { transaction -> String? in
if let peer = transaction.getPeer(callPeerId), let addressName = peer.addressName, !addressName.isEmpty {
if let link = inviteLinks?.listenerLink {
return link
} else if let peer = transaction.getPeer(callPeerId), let addressName = peer.addressName, !addressName.isEmpty {
return "https://t.me/\(addressName)"
} else if let cachedData = transaction.getPeerCachedData(peerId: callPeerId) {
if let cachedData = cachedData as? CachedChannelData {