Skip to content

Commit 1439c8c

Browse files
committed
Various fixes
1 parent 567ca06 commit 1439c8c

File tree

11 files changed

+62
-44
lines changed

11 files changed

+62
-44
lines changed

submodules/AccountContext/Sources/GalleryController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public enum GalleryControllerItemSource {
1212
}
1313

1414
public final class GalleryControllerActionInteraction {
15-
public let openUrl: (String, Bool) -> Void
15+
public let openUrl: (String, Bool, Bool) -> Void
1616
public let openUrlIn: (String) -> Void
1717
public let openPeerMention: (String) -> Void
1818
public let openPeer: (EnginePeer) -> Void
@@ -25,7 +25,7 @@ public final class GalleryControllerActionInteraction {
2525
public let updateCanReadHistory: (Bool) -> Void
2626

2727
public init(
28-
openUrl: @escaping (String, Bool) -> Void,
28+
openUrl: @escaping (String, Bool, Bool) -> Void,
2929
openUrlIn: @escaping (String) -> Void,
3030
openPeerMention: @escaping (String) -> Void,
3131
openPeer: @escaping (EnginePeer) -> Void,

submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, ASScroll
783783
if let (attributeText, fullText) = self.textNode.attributeSubstring(name: TelegramTextAttributes.URL, index: index) {
784784
concealed = !doesUrlMatchText(url: url, text: attributeText, fullText: fullText)
785785
}
786-
return .url(url: url, concealed: concealed, dismiss: true)
786+
return .url(url: url, concealed: concealed, forceExternal: false, dismiss: true)
787787
} else if let peerMention = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerMention)] as? TelegramPeerMention {
788788
return .peerMention(peerMention.peerId, peerMention.mention)
789789
} else if let peerName = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.PeerTextMention)] as? String {

submodules/GalleryUI/Sources/GalleryController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public func galleryItemForEntry(
386386
}
387387
}
388388
if content == nil, let webEmbedContent = WebEmbedVideoContent(userLocation: .peer(message.id.peerId), webPage: webpage, webpageContent: webpageContent, forcedTimestamp: timecode.flatMap(Int.init), openUrl: { url in
389-
performAction(.url(url: url.absoluteString, concealed: false, dismiss: true))
389+
performAction(.url(url: url.absoluteString, concealed: false, forceExternal: false, dismiss: true))
390390
}) {
391391
content = webEmbedContent
392392
}
@@ -504,7 +504,7 @@ private enum GalleryMessageHistoryView {
504504
}
505505

506506
public enum GalleryControllerInteractionTapAction {
507-
case url(url: String, concealed: Bool, dismiss: Bool)
507+
case url(url: String, concealed: Bool, forceExternal: Bool, dismiss: Bool)
508508
case textMention(String)
509509
case peerMention(PeerId, String)
510510
case botCommand(String)
@@ -960,14 +960,14 @@ public class GalleryController: ViewController, StandalonePresentableController,
960960

961961
performActionImpl = { [weak self] action in
962962
if let strongSelf = self {
963-
if case let .url(_, _, dismiss) = action, !dismiss {
963+
if case let .url(_, _, _, dismiss) = action, !dismiss {
964964
} else if case .timecode = action {
965965
} else {
966966
strongSelf.dismiss(forceAway: false)
967967
}
968968
switch action {
969-
case let .url(url, concealed, _):
970-
strongSelf.actionInteraction?.openUrl(url, concealed)
969+
case let .url(url, concealed, forceExternal, _):
970+
strongSelf.actionInteraction?.openUrl(url, concealed, forceExternal)
971971
case let .textMention(mention):
972972
strongSelf.actionInteraction?.openPeerMention(mention)
973973
case let .peerMention(peerId, _):
@@ -996,7 +996,7 @@ public class GalleryController: ViewController, StandalonePresentableController,
996996
presentationData = presentationData.withUpdated(theme: defaultDarkColorPresentationTheme)
997997
}
998998
switch action {
999-
case let .url(url, _, _):
999+
case let .url(url, _, forceExternal, _):
10001000
var cleanUrl = url
10011001
var canAddToReadingList = true
10021002
let canOpenIn = availableOpenInOptions(context: strongSelf.context, item: .url(url: url)).count > 1
@@ -1031,7 +1031,7 @@ public class GalleryController: ViewController, StandalonePresentableController,
10311031
strongSelf.actionInteraction?.openUrlIn(url)
10321032
} else {
10331033
strongSelf.dismiss(forceAway: false)
1034-
strongSelf.actionInteraction?.openUrl(url, false)
1034+
strongSelf.actionInteraction?.openUrl(url, false, forceExternal)
10351035
}
10361036
}
10371037
}))

submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
435435
guard let strongSelf = self, let message = strongSelf.message else {
436436
return
437437
}
438-
strongSelf.footerContentNode.openActionOptions?(.url(url: payload, concealed: true, dismiss: true), message)
438+
strongSelf.footerContentNode.openActionOptions?(.url(url: payload, concealed: true, forceExternal: false, dismiss: true), message)
439439
}
440440
recognizedContentNode.alpha = 0.0
441441
recognizedContentNode.frame = CGRect(origin: CGPoint(), size: size)

submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private final class UniversalVideoGalleryItemOverlayNode: GalleryOverlayContentN
368368
self.updateLayout(size: validLayout.size, metrics: validLayout.metrics, insets: validLayout.insets, isHidden: false, transition: .immediate)
369369
}
370370
context.engine.messages.markAdAction(opaqueId: ad.opaqueId, media: false, fullscreen: false)
371-
self.performAction?(.url(url: ad.url, concealed: false, dismiss: false))
371+
self.performAction?(.url(url: ad.url, concealed: false, forceExternal: true, dismiss: false))
372372
}
373373
},
374374
moreAction: { [weak self] sourceNode in

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,14 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
660660
} else {
661661
authorName = item.message.author.flatMap { EnginePeer($0) }?.compactDisplayTitle ?? ""
662662
}
663-
if isSelfGift {
663+
if isStoryEntity {
664+
title = uniqueGift.title
665+
} else if isSelfGift {
664666
title = item.presentationData.strings.Notification_StarGift_Self_Title
665667
} else if item.message.id.peerId.isTelegramNotifications {
666668
title = item.presentationData.strings.Notification_StarGift_TitleShort
667669
} else {
668-
title = isStoryEntity ? uniqueGift.title : item.presentationData.strings.Notification_StarGift_Title(authorName).string
670+
title = item.presentationData.strings.Notification_StarGift_Title(authorName).string
669671
}
670672
text = isStoryEntity ? "**\(item.presentationData.strings.Notification_StarGift_Collectible) #\(presentationStringsFormattedNumber(uniqueGift.number, item.presentationData.dateTimeFormat.groupingSeparator))**" : "**\(uniqueGift.title) #\(presentationStringsFormattedNumber(uniqueGift.number, item.presentationData.dateTimeFormat.groupingSeparator))**"
671673
ribbonTitle = isStoryEntity ? "" : item.presentationData.strings.Notification_StarGift_Gift

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftPurchaseAlertController.swift

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -135,31 +135,11 @@ private final class GiftPurchaseAlertContentNode: AlertContentNode {
135135
}
136136

137137
override func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) -> CGSize {
138+
let containerSize = size
138139
var size = size
139140
size.width = min(size.width, 270.0)
140-
self.validLayout = size
141-
142-
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
143-
144-
var origin: CGPoint = CGPoint(x: 0.0, y: 20.0)
145-
146-
var resellPrice: CurrencyAmount?
147-
if let actionNode = self.actionNodes.first {
148-
switch self.currency {
149-
case .stars:
150-
if let resellAmount = self.gift.resellAmounts?.first(where: { $0.currency == .stars }) {
151-
resellPrice = resellAmount
152-
actionNode.action = TextAlertAction(type: .defaultAction, title: self.strings.Gift_Buy_Confirm_BuyFor(Int32(resellAmount.amount.value)), action: actionNode.action.action)
153-
}
154-
case .ton:
155-
if let resellAmount = self.gift.resellAmounts?.first(where: { $0.currency == .ton }) {
156-
resellPrice = resellAmount
157-
let valueString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat)
158-
actionNode.action = TextAlertAction(type: .defaultAction, title: self.strings.Gift_Buy_Confirm_BuyForTon(valueString).string, action: actionNode.action.action)
159-
}
160-
}
161-
}
162141

