Update API

This commit is contained in:
Ali 2020-11-29 23:47:21 +04:00
parent 705ad11e0c
commit 0b07e34439
8 changed files with 60 additions and 30 deletions

View File

@ -47,7 +47,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case phoneNumberRequest
case geoProximityReached(from: PeerId, to: PeerId, distance: Int32)
case groupPhoneCall(callId: Int64, accessHash: Int64, duration: Int32?)
case inviteToGroupPhoneCall(callId: Int64, accessHash: Int64, peerId: PeerId)
case inviteToGroupPhoneCall(callId: Int64, accessHash: Int64, peerIds: [PeerId])
public init(decoder: PostboxDecoder) {
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
@ -103,7 +103,13 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case 22:
self = .groupPhoneCall(callId: decoder.decodeInt64ForKey("callId", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), duration: decoder.decodeOptionalInt32ForKey("duration"))
case 23:
self = .inviteToGroupPhoneCall(callId: decoder.decodeInt64ForKey("callId", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), peerId: PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)))
var peerIds: [PeerId] = []
if let peerId = decoder.decodeOptionalInt64ForKey("peerId") {
peerIds.append(PeerId(peerId))
} else {
peerIds = decoder.decodeInt64ArrayForKey("peerIds").map(PeerId.init)
}
self = .inviteToGroupPhoneCall(callId: decoder.decodeInt64ForKey("callId", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), peerIds: peerIds)
default:
self = .unknown
}
@ -203,11 +209,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
} else {
encoder.encodeNil(forKey: "duration")
}
case let .inviteToGroupPhoneCall(callId, accessHash, peerId):
case let .inviteToGroupPhoneCall(callId, accessHash, peerIds):
encoder.encodeInt32(23, forKey: "_rawValue")
encoder.encodeInt64(callId, forKey: "callId")
encoder.encodeInt64(accessHash, forKey: "accessHash")
encoder.encodeInt64(peerId.toInt64(), forKey: "peerId")
encoder.encodeInt64Array(peerIds.map { $0.toInt64() }, forKey: "peerIds")
}
}
@ -225,8 +231,8 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
return [channelId]
case let .geoProximityReached(from, to, _):
return [from, to]
case let .inviteToGroupPhoneCall(_, _, peerId):
return [peerId]
case let .inviteToGroupPhoneCall(_, _, peerIds):
return peerIds
default:
return []
}

View File

@ -787,7 +787,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-202219658] = { return Api.MessageAction.parse_messageActionContactSignUp($0) }
dict[-1730095465] = { return Api.MessageAction.parse_messageActionGeoProximityReached($0) }
dict[2047704898] = { return Api.MessageAction.parse_messageActionGroupCall($0) }
dict[254144570] = { return Api.MessageAction.parse_messageActionInviteToGroupCall($0) }
dict[1991897370] = { return Api.MessageAction.parse_messageActionInviteToGroupCall($0) }
dict[1399245077] = { return Api.PhoneCall.parse_phoneCallEmpty($0) }
dict[462375633] = { return Api.PhoneCall.parse_phoneCallWaiting($0) }
dict[-2014659757] = { return Api.PhoneCall.parse_phoneCallRequested($0) }

View File

