@@ -3490,7 +3490,7 @@ private func serializeGroupCallMessage(randomId: Int64, text: String, entities:
34903490 entityDict [ " _ " ] = " messageEntitySpoiler "
34913491 case let . CustomEmoji( _, fileId) :
34923492 entityDict [ " _ " ] = " messageEntityCustomEmoji "
3493- entityDict [ " document_id " ] = fileId
3493+ entityDict [ " document_id " ] = " \( fileId) "
34943494 case . Custom:
34953495 return nil
34963496 }
@@ -3515,7 +3515,29 @@ private func deserializeGroupCallMessage(data: Data) -> (randomId: Int64, text:
35153515 return nil
35163516 }
35173517
3518- guard let randomId = jsonObject [ " random_id " ] as? Int64 else {
3518+ func readInt32( _ value: Any ? ) -> Int32 ? {
3519+ if let int32 = value as? Int32 {
3520+ return int32
3521+ } else if let int = value as? Int {
3522+ return Int32 ( int)
3523+ } else if let string = value as? String , let int = Int32 ( string) {
3524+ return int
3525+ }
3526+ return nil
3527+ }
3528+
3529+ func readInt64( _ value: Any ? ) -> Int64 ? {
3530+ if let int64 = value as? Int64 {
3531+ return int64
3532+ } else if let int = value as? Int {
3533+ return Int64 ( int)
3534+ } else if let string = value as? String , let int = Int64 ( string) {
3535+ return int
3536+ }
3537+ return nil
3538+ }
3539+
3540+ guard let randomId = readInt64 ( jsonObject [ " random_id " ] ) else {
35193541 return nil
35203542 }
35213543
@@ -3538,37 +3560,10 @@ private func deserializeGroupCallMessage(data: Data) -> (randomId: Int64, text:
35383560 return nil
35393561 }
35403562
3541- let offset : Int32
3542- if let offsetInt32 = entityDict [ " offset " ] as? Int32 {
3543- offset = offsetInt32
3544- } else if let offsetInt = entityDict [ " offset " ] as? Int {
3545- guard offsetInt >= Int32 . min && offsetInt <= Int32 . max else {
3546- return nil
3547- }
3548- offset = Int32 ( offsetInt)
3549- } else if let offsetString = entityDict [ " offset " ] as? String , let offsetInt = Int ( offsetString) {
3550- guard offsetInt >= Int32 . min && offsetInt <= Int32 . max else {
3551- return nil
3552- }
3553- offset = Int32 ( offsetInt)
3554- } else {
3563+ guard let offset = readInt32 ( entityDict [ " offset " ] ) else {
35553564 return nil
35563565 }
3557-
3558- let length : Int32
3559- if let lengthInt32 = entityDict [ " length " ] as? Int32 {
3560- length = lengthInt32
3561- } else if let lengthInt = entityDict [ " length " ] as? Int {
3562- guard lengthInt >= 0 && lengthInt <= Int32 . max else {
3563- return nil
3564- }
3565- length = Int32 ( lengthInt)
3566- } else if let lengthString = entityDict [ " length " ] as? String , let lengthInt = Int ( lengthString) {
3567- guard lengthInt >= 0 && lengthInt <= Int32 . max else {
3568- return nil
3569- }
3570- length = Int32 ( lengthInt)
3571- } else {
3566+ guard let length = readInt32 ( entityDict [ " length " ] ) else {
35723567 return nil
35733568 }
35743569
@@ -3603,15 +3598,10 @@ private func deserializeGroupCallMessage(data: Data) -> (randomId: Int64, text:
36033598 }
36043599 messageEntityType = . TextUrl( url: url)
36053600 case " messageEntityMentionName " :
3606- let userIdValue : Int64
3607- if let userIdInt64 = entityDict [ " user_id " ] as? Int64 {
3608- userIdValue = userIdInt64
3609- } else if let userIdInt = entityDict [ " user_id " ] as? Int {
3610- userIdValue = Int64 ( userIdInt)
3611- } else {
3601+ guard let userId = readInt64 ( entityDict [ " user_id " ] ) else {
36123602 return nil
36133603 }
3614- let peerId = PeerId ( namespace: Namespaces . Peer. CloudUser, id: PeerId . Id. _internalFromInt64Value ( userIdValue ) )
3604+ let peerId = PeerId ( namespace: Namespaces . Peer. CloudUser, id: PeerId . Id. _internalFromInt64Value ( userId ) )
36153605 messageEntityType = . TextMention( peerId: peerId)
36163606 case " messageEntityPhone " :
36173607 messageEntityType = . PhoneNumber
@@ -3627,12 +3617,7 @@ private func deserializeGroupCallMessage(data: Data) -> (randomId: Int64, text:
36273617 case " messageEntitySpoiler " :
36283618 messageEntityType = . Spoiler
36293619 case " messageEntityCustomEmoji " :
3630- let documentId : Int64
3631- if let documentIdInt64 = entityDict [ " document_id " ] as? Int64 {
3632- documentId = documentIdInt64
3633- } else if let documentIdInt = entityDict [ " document_id " ] as? Int {
3634- documentId = Int64 ( documentIdInt)
3635- } else {
3620+ guard let documentId = readInt64 ( entityDict [ " document_id " ] ) else {
36363621 return nil
36373622 }
36383623 messageEntityType = . CustomEmoji( stickerPack: nil , fileId: documentId)
0 commit comments