Skip to content

Commit

Permalink
Add support for multiple users selection in bots peer requests
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Dec 21, 2023
1 parent c3f15c4 commit 6795603
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 121 deletions.
6 changes: 6 additions & 0 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -8719,6 +8719,7 @@ Sorry for the inconvenience.";
"CreateGroup.PublicLinkInfo" = "You can use **a-z**, **0-9** and underscores. Minimum length is **5** characters.";

"Notification.RequestedPeer" = "You shared %1$@ with %2$@.";
"Notification.RequestedPeerMultiple" = "You shared %1$@ with %2$@.";

"Conversation.ViewInChannel" = "View in Channel";

Expand Down Expand Up @@ -10829,3 +10830,8 @@ Sorry for the inconvenience.";

"Channel.Info.BoostLevelPlusBadge" = "Level %@+";
"Channel.Info.AppearanceItem" = "Appearance";

"RequestPeer.SelectUsers" = "Choose Users";
"RequestPeer.SelectUsers.SearchPlaceholder" = "Search";
"RequestPeer.ReachedMaximum_1" = "You can select up to %@ user.";
"RequestPeer.ReachedMaximum_any" = "You can select up to %@ users.";
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public enum ContactMultiselectionControllerMode {
case channelCreation
case chatSelection(ChatSelection)
case premiumGifting
case requestedUsersSelection
}