@ -21451,7 +21451,7 @@ public extension Api {
case messageActionContactSignUp
case messageActionGeoProximityReached(fromId: Api.Peer, toId: Api.Peer, distance: Int32)
case messageActionGroupCall(flags: Int32, call: Api.InputGroupCall, duration: Int32?)
case messageActionInviteToGroupCall(call: Api.InputGroupCall, userId: Int32)
case messageActionInviteToGroupCall(call: Api.InputGroupCall, users: [Int32])
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
@ -21639,12 +21639,16 @@ public extension Api {
call.serialize(buffer, true)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(duration!, buffer: buffer, boxed: false)}
break
case .messageActionInviteToGroupCall(let call, let userId):
case .messageActionInviteToGroupCall(let call, let users):
if boxed {
buffer.appendInt32(254144570)
buffer.appendInt32(1991897370)
}
call.serialize(buffer, true)
serializeInt32(userId, buffer: buffer, boxed: false)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(users.count))
for item in users {
serializeInt32(item, buffer: buffer, boxed: false)
}
break
}
}
@ -21701,8 +21705,8 @@ public extension Api {
return ("messageActionGeoProximityReached", [("fromId", fromId), ("toId", toId), ("distance", distance)])
case .messageActionGroupCall(let flags, let call, let duration):
return ("messageActionGroupCall", [("flags", flags), ("call", call), ("duration", duration)])
case .messageActionInviteToGroupCall(let call, let userId):
return ("messageActionInviteToGroupCall", [("call", call), ("userId", userId)])
case .messageActionInviteToGroupCall(let call, let users):
return ("messageActionInviteToGroupCall", [("call", call), ("users", users)])
}
}
@ -22016,12 +22020,14 @@ public extension Api {
if let signature = reader.readInt32() {
_1 = Api.parse(reader, signature: signature) as? Api.InputGroupCall
}
var _2: Int32?
_2 = reader.readInt32()
var _2: [Int32]?
if let _ = reader.readInt32() {
_2 = Api.parseVector(reader, elementSignature: -1471112230, elementType: Int32.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
if _c1 && _c2 {
return Api.MessageAction.messageActionInviteToGroupCall(call: _1!, userId: _2!)
return Api.MessageAction.messageActionInviteToGroupCall(call: _1!, users: _2!)
}
else {
return nil

View File

@ -7303,12 +7303,16 @@ public extension Api {
})
}
public static func inviteToGroupCall(call: Api.InputGroupCall, userId: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
public static func inviteToGroupCall(call: Api.InputGroupCall, users: [Api.InputUser]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer()
buffer.appendInt32(-580284540)
buffer.appendInt32(2067345760)
call.serialize(buffer, true)
userId.serialize(buffer, true)
return (FunctionDescription(name: "phone.inviteToGroupCall", parameters: [("call", call), ("userId", userId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(users.count))
for item in users {
item.serialize(buffer, true)
}
return (FunctionDescription(name: "phone.inviteToGroupCall", parameters: [("call", call), ("users", users)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer)
var result: Api.Updates?
if let signature = reader.readInt32() {

View File

@ -1001,7 +1001,7 @@ public func inviteToGroupCall(account: Account, callId: Int64, accessHash: Int64
return .fail(.generic)
}
return account.network.request(Api.functions.phone.inviteToGroupCall(call: .inputGroupCall(id: callId, accessHash: accessHash), userId: apiUser))
return account.network.request(Api.functions.phone.inviteToGroupCall(call: .inputGroupCall(id: callId, accessHash: accessHash), users: [apiUser]))
|> mapError { _ -> InviteToGroupCallError in
return .generic
}

View File

@ -188,7 +188,7 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
}
switch action {
case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall, .messageActionInviteToGroupCall:
case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall:
break
case let .messageActionChannelMigrateFrom(_, chatId):
result.append(PeerId(namespace: Namespaces.Peer.CloudGroup, id: chatId))
@ -209,6 +209,10 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
case let .messageActionGeoProximityReached(fromId, toId, _):
result.append(fromId.peerId)
result.append(toId.peerId)
case let .messageActionInviteToGroupCall(_, userIds):
for id in userIds {
result.append(PeerId(namespace: Namespaces.Peer.CloudUser, id: id))
}
}
return result

View File

@ -64,10 +64,12 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
case let .inputGroupCall(id, accessHash):
return TelegramMediaAction(action: .groupPhoneCall(callId: id, accessHash: accessHash, duration: duration))
}
case let .messageActionInviteToGroupCall(call, userId):
case let .messageActionInviteToGroupCall(call, userIds):
switch call {
case let .inputGroupCall(id, accessHash):
return TelegramMediaAction(action: .inviteToGroupPhoneCall(callId: id, accessHash: accessHash, peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)))
return TelegramMediaAction(action: .inviteToGroupPhoneCall(callId: id, accessHash: accessHash, peerIds: userIds.map { userId in
PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
}))
}
}
}

View File

@ -459,14 +459,22 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
} else {
attributedString = addAttributesToStringWithRanges(strings.Notification_ProximityReached(message.peers[fromId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? "", distanceString, message.peers[toId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? ""), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, fromId), (2, toId)]))
}
case let .inviteToGroupPhoneCall(_, _, userId):
if message.author?.id == accountPeerId {
attributedString = addAttributesToStringWithRanges(strings.Notification_VoiceChatInvitationByYou( message.peers[userId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? ""), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, userId)]))
} else if userId == accountPeerId {
attributedString = addAttributesToStringWithRanges(strings.Notification_VoiceChatInvitationForYou(authorName), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]))
case let .inviteToGroupPhoneCall(_, _, peerIds):
var attributePeerIds: [(Int, PeerId?)] = [(0, message.author?.id)]
let resultTitleString: (String, [(Int, NSRange)])
if peerIds.count == 1 {
if peerIds[0] == accountPeerId {
attributePeerIds.append((1, peerIds.first))
resultTitleString = strings.Notification_VoiceChatInvitationForYou(authorName)
} else {
attributePeerIds.append((1, peerIds.first))
resultTitleString = strings.Notification_VoiceChatInvitation(authorName, peerDebugDisplayTitles(peerIds, message.peers))
}
} else {
attributedString = addAttributesToStringWithRanges(strings.Notification_VoiceChatInvitation(authorName, message.peers[userId]?.displayTitle(strings: strings, displayOrder: nameDisplayOrder) ?? ""), body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id), (1, userId)]))
resultTitleString = strings.Notification_VoiceChatInvitation(authorName, peerDebugDisplayTitles(peerIds, message.peers))
}
attributedString = addAttributesToStringWithRanges(resultTitleString, body: bodyAttributes, argumentAttributes: peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: attributePeerIds))
case .unknown:
attributedString = nil
}