Various fixes

This commit is contained in:
Ilya Laktyushin 2022-06-21 15:57:37 +05:00
parent 009d2445d2
commit a22cf29e19
14 changed files with 71 additions and 47 deletions

View File

@ -188,7 +188,7 @@ private var declaredEncodables: Void = {
declareEncodable(ForwardOptionsMessageAttribute.self, f: { ForwardOptionsMessageAttribute(decoder: $0) })
declareEncodable(SendAsMessageAttribute.self, f: { SendAsMessageAttribute(decoder: $0) })
declareEncodable(AudioTranscriptionMessageAttribute.self, f: { AudioTranscriptionMessageAttribute(decoder: $0) })
declareEncodable(NonPremiumMessageAttribute.self, f: { NonPremiumMessageAttribute(decoder: $0) })
return
}()

View File

@ -18,7 +18,7 @@ extension BotInfo {
switch apiBotInfo {
case let .botInfo(_, _, description, descriptionPhoto, descriptionDocument, apiCommands, apiMenuButton):
let photo: TelegramMediaImage? = descriptionPhoto.flatMap(telegramMediaImageFromApiPhoto)
let video: TelegramMediaFile? = descriptionDocument.flatMap { telegramMediaFileFromApiDocument($0, noPremium: false) }
let video: TelegramMediaFile? = descriptionDocument.flatMap(telegramMediaFileFromApiDocument)
var commands: [BotCommand] = []
if let apiCommands = apiCommands {
commands = apiCommands.map { command in

View File

@ -256,48 +256,48 @@ func apiMessageAssociatedMessageIds(_ message: Api.Message) -> [MessageId]? {
return nil
}
func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (Media?, Int32?) {
func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerId:PeerId) -> (Media?, Int32?, Bool?) {
if let media = media {
switch media {
case let .messageMediaPhoto(_, photo, ttlSeconds):
if let photo = photo {
if let mediaImage = telegramMediaImageFromApiPhoto(photo) {
return (mediaImage, ttlSeconds)
return (mediaImage, ttlSeconds, nil)
}
} else {
return (TelegramMediaExpiredContent(data: .image), nil)
return (TelegramMediaExpiredContent(data: .image), nil, nil)
}
case let .messageMediaContact(phoneNumber, firstName, lastName, vcard, userId):
let contactPeerId: PeerId? = userId == 0 ? nil : PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
let mediaContact = TelegramMediaContact(firstName: firstName, lastName: lastName, phoneNumber: phoneNumber, peerId: contactPeerId, vCardData: vcard.isEmpty ? nil : vcard)
return (mediaContact, nil)
return (mediaContact, nil, nil)
case let .messageMediaGeo(geo):
let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil, heading: nil)
return (mediaMap, nil)
return (mediaMap, nil, nil)
case let .messageMediaVenue(geo, title, address, provider, venueId, venueType):
let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: title, address: address, provider: provider, venueId: venueId, venueType: venueType, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil, heading: nil)
return (mediaMap, nil)
return (mediaMap, nil, nil)
case let .messageMediaGeoLive(_, geo, heading, period, proximityNotificationRadius):
let mediaMap = telegramMediaMapFromApiGeoPoint(geo, title: nil, address: nil, provider: nil, venueId: nil, venueType: nil, liveBroadcastingTimeout: period, liveProximityNotificationRadius: proximityNotificationRadius, heading: heading)
return (mediaMap, nil)
return (mediaMap, nil, nil)
case let .messageMediaDocument(flags, document, ttlSeconds):
if let document = document {
if let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0) {
return (mediaFile, ttlSeconds)
if let mediaFile = telegramMediaFileFromApiDocument(document) {
return (mediaFile, ttlSeconds, (flags & (1 << 3)) != 0)
}
} else {
return (TelegramMediaExpiredContent(data: .file), nil)
return (TelegramMediaExpiredContent(data: .file), nil, nil)
}
case let .messageMediaWebPage(webpage):
if let mediaWebpage = telegramMediaWebpageFromApiWebpage(webpage, url: nil) {
return (mediaWebpage, nil)
return (mediaWebpage, nil, nil)
}
case .messageMediaUnsupported:
return (TelegramMediaUnsupported(), nil)
return (TelegramMediaUnsupported(), nil, nil)
case .messageMediaEmpty:
break
case let .messageMediaGame(game):
return (TelegramMediaGame(apiGame: game), nil)
return (TelegramMediaGame(apiGame: game), nil, nil)
case let .messageMediaInvoice(flags, title, description, photo, receiptMsgId, currency, totalAmount, startParam):
var parsedFlags = TelegramMediaInvoiceFlags()
if (flags & (1 << 3)) != 0 {
@ -306,7 +306,7 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI
if (flags & (1 << 1)) != 0 {
parsedFlags.insert(.shippingAddressRequested)
}
return (TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags), nil)
return (TelegramMediaInvoice(title: title, description: description, photo: photo.flatMap(TelegramMediaWebFile.init), receiptMessageId: receiptMsgId.flatMap { MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }, currency: currency, totalAmount: totalAmount, startParam: startParam, flags: parsedFlags), nil, nil)
case let .messageMediaPoll(poll, results):
switch poll {
case let .poll(id, flags, question, answers, closePeriod, _):
@ -322,14 +322,14 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI
} else {
kind = .poll(multipleAnswers: (flags & (1 << 2)) != 0)
}
return (TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0, deadlineTimeout: closePeriod), nil)
return (TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0, deadlineTimeout: closePeriod), nil, nil)
}
case let .messageMediaDice(value, emoticon):
return (TelegramMediaDice(emoji: emoticon, value: value), nil)
return (TelegramMediaDice(emoji: emoticon, value: value), nil, nil)
}
}
return (nil, nil)
return (nil, nil, nil)
}
func messageTextEntitiesFromApiEntities(_ entities: [Api.MessageEntity]) -> [MessageTextEntity] {
@ -474,7 +474,7 @@ extension StoreMessage {
var consumableContent: (Bool, Bool)? = nil
if let media = media {
let (mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
let (mediaValue, expirationTimer, nonPremium) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
if let mediaValue = mediaValue {
medias.append(mediaValue)
@ -483,6 +483,10 @@ extension StoreMessage {
consumableContent = (true, false)
}
if let nonPremium = nonPremium, nonPremium {
attributes.append(NonPremiumMessageAttribute())
}
}
}

View File

@ -141,14 +141,11 @@ func telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: Int32,
return (immediateThumbnailData, representations)
}
func telegramMediaFileFromApiDocument(_ document: Api.Document, noPremium: Bool = false) -> TelegramMediaFile? {
func telegramMediaFileFromApiDocument(_ document: Api.Document) -> TelegramMediaFile? {
switch document {
case let .document(_, id, accessHash, fileReference, _, mimeType, size, thumbs, videoThumbs, dcId, attributes):
var parsedAttributes = telegramMediaFileAttributesFromApiAttributes(attributes)
parsedAttributes.append(.hintIsValidated)
if noPremium {
parsedAttributes.append(.NoPremium)
}
let (immediateThumbnail, previewRepresentations) = telegramMediaFileThumbnailRepresentationsFromApiSizes(datacenterId: dcId, documentId: id, accessHash: accessHash, fileReference: fileReference.makeData(), sizes: thumbs ?? [])

View File

@ -784,8 +784,8 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
|> mapError { _ -> PendingMessageUploadError in return .generic }
|> mapToSignal { result -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> in
switch result {
case let .messageMediaDocument(flags, document, _):
if let document = document, let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0), let resource = mediaFile.resource as? CloudDocumentMediaResource, let fileReference = resource.fileReference {
case let .messageMediaDocument(_, document, _):
if let document = document, let mediaFile = telegramMediaFileFromApiDocument(document), let resource = mediaFile.resource as? CloudDocumentMediaResource, let fileReference = resource.fileReference {
return maybeCacheUploadedResource(postbox: postbox, key: referenceKey, result: .content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaDocument(flags: 0, id: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: fileReference)), ttlSeconds: nil, query: nil), text), reuploadInfo: nil)), media: mediaFile)
}
default:

View File

@ -162,9 +162,9 @@ public func standaloneUploadedFile(account: Account, peerId: PeerId, text: Strin
|> mapError { _ -> StandaloneUploadMediaError in return .generic }
|> mapToSignal { media -> Signal<StandaloneUploadMediaEvent, StandaloneUploadMediaError> in
switch media {
case let .messageMediaDocument(flags, document, _):
case let .messageMediaDocument(_, document, _):
if let document = document {
if let mediaFile = telegramMediaFileFromApiDocument(document, noPremium: (flags & (1 << 3)) != 0) {
if let mediaFile = telegramMediaFileFromApiDocument(document) {
return .single(.result(.media(.standalone(media: mediaFile))))
}
}

View File

@ -1048,7 +1048,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
let messageText = text
var medias: [Media] = []
let (mediaValue, expirationTimer) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
let (mediaValue, expirationTimer, nonPremium) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
if let mediaValue = mediaValue {
medias.append(mediaValue)
}
@ -1056,6 +1056,10 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
attributes.append(AutoclearTimeoutMessageAttribute(timeout: expirationTimer, countdownBeginTime: nil))
}
if let nonPremium = nonPremium, nonPremium {
attributes.append(NonPremiumMessageAttribute())
}
if type.hasPrefix("auth") {
updatedState.authorizationListUpdated = true
}

View File

@ -117,7 +117,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes
text = updatedMessage.text
forwardInfo = updatedMessage.forwardInfo
} else if case let .updateShortSentMessage(_, _, _, _, _, apiMedia, entities, ttlPeriod) = result {
let (mediaValue, _) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId)
let (mediaValue, _, nonPremium) = textMediaAndExpirationTimerFromApiMedia(apiMedia, currentMessage.id.peerId)
if let mediaValue = mediaValue {
media = [mediaValue]
} else {
@ -140,6 +140,11 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes
updatedAttributes.append(AutoremoveTimeoutMessageAttribute(timeout: ttlPeriod, countdownBeginTime: updatedTimestamp))
}
updatedAttributes = updatedAttributes.filter({ !($0 is NonPremiumMessageAttribute) })
if let nonPremium = nonPremium, nonPremium {
updatedAttributes.append(NonPremiumMessageAttribute())
}
if Namespaces.Message.allScheduled.contains(message.id.namespace) && updatedId.namespace == Namespaces.Message.Cloud {
for i in 0 ..< updatedAttributes.count {
if updatedAttributes[i] is OutgoingScheduleInfoMessageAttribute {

View File

@ -0,0 +1,16 @@
import Foundation
import Postbox
public class NonPremiumMessageAttribute: MessageAttribute {
public var associatedMessageIds: [MessageId] = []
public init() {
}
required public init(decoder: PostboxDecoder) {
}
public func encode(_ encoder: PostboxEncoder) {
}
}

View File

@ -14,10 +14,6 @@ public extension TelegramEngine {
return _internal_acceptTermsOfService(account: self.account, id: id)
}
public func resetAccountDueTermsOfService() -> Signal<Void, NoError> {
return _internal_resetAccountDueTermsOfService(network: self.account.network)
}
public func requestChangeAccountPhoneNumberVerification(phoneNumber: String) -> Signal<ChangeAccountPhoneNumberData, RequestChangeAccountPhoneNumberVerificationError> {
return _internal_requestChangeAccountPhoneNumberVerification(account: self.account, phoneNumber: phoneNumber)
}

View File

@ -44,12 +44,6 @@ func _internal_acceptTermsOfService(account: Account, id: String) -> Signal<Void
}
}
func _internal_resetAccountDueTermsOfService(network: Network) -> Signal<Void, NoError> {
return network.request(Api.functions.account.deleteAccount(reason: "Decline ToS update"))
|> retryRequest
|> map { _ in return }
}
func managedTermsOfServiceUpdates(postbox: Postbox, network: Network, stateManager: AccountStateManager) -> Signal<Void, NoError> {
let poll = network.request(Api.functions.help.getTermsOfServiceUpdate())
|> retryRequest

View File

@ -90,8 +90,8 @@ public extension TelegramEngine {
return _internal_updateTwoStepVerificationPassword(network: self.account.network, currentPassword: currentPassword, updatedPassword: updatedPassword)
}
public func deleteAccount() -> Signal<Never, DeleteAccountError> {
return self.account.network.request(Api.functions.account.deleteAccount(reason: "GDPR"))
public func deleteAccount(reason: String) -> Signal<Never, DeleteAccountError> {
return self.account.network.request(Api.functions.account.deleteAccount(reason: reason))
|> mapError { _ -> DeleteAccountError in
return .generic
}

View File

@ -486,7 +486,7 @@ final class AuthorizedApplicationContext {
}
let accountId = strongSelf.context.account.id
let accountManager = strongSelf.context.sharedContext.accountManager
let _ = (strongSelf.context.engine.auth.deleteAccount()
let _ = (strongSelf.context.engine.auth.deleteAccount(reason: "GDPR")
|> deliverOnMainQueue).start(error: { _ in
guard let strongSelf = self else {
return

View File

@ -1614,12 +1614,12 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
private var playedPremiumStickerAnimation = false
func playPremiumStickerAnimation() {
guard !self.playedPremiumStickerAnimation, let file = self.telegramFile, file.isPremiumSticker, let effect = file.videoThumbnails.first else {
guard !self.playedPremiumStickerAnimation, let item = self.item, let file = self.telegramFile, file.isPremiumSticker, let effect = file.videoThumbnails.first else {
return
}
self.playedPremiumStickerAnimation = true
if file.attributes.contains(where: { attribute in
if case .NoPremium = attribute {
if item.message.attributes.contains(where: { attribute in
if attribute is NonPremiumMessageAttribute {
return true
} else {
return false
@ -1768,7 +1768,15 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
if let item = self.item, self.imageNode.frame.contains(location) {
if let file = self.telegramFile {
if file.isPremiumSticker {
let noPremium = item.message.attributes.contains(where: { attribute in
if attribute is NonPremiumMessageAttribute {
return true
} else {
return false
}
})
if file.isPremiumSticker && !noPremium {
return .optionalAction({
if self.additionalAnimationNodes.isEmpty {
self.playedPremiumStickerAnimation = false