public enum ContactListFilter {
Expand Down
7 changes: 4 additions & 3 deletions submodules/TelegramApi/Sources/Api0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[42402760] = { return Api.InputStickerSet.parse_inputStickerSetAnimatedEmoji($0) }
dict[215889721] = { return Api.InputStickerSet.parse_inputStickerSetAnimatedEmojiAnimations($0) }
dict[-427863538] = { return Api.InputStickerSet.parse_inputStickerSetDice($0) }
dict[1232373075] = { return Api.InputStickerSet.parse_inputStickerSetEmojiChannelDefaultStatuses($0) }
dict[701560302] = { return Api.InputStickerSet.parse_inputStickerSetEmojiDefaultStatuses($0) }
dict[1153562857] = { return Api.InputStickerSet.parse_inputStickerSetEmojiDefaultTopicIcons($0) }
dict[80008398] = { return Api.InputStickerSet.parse_inputStickerSetEmojiGenericAnimations($0) }
Expand Down Expand Up @@ -447,7 +448,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[901503851] = { return Api.KeyboardButton.parse_keyboardButtonCallback($0) }
dict[1358175439] = { return Api.KeyboardButton.parse_keyboardButtonGame($0) }
dict[-59151553] = { return Api.KeyboardButton.parse_keyboardButtonRequestGeoLocation($0) }
dict[218842764] = { return Api.KeyboardButton.parse_keyboardButtonRequestPeer($0) }
dict[1406648280] = { return Api.KeyboardButton.parse_keyboardButtonRequestPeer($0) }
dict[-1318425559] = { return Api.KeyboardButton.parse_keyboardButtonRequestPhone($0) }
dict[-1144565411] = { return Api.KeyboardButton.parse_keyboardButtonRequestPoll($0) }
dict[-1598009252] = { return Api.KeyboardButton.parse_keyboardButtonSimpleWebView($0) }
Expand Down Expand Up @@ -503,7 +504,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1892568281] = { return Api.MessageAction.parse_messageActionPaymentSentMe($0) }
dict[-2132731265] = { return Api.MessageAction.parse_messageActionPhoneCall($0) }
dict[-1799538451] = { return Api.MessageAction.parse_messageActionPinMessage($0) }
dict[-25742243] = { return Api.MessageAction.parse_messageActionRequestedPeer($0) }
dict[827428507] = { return Api.MessageAction.parse_messageActionRequestedPeer($0) }
dict[1200788123] = { return Api.MessageAction.parse_messageActionScreenshotTaken($0) }
dict[-648257196] = { return Api.MessageAction.parse_messageActionSecureValuesSent($0) }
dict[455635795] = { return Api.MessageAction.parse_messageActionSecureValuesSentMe($0) }
Expand Down Expand Up @@ -1262,7 +1263,7 @@ public extension Api {
return parser(reader)
}
else {
telegramApiLog("Type constructor \(String(UInt32(bitPattern: signature), radix: 16, uppercase: false)) not found")
telegramApiLog("Type constructor \(String(signature, radix: 16, uppercase: false)) not found")
return nil
}
}
Expand Down
12 changes: 12 additions & 0 deletions submodules/TelegramApi/Sources/Api10.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public extension Api {
case inputStickerSetAnimatedEmoji
case inputStickerSetAnimatedEmojiAnimations
case inputStickerSetDice(emoticon: String)
case inputStickerSetEmojiChannelDefaultStatuses
case inputStickerSetEmojiDefaultStatuses
case inputStickerSetEmojiDefaultTopicIcons
case inputStickerSetEmojiGenericAnimations
Expand Down Expand Up @@ -352,6 +353,12 @@ public extension Api {
buffer.appendInt32(-427863538)
}
serializeString(emoticon, buffer: buffer, boxed: false)
break
case .inputStickerSetEmojiChannelDefaultStatuses:
if boxed {
buffer.appendInt32(1232373075)
}

break
case .inputStickerSetEmojiDefaultStatuses:
if boxed {
Expand Down Expand Up @@ -407,6 +414,8 @@ public extension Api {
return ("inputStickerSetAnimatedEmojiAnimations", [])
case .inputStickerSetDice(let emoticon):
return ("inputStickerSetDice", [("emoticon", emoticon as Any)])
case .inputStickerSetEmojiChannelDefaultStatuses:
return ("inputStickerSetEmojiChannelDefaultStatuses", [])
case .inputStickerSetEmojiDefaultStatuses:
return ("inputStickerSetEmojiDefaultStatuses", [])
case .inputStickerSetEmojiDefaultTopicIcons:
Expand Down Expand Up @@ -441,6 +450,9 @@ public extension Api {
return nil
}
}
public static func parse_inputStickerSetEmojiChannelDefaultStatuses(_ reader: BufferReader) -> InputStickerSet? {
return Api.InputStickerSet.inputStickerSetEmojiChannelDefaultStatuses
}
public static func parse_inputStickerSetEmojiDefaultStatuses(_ reader: BufferReader) -> InputStickerSet? {
return Api.InputStickerSet.inputStickerSetEmojiDefaultStatuses
}
Expand Down
18 changes: 11 additions & 7 deletions submodules/TelegramApi/Sources/Api11.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public extension Api {
case keyboardButtonCallback(flags: Int32, text: String, data: Buffer)
case keyboardButtonGame(text: String)
case keyboardButtonRequestGeoLocation(text: String)
case keyboardButtonRequestPeer(text: String, buttonId: Int32, peerType: Api.RequestPeerType)
case keyboardButtonRequestPeer(text: String, buttonId: Int32, peerType: Api.RequestPeerType, maxQuantity: Int32)
case keyboardButtonRequestPhone(text: String)
case keyboardButtonRequestPoll(flags: Int32, quiz: Api.Bool?, text: String)
case keyboardButtonSimpleWebView(text: String, url: String)
Expand Down Expand Up @@ -490,13 +490,14 @@ public extension Api {
}
serializeString(text, buffer: buffer, boxed: false)
break
case .keyboardButtonRequestPeer(let text, let buttonId, let peerType):
case .keyboardButtonRequestPeer(let text, let buttonId, let peerType, let maxQuantity):
if boxed {
buffer.appendInt32(218842764)
buffer.appendInt32(1406648280)
}
serializeString(text, buffer: buffer, boxed: false)
serializeInt32(buttonId, buffer: buffer, boxed: false)
peerType.serialize(buffer, true)
serializeInt32(maxQuantity, buffer: buffer, boxed: false)
break
case .keyboardButtonRequestPhone(let text):
if boxed {
Expand Down Expand Up @@ -582,8 +583,8 @@ public extension Api {
return ("keyboardButtonGame", [("text", text as Any)])
case .keyboardButtonRequestGeoLocation(let text):
return ("keyboardButtonRequestGeoLocation", [("text", text as Any)])
case .keyboardButtonRequestPeer(let text, let buttonId, let peerType):
return ("keyboardButtonRequestPeer", [("text", text as Any), ("buttonId", buttonId as Any), ("peerType", peerType as Any)])
case .keyboardButtonRequestPeer(let text, let buttonId, let peerType, let maxQuantity):
return ("keyboardButtonRequestPeer", [("text", text as Any), ("buttonId", buttonId as Any), ("peerType", peerType as Any), ("maxQuantity", maxQuantity as Any)])
case .keyboardButtonRequestPhone(let text):
return ("keyboardButtonRequestPhone", [("text", text as Any)])
case .keyboardButtonRequestPoll(let flags, let quiz, let text):
Expand Down Expand Up @@ -714,11 +715,14 @@ public extension Api {
if let signature = reader.readInt32() {
_3 = Api.parse(reader, signature: signature) as? Api.RequestPeerType
}
var _4: Int32?
_4 = reader.readInt32()
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
if _c1 && _c2 && _c3 {
return Api.KeyboardButton.keyboardButtonRequestPeer(text: _1!, buttonId: _2!, peerType: _3!)
let _c4 = _4 != nil
if _c1 && _c2 && _c3 && _c4 {
return Api.KeyboardButton.keyboardButtonRequestPeer(text: _1!, buttonId: _2!, peerType: _3!, maxQuantity: _4!)
}
else {
return nil
Expand Down
24 changes: 14 additions & 10 deletions submodules/TelegramApi/Sources/Api12.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public extension Api {
case messageActionPaymentSentMe(flags: Int32, currency: String, totalAmount: Int64, payload: Buffer, info: Api.PaymentRequestedInfo?, shippingOptionId: String?, charge: Api.PaymentCharge)
case messageActionPhoneCall(flags: Int32, callId: Int64, reason: Api.PhoneCallDiscardReason?, duration: Int32?)
case messageActionPinMessage
case messageActionRequestedPeer(buttonId: Int32, peer: Api.Peer)
case messageActionRequestedPeer(buttonId: Int32, peers: [Api.Peer])
case messageActionScreenshotTaken
case messageActionSecureValuesSent(types: [Api.SecureValueType])
case messageActionSecureValuesSentMe(values: [Api.SecureValue], credentials: Api.SecureCredentialsEncrypted)
Expand Down Expand Up @@ -920,12 +920,16 @@ public extension Api {
}

break
case .messageActionRequestedPeer(let buttonId, let peer):
case .messageActionRequestedPeer(let buttonId, let peers):
if boxed {
buffer.appendInt32(-25742243)
buffer.appendInt32(827428507)
}
serializeInt32(buttonId, buffer: buffer, boxed: false)
peer.serialize(buffer, true)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(peers.count))
for item in peers {
item.serialize(buffer, true)
}
break
case .messageActionScreenshotTaken:
if boxed {
Expand Down Expand Up @@ -1076,8 +1080,8 @@ public extension Api {
return ("messageActionPhoneCall", [("flags", flags as Any), ("callId", callId as Any), ("reason", reason as Any), ("duration", duration as Any)])
case .messageActionPinMessage:
return ("messageActionPinMessage", [])
case .messageActionRequestedPeer(let buttonId, let peer):
return ("messageActionRequestedPeer", [("buttonId", buttonId as Any), ("peer", peer as Any)])
case .messageActionRequestedPeer(let buttonId, let peers):
return ("messageActionRequestedPeer", [("buttonId", buttonId as Any), ("peers", peers as Any)])
case .messageActionScreenshotTaken:
return ("messageActionScreenshotTaken", [])
case .messageActionSecureValuesSent(let types):
Expand Down Expand Up @@ -1505,14 +1509,14 @@ public extension Api {
public static func parse_messageActionRequestedPeer(_ reader: BufferReader) -> MessageAction? {
var _1: Int32?
_1 = reader.readInt32()
var _2: Api.Peer?
if let signature = reader.readInt32() {
_2 = Api.parse(reader, signature: signature) as? Api.Peer
var _2: [Api.Peer]?
if let _ = reader.readInt32() {
_2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Peer.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
if _c1 && _c2 {
return Api.MessageAction.messageActionRequestedPeer(buttonId: _1!, peer: _2!)
return Api.MessageAction.messageActionRequestedPeer(buttonId: _1!, peers: _2!)
}
else {
return nil
Expand Down
27 changes: 23 additions & 4 deletions submodules/TelegramApi/Sources/Api32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ public extension Api.functions.account {
})
}
}
public extension Api.functions.account {
static func getChannelDefaultEmojiStatuses(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.account.EmojiStatuses>) {
let buffer = Buffer()
buffer.appendInt32(1999087573)
serializeInt64(hash, buffer: buffer, boxed: false)
return (FunctionDescription(name: "account.getChannelDefaultEmojiStatuses", parameters: [("hash", String(describing: hash))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.account.EmojiStatuses? in
let reader = BufferReader(buffer)
var result: Api.account.EmojiStatuses?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.account.EmojiStatuses
}
return result
})
}
}
public extension Api.functions.account {
static func getChannelRestrictedStatusEmojis(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.EmojiList>) {
let buffer = Buffer()
Expand Down Expand Up @@ -6750,14 +6765,18 @@ public extension Api.functions.messages {
}
}
public extension Api.functions.messages {
static func sendBotRequestedPeer(peer: Api.InputPeer, msgId: Int32, buttonId: Int32, requestedPeer: Api.InputPeer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
static func sendBotRequestedPeer(peer: Api.InputPeer, msgId: Int32, buttonId: Int32, requestedPeers: [Api.InputPeer]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer()
buffer.appendInt32(-29831141)
buffer.appendInt32(-1850552224)
peer.serialize(buffer, true)
serializeInt32(msgId, buffer: buffer, boxed: false)
serializeInt32(buttonId, buffer: buffer, boxed: false)
requestedPeer.serialize(buffer, true)
return (FunctionDescription(name: "messages.sendBotRequestedPeer", parameters: [("peer", String(describing: peer)), ("msgId", String(describing: msgId)), ("buttonId", String(describing: buttonId)), ("requestedPeer", String(describing: requestedPeer))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(requestedPeers.count))
for item in requestedPeers {
item.serialize(buffer, true)
}
return (FunctionDescription(name: "messages.sendBotRequestedPeer", parameters: [("peer", String(describing: peer)), ("msgId", String(describing: msgId)), ("buttonId", String(describing: buttonId)), ("requestedPeers", String(describing: requestedPeers))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer)
var result: Api.Updates?
if let signature = reader.readInt32() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension ReplyMarkupButton {
self.init(title: text, titleWhenForwarded: nil, action: .openWebView(url: url, simple: false))
case let .keyboardButtonSimpleWebView(text, url):
self.init(title: text, titleWhenForwarded: nil, action: .openWebView(url: url, simple: true))
case let .keyboardButtonRequestPeer(text, buttonId, peerType):
case let .keyboardButtonRequestPeer(text, buttonId, peerType, maxQuantity):
let mappedPeerType: ReplyMarkupButtonRequestPeerType
switch peerType {
case let .requestPeerTypeUser(_, bot, premium):
Expand All @@ -88,7 +88,7 @@ extension ReplyMarkupButton {
botAdminRights: botAdminRights.flatMap(TelegramChatAdminRights.init(apiAdminRights:))
))
}
self.init(title: text, titleWhenForwarded: nil, action: .requestPeer(peerType: mappedPeerType, buttonId: buttonId))
self.init(title: text, titleWhenForwarded: nil, action: .requestPeer(peerType: mappedPeerType, buttonId: buttonId, maxQuantity: maxQuantity))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
for id in userIds {
result.append(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id)))
}
case let .messageActionRequestedPeer(_, peer):
result.append(peer.peerId)
case let .messageActionRequestedPeer(_, peers):
result.append(contentsOf: peers.map(\.peerId))
case let .messageActionGiftCode(_, boostPeer, _, _, _, _, _, _):
if let boostPeer = boostPeer {
result.append(boostPeer.peerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
return TelegramMediaAction(action: .topicEdited(components: components))
case let .messageActionSuggestProfilePhoto(photo):
return TelegramMediaAction(action: .suggestedProfilePhoto(image: telegramMediaImageFromApiPhoto(photo)))
case let .messageActionRequestedPeer(buttonId, peer):
return TelegramMediaAction(action: .requestedPeer(buttonId: buttonId, peerId: peer.peerId))
case let .messageActionRequestedPeer(buttonId, peers):
return TelegramMediaAction(action: .requestedPeer(buttonId: buttonId, peerIds: peers.map { $0.peerId }))
case let .messageActionSetChatWallPaper(flags, wallpaper):
if (flags & (1 << 0)) != 0 {
return TelegramMediaAction(action: .setSameChatWallpaper(wallpaper: TelegramWallpaper(apiWallpaper: wallpaper)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ extension StickerPackReference {
self = .iconStatusEmoji
case .inputStickerSetEmojiDefaultTopicIcons:
self = .iconTopicEmoji
case .inputStickerSetEmojiChannelDefaultStatuses:
return nil
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/TelegramCore/Sources/State/Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public class BoxedMessage: NSObject {

public class Serialization: NSObject, MTSerialization {
public func currentLayer() -> UInt {
return 168
return 169
}

public func parseMessage(_ data: Data!) -> Any! {
Expand Down
Loading

0 comments on commit 6795603

Please sign in to comment.