Skip to content

Commit e7f6d60

Browse files
committed
Various improvements
1 parent f4aaf08 commit e7f6d60

File tree

9 files changed

+154
-102
lines changed

9 files changed

+154
-102
lines changed

Telegram/Telegram-iOS/en.lproj/Localizable.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13223,3 +13223,6 @@ Sorry for the inconvenience.";
1322313223
"Gift.Send.SendShort" = "Send";
1322413224

1322513225
"Premium.EmojiStatus.Proceed" = "Unlock Emoji Statuses";
13226+
13227+
"Stars.Transaction.Subscription.CancelledByBot" = "Your subscription was cancelled by the bot.";
13228+
"Stars.Transaction.Subscription.CancelledByBusiness" = "Your subscription was cancelled by the business.";

submodules/TelegramCore/Sources/TelegramEngine/Payments/Stars.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ private extension StarsContext.State.Subscription {
568568
if (apiFlags & (1 << 2)) != 0 {
569569
flags.insert(.missingBalance)
570570
}
571+
if (apiFlags & (1 << 7)) != 0 {
572+
flags.insert(.isCancelledByBot)
573+
}
571574
self.init(flags: flags, id: id, peer: EnginePeer(peer), untilDate: untilDate, pricing: StarsSubscriptionPricing(apiStarsSubscriptionPricing: pricing), inviteHash: inviteHash, title: title, photo: photo.flatMap(TelegramMediaWebFile.init), invoiceSlug: invoiceSlug)
572575
}
573576
}
@@ -719,6 +722,7 @@ public final class StarsContext {
719722
public static let isCancelled = Flags(rawValue: 1 << 0)
720723
public static let canRefulfill = Flags(rawValue: 1 << 1)
721724
public static let missingBalance = Flags(rawValue: 1 << 2)
725+
public static let isCancelledByBot = Flags(rawValue: 1 << 3)
722726
}
723727

724728
public let flags: Flags

submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ private func contentNodeMessagesAndClassesForItem(_ item: ChatMessageItem) -> ([
149149
messageWithCaptionToAdd = (message, itemAttributes)
150150
}
151151
result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default)))
152+
} else if let _ = media as? TelegramMediaWebFile {
153+
result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default)))
152154
} else if let story = media as? TelegramMediaStory {
153155
if story.isMention {
154156
if let storyItem = message.associatedStories[story.storyId], storyItem.data.isEmpty {

submodules/TelegramUI/Components/Chat/ChatMessageInteractiveMediaNode/Sources/ChatMessageInteractiveMediaNode.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,8 @@ public final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTr
19201920
imageDimensions = dimensions.cgSize
19211921
} else if let image = media as? TelegramMediaWebFile, let dimensions = image.dimensions {
19221922
imageDimensions = dimensions.cgSize
1923+
} else if let file = media as? TelegramMediaWebFile, let dimensions = file.dimensions {
1924+
imageDimensions = dimensions.cgSize
19231925
}
19241926

19251927
if let imageDimensions = imageDimensions {

submodules/TelegramUI/Components/Chat/ChatMessageMediaBubbleContentNode/Sources/ChatMessageMediaBubbleContentNode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,19 @@ public class ChatMessageMediaBubbleContentNode: ChatMessageBubbleContentNode {
183183
} else if let invoice = media as? TelegramMediaInvoice {
184184
selectedMedia = invoice
185185
extendedMedia = invoice.extendedMedia
186-
}
187-
else if let paidContent = media as? TelegramMediaPaidContent {
186+
} else if let paidContent = media as? TelegramMediaPaidContent {
188187
selectedMedia = paidContent
189188
if case let .mosaic(_, _, index) = preparePosition, let index {
190189
extendedMedia = paidContent.extendedMedia[index]
191190
selectedMediaIndex = index
192191
} else {
193192
extendedMedia = paidContent.extendedMedia.first
194193
}
194+
} else if let webFile = media as? TelegramMediaWebFile {
195+
selectedMedia = webFile
196+
if item.presentationData.isPreview {
197+
automaticDownload = .full
198+
}
195199
}
196200
}
197201
}

submodules/TelegramUI/Components/Stars/StarsAvatarComponent/Sources/StarsAvatarComponent.swift

Lines changed: 105 additions & 93 deletions
Large diffs are not rendered by default.

submodules/TelegramUI/Components/Stars/StarsTransactionScreen/Sources/StarsTransactionScreen.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
226226
var isSubscriber = false
227227
var isSubscriptionFee = false
228228
var isBotSubscription = false
229+
var isBusinessSubscription = false
229230
var isCancelled = false
230231
var isReaction = false
231232
var giveawayMessageId: MessageId?
@@ -259,8 +260,12 @@ private final class StarsTransactionSheetContent: CombinedComponent {
259260
transactionPeer = .peer(peer)
260261
isSubscriber = true
261262
case let .subscription(subscription):
262-
if case let .user(user) = subscription.peer, user.botInfo != nil {
263-
isBotSubscription = true
263+
if case let .user(user) = subscription.peer {
264+
if user.botInfo != nil {
265+
isBotSubscription = true
266+
} else {
267+
isBusinessSubscription = true
268+
}
264269
}
265270
if let title = subscription.title {
266271
titleText = title
@@ -318,18 +323,30 @@ private final class StarsTransactionSheetContent: CombinedComponent {
318323
}
319324
isCancelled = true
320325
} else {
321-
if subscription.flags.contains(.isCancelled) {
326+
if subscription.flags.contains(.isCancelledByBot) {
327+
if case let .user(user) = subscription.peer, user.botInfo == nil {
328+
statusText = strings.Stars_Transaction_Subscription_CancelledByBusiness
329+
} else {
330+
statusText = strings.Stars_Transaction_Subscription_CancelledByBot
331+
}
332+
statusIsDestructive = true
333+
buttonText = strings.Common_OK
334+
isCancelled = true
335+
} else if subscription.flags.contains(.isCancelled) {
322336
statusText = strings.Stars_Transaction_Subscription_Cancelled
323337
statusIsDestructive = true
324338
if date > Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) {
325339
buttonText = strings.Stars_Transaction_Subscription_Renew
326340
} else {
327-
if let _ = subscription.inviteHash, !isKicked {
341+
if let _ = subscription.invoiceSlug {
342+
buttonText = strings.Stars_Transaction_Subscription_Renew
343+
} else if let _ = subscription.inviteHash, !isKicked {
328344
buttonText = strings.Stars_Transaction_Subscription_JoinAgainChannel
329345
} else {
330346
buttonText = strings.Common_OK
331347
}
332348
}
349+
isCancelled = true
333350
} else {
334351
statusText = strings.Stars_Transaction_Subscription_Active(stringForMediumDate(timestamp: subscription.untilDate, strings: strings, dateTimeFormat: dateTimeFormat, withTime: false)).string
335352
cancelButtonText = strings.Stars_Transaction_Subscription_Cancel
@@ -710,6 +727,8 @@ private final class StarsTransactionSheetContent: CombinedComponent {
710727
if isBotSubscription {
711728
//TODO:localize
712729
title = "Bot"
730+
} else if isBusinessSubscription {
731+
title = "Business"
713732
} else {
714733
title = strings.Stars_Transaction_Subscription_Subscription
715734
}

submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsScreen.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,10 @@ final class StarsTransactionsScreenComponent: Component {
708708
))
709709
))
710710
var nameGroupComponent: AnyComponent<Empty>
711-
if let _ = subscription.photo {
711+
if let photo = subscription.photo {
712712
nameGroupComponent = AnyComponent(
713713
HStack([
714-
AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(RoundedRectangle(color: .lightGray, cornerRadius: 3.0, size: CGSize(width: 19.0, height: 19.0)))),
714+
AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(StarsAvatarComponent(context: component.context, theme: environment.theme, peer: nil, photo: photo, media: [], backgroundColor: .clear, size: CGSize(width: 19.0, height: 19.0)))),
715715
AnyComponentWithIdentity(id: AnyHashable(1), component: nameComponent)
716716
], spacing: 6.0)
717717
)
@@ -1055,6 +1055,10 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
10551055
let _ = self.context.engine.payments.fulfillStarsSubscription(peerId: context.account.peerId, subscriptionId: subscription.id).startStandalone()
10561056
updated = true
10571057
}
1058+
if let _ = subscription.inviteHash, !subscription.flags.contains(.isCancelledByBot) {
1059+
let _ = self.context.engine.payments.fulfillStarsSubscription(peerId: context.account.peerId, subscriptionId: subscription.id).startStandalone()
1060+
updated = true
1061+
}
10581062
if !updated {
10591063
if subscription.flags.contains(.isCancelled) {
10601064
self.subscriptionsContext.updateSubscription(id: subscription.id, cancel: false)
@@ -1065,6 +1069,8 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer {
10651069
} else {
10661070
if let inviteHash = subscription.inviteHash {
10671071
self.context.sharedContext.handleTextLinkAction(context: self.context, peerId: nil, navigateDisposable: self.navigateDisposable, controller: self, action: .tap, itemLink: .url(url: "https://t.me/+\(inviteHash)", concealed: false))
1072+
} else if let invoiceSlug = subscription.invoiceSlug {
1073+
self.context.sharedContext.handleTextLinkAction(context: self.context, peerId: nil, navigateDisposable: self.navigateDisposable, controller: self, action: .tap, itemLink: .url(url: "https://t.me/$\(invoiceSlug)", concealed: false))
10681074
}
10691075
}
10701076
})

submodules/TelegramUI/Sources/TextLinkHandling.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: EnginePeer.Id?, n
100100
let sourceLocation = InstantPageSourceLocation(userLocation: peerId.flatMap(MediaResourceUserLocation.peer) ?? .other, peerType: .group)
101101
let browserController = context.sharedContext.makeInstantPageController(context: context, webPage: webPage, anchor: anchor, sourceLocation: sourceLocation)
102102
(controller.navigationController as? NavigationController)?.pushViewController(browserController, animated: true)
103-
case .boost, .chatFolder, .join:
103+
case .boost, .chatFolder, .join, .invoice:
104104
if let navigationController = controller.navigationController as? NavigationController {
105105
openResolvedUrlImpl(result, context: context, urlContext: peerId.flatMap { .chat(peerId: $0, message: nil, updatedPresentationData: nil) } ?? .generic, navigationController: navigationController, forceExternal: false, forceUpdate: false, openPeer: { peer, navigateToPeer in
106106
openResolvedPeerImpl(peer, navigateToPeer)

0 commit comments

Comments
 (0)