142+
var origin = CGPoint(x: 0.0, y: 20.0)
163143
if self.gift.resellForTonOnly {
164144
let headerSize = self.header.update(
165145
transition: .immediate,
@@ -173,6 +153,7 @@ private final class GiftPurchaseAlertContentNode: AlertContentNode {
173153
environment: {},
174154
containerSize: CGSize(width: size.width - 32.0, height: size.height)
175155
)
156+
176157
let headerFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - headerSize.width) / 2.0), y: origin.y), size: headerSize)
177158
if let view = self.header.view {
178159
if view.superview == nil {
@@ -226,8 +207,11 @@ private final class GiftPurchaseAlertContentNode: AlertContentNode {
226207
}
227208
)),
228209
environment: {},
229-
containerSize: CGSize(width: size.width - 16.0 * 2.0, height: 100.0)
210+
containerSize: CGSize(width: containerSize.width - 16.0 * 2.0, height: 100.0)
230211
)
212+
213+
size.width = min(containerSize.width, max(270.0, headerSize.width + 32.0))
214+
231215
let headerFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - headerSize.width) / 2.0), y: origin.y), size: headerSize)
232216
if let view = self.header.view {
233217
if view.superview == nil {
@@ -238,6 +222,27 @@ private final class GiftPurchaseAlertContentNode: AlertContentNode {
238222
origin.y += headerSize.height + 17.0
239223
}
240224

225+
self.validLayout = size
226+
227+
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
228+
229+
var resellPrice: CurrencyAmount?
230+
if let actionNode = self.actionNodes.first {
231+
switch self.currency {
232+
case .stars:
233+
if let resellAmount = self.gift.resellAmounts?.first(where: { $0.currency == .stars }) {
234+
resellPrice = resellAmount
235+
actionNode.action = TextAlertAction(type: .defaultAction, title: self.strings.Gift_Buy_Confirm_BuyFor(Int32(resellAmount.amount.value)), action: actionNode.action.action)
236+
}
237+
case .ton:
238+
if let resellAmount = self.gift.resellAmounts?.first(where: { $0.currency == .ton }) {
239+
resellPrice = resellAmount
240+
let valueString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat)
241+
actionNode.action = TextAlertAction(type: .defaultAction, title: self.strings.Gift_Buy_Confirm_BuyForTon(valueString).string, action: actionNode.action.action)
242+
}
243+
}
244+
}
245+
241246
let avatarSize = CGSize(width: 60.0, height: 60.0)
242247
self.avatarNode.updateSize(size: avatarSize)
243248

@@ -495,9 +500,13 @@ public func giftPurchaseAlertController(
495500

496501
if !gift.resellForTonOnly {
497502
Queue.mainQueue().after(0.3) {
498-
if let headerView = contentNode?.header.view {
503+
if let headerView = contentNode?.header.view as? TabSelectorComponent.View {
499504
let absoluteFrame = headerView.convert(headerView.bounds, to: nil)
500-
let location = CGRect(origin: CGPoint(x: absoluteFrame.minX + floor(absoluteFrame.width * 0.75), y: absoluteFrame.minY - 8.0), size: CGSize())
505+
var originX = absoluteFrame.width * 0.75
506+
if let itemFrame = headerView.frameForItem(AnyHashable(1)) {
507+
originX = itemFrame.midX
508+
}
509+
let location = CGRect(origin: CGPoint(x: absoluteFrame.minX + floor(originX), y: absoluteFrame.minY - 8.0), size: CGSize())
501510
let tooltipController = TooltipScreen(account: context.account, sharedContext: context.sharedContext, text: .plain(text: presentationData.strings.Gift_Buy_PayInTon_Tooltip), style: .wide, location: .point(location, .bottom), displayDuration: .default, inset: 16.0, shouldDismissOnTouch: { _, _ in
502511
return .dismiss(consume: false)
503512
})

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,9 +5599,9 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
55995599
}, callPeer: { peerId, isVideo in
56005600
}, openConferenceCall: { _ in
56015601
}, enqueueMessage: { _ in
5602-
}, sendSticker: nil, sendEmoji: nil, setupTemporaryHiddenMedia: { _, _, _ in }, chatAvatarHiddenMedia: { _, _ in }, actionInteraction: GalleryControllerActionInteraction(openUrl: { [weak self] url, concealed in
5602+
}, sendSticker: nil, sendEmoji: nil, setupTemporaryHiddenMedia: { _, _, _ in }, chatAvatarHiddenMedia: { _, _ in }, actionInteraction: GalleryControllerActionInteraction(openUrl: { [weak self] url, concealed, forceExternal in
56035603
if let strongSelf = self {
5604-
strongSelf.openUrl(url: url, concealed: false, external: false)
5604+
strongSelf.openUrl(url: url, concealed: false, external: forceExternal)
56055605
}
56065606
}, openUrlIn: { [weak self] url in
56075607
if let strongSelf = self {

submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ final class StorageUsageScreenComponent: Component {
28012801
sendEmoji: nil,
28022802
setupTemporaryHiddenMedia: { _, _, _ in },
28032803
chatAvatarHiddenMedia: { _, _ in },
2804-
actionInteraction: GalleryControllerActionInteraction(openUrl: { [weak self] url, concealed in
2804+
actionInteraction: GalleryControllerActionInteraction(openUrl: { [weak self] url, concealed, forceExternal in
28052805
guard let self else {
28062806
return
28072807
}

submodules/TelegramUI/Components/TabSelectorComponent/Sources/TabSelectorComponent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ public final class TabSelectorComponent: Component {
498498
public func scrollToEnd() {
499499
self.setContentOffset(CGPoint(x: self.contentSize.width - self.bounds.width, y: 0.0), animated: true)
500500
}
501+
502+
public func frameForItem(_ id: AnyHashable) -> CGRect? {
503+
if let item = self.visibleItems[id] {
504+
return item.convert(item.bounds, to: self)
505+
}
506+
return nil
507+
}
501508

502509
func update(component: TabSelectorComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
503510
let selectionColorUpdated = component.colors.selection != self.component?.colors.selection

0 commit comments

Comments
 (0)