Skip to content

Commit a8c7b21

Browse files
committed
Various improvements
1 parent f696cfb commit a8c7b21

File tree

23 files changed

+975
-454
lines changed

23 files changed

+975
-454
lines changed

submodules/Camera/Sources/Camera.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ private final class CameraContext {
173173
self.positionValue = configuration.position
174174
self._positionPromise = ValuePromise<Camera.Position>(configuration.position)
175175

176+
#if targetEnvironment(simulator)
177+
#else
176178
self.setDualCameraEnabled(configuration.isDualEnabled, change: false)
177-
179+
#endif
180+
178181
NotificationCenter.default.addObserver(
179182
self,
180183
selector: #selector(self.sessionRuntimeError),

submodules/Components/SheetComponent/Sources/SheetComponent.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
6767
public let externalState: ExternalState?
6868
public let animateOut: ActionSlot<Action<()>>
6969
public let onPan: () -> Void
70+
public let willDismiss: () -> Void
7071

7172
public init(
7273
content: AnyComponent<ChildEnvironmentType>,
@@ -76,7 +77,8 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
7677
isScrollEnabled: Bool = true,
7778
externalState: ExternalState? = nil,
7879
animateOut: ActionSlot<Action<()>>,
79-
onPan: @escaping () -> Void = {}
80+
onPan: @escaping () -> Void = {},
81+
willDismiss: @escaping () -> Void = {}
8082
) {
8183
self.content = content
8284
self.backgroundColor = backgroundColor
@@ -86,6 +88,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
8688
self.externalState = externalState
8789
self.animateOut = animateOut
8890
self.onPan = onPan
91+
self.willDismiss = willDismiss
8992
}
9093

9194
public static func ==(lhs: SheetComponent, rhs: SheetComponent) -> Bool {
@@ -222,6 +225,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
222225
let currentContentOffset = scrollView.contentOffset
223226
targetContentOffset.pointee = currentContentOffset
224227
if velocity.y > 300.0 {
228+
self.component?.willDismiss()
225229
self.animateOut(initialVelocity: initialVelocity, completion: {
226230
self.dismiss?(false)
227231
})
@@ -233,6 +237,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
233237
scrollView.setContentOffset(CGPoint(x: 0.0, y: scrollView.contentSize.height - scrollView.contentInset.top), animated: true)
234238
}
235239
} else {
240+
self.component?.willDismiss()
236241
self.animateOut(initialVelocity: initialVelocity, completion: {
237242
self.dismiss?(false)
238243
})

submodules/TelegramApi/Sources/Api0.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
467467
dict[583071445] = { return Api.InputReplyTo.parse_inputReplyToMessage($0) }
468468
dict[1484862010] = { return Api.InputReplyTo.parse_inputReplyToStory($0) }
469469
dict[-251549057] = { return Api.InputSavedStarGift.parse_inputSavedStarGiftChat($0) }
470+
dict[545636920] = { return Api.InputSavedStarGift.parse_inputSavedStarGiftSlug($0) }
470471
dict[1764202389] = { return Api.InputSavedStarGift.parse_inputSavedStarGiftUser($0) }
471472
dict[1399317950] = { return Api.InputSecureFile.parse_inputSecureFile($0) }
472473
dict[859091184] = { return Api.InputSecureFile.parse_inputSecureFileUploaded($0) }

submodules/TelegramApi/Sources/Api12.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ public extension Api {
367367
public extension Api {
368368
indirect enum InputSavedStarGift: TypeConstructorDescription {
369369
case inputSavedStarGiftChat(peer: Api.InputPeer, savedId: Int64)
370+
case inputSavedStarGiftSlug(slug: String)
370371
case inputSavedStarGiftUser(msgId: Int32)
371372

372373
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
@@ -378,6 +379,12 @@ public extension Api {
378379
peer.serialize(buffer, true)
379380
serializeInt64(savedId, buffer: buffer, boxed: false)
380381
break
382+
case .inputSavedStarGiftSlug(let slug):
383+
if boxed {
384+
buffer.appendInt32(545636920)
385+
}
386+
serializeString(slug, buffer: buffer, boxed: false)
387+
break
381388
case .inputSavedStarGiftUser(let msgId):
382389
if boxed {
383390
buffer.appendInt32(1764202389)
@@ -391,6 +398,8 @@ public extension Api {
391398
switch self {
392399
case .inputSavedStarGiftChat(let peer, let savedId):
393400
return ("inputSavedStarGiftChat", [("peer", peer as Any), ("savedId", savedId as Any)])
401+
case .inputSavedStarGiftSlug(let slug):
402+
return ("inputSavedStarGiftSlug", [("slug", slug as Any)])
394403
case .inputSavedStarGiftUser(let msgId):
395404
return ("inputSavedStarGiftUser", [("msgId", msgId as Any)])
396405
}
@@ -412,6 +421,17 @@ public extension Api {
412421
return nil
413422
}
414423
}
424+
public static func parse_inputSavedStarGiftSlug(_ reader: BufferReader) -> InputSavedStarGift? {
425+
var _1: String?
426+
_1 = parseString(reader)
427+
let _c1 = _1 != nil
428+
if _c1 {
429+
return Api.InputSavedStarGift.inputSavedStarGiftSlug(slug: _1!)
430+
}
431+
else {
432+
return nil
433+
}
434+
}
415435
public static func parse_inputSavedStarGiftUser(_ reader: BufferReader) -> InputSavedStarGift? {
416436
var _1: Int32?
417437
_1 = reader.readInt32()

submodules/TelegramApi/Sources/Api38.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9791,12 +9791,12 @@ public extension Api.functions.payments {
97919791
}
97929792
}
97939793
public extension Api.functions.payments {
9794-
static func updateStarGiftPrice(slug: String, resellStars: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
9794+
static func updateStarGiftPrice(stargift: Api.InputSavedStarGift, resellStars: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
97959795
let buffer = Buffer()
9796-
buffer.appendInt32(-489360582)
9797-
serializeString(slug, buffer: buffer, boxed: false)
9796+
buffer.appendInt32(1001301217)
9797+
stargift.serialize(buffer, true)
97989798
serializeInt64(resellStars, buffer: buffer, boxed: false)
9799-
return (FunctionDescription(name: "payments.updateStarGiftPrice", parameters: [("slug", String(describing: slug)), ("resellStars", String(describing: resellStars))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
9799+
return (FunctionDescription(name: "payments.updateStarGiftPrice", parameters: [("stargift", String(describing: stargift)), ("resellStars", String(describing: resellStars))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
98009800
let reader = BufferReader(buffer)
98019801
var result: Api.Updates?
98029802
if let signature = reader.readInt32() {

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

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,14 +1509,14 @@ private final class ProfileGiftsContextImpl {
15091509
}
15101510
}
15111511

1512-
func updateStarGiftResellPrice(slug: String, price: Int64?) {
1512+
func updateStarGiftResellPrice(reference: StarGiftReference, price: Int64?) {
15131513
self.actionDisposable.set(
1514-
_internal_updateStarGiftResalePrice(account: self.account, slug: slug, price: price).startStrict()
1514+
_internal_updateStarGiftResalePrice(account: self.account, reference: reference, price: price).startStrict()
15151515
)
15161516

15171517

15181518
if let index = self.gifts.firstIndex(where: { gift in
1519-
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
1519+
if gift.reference == reference {
15201520
return true
15211521
}
15221522
return false
@@ -1529,7 +1529,7 @@ private final class ProfileGiftsContextImpl {
15291529
}
15301530

15311531
if let index = self.filteredGifts.firstIndex(where: { gift in
1532-
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
1532+
if gift.reference == reference {
15331533
return true
15341534
}
15351535
return false
@@ -1939,9 +1939,9 @@ public final class ProfileGiftsContext {
19391939
}
19401940
}
19411941

1942-
public func updateStarGiftResellPrice(slug: String, price: Int64?) {
1942+
public func updateStarGiftResellPrice(reference: StarGiftReference, price: Int64?) {
19431943
self.impl.with { impl in
1944-
impl.updateStarGiftResellPrice(slug: slug, price: price)
1944+
impl.updateStarGiftResellPrice(reference: reference, price: price)
19451945
}
19461946
}
19471947

@@ -2082,10 +2082,12 @@ public enum StarGiftReference: Equatable, Hashable, Codable {
20822082
case messageId
20832083
case peerId
20842084
case id
2085+
case slug
20852086
}
20862087

20872088
case message(messageId: EngineMessage.Id)
20882089
case peer(peerId: EnginePeer.Id, id: Int64)
2090+
case slug(slug: String)
20892091

20902092
public enum DecodingError: Error {
20912093
case generic
@@ -2100,6 +2102,8 @@ public enum StarGiftReference: Equatable, Hashable, Codable {
21002102
self = .message(messageId: try container.decode(EngineMessage.Id.self, forKey: .messageId))
21012103
case 1:
21022104
self = .peer(peerId: try container.decode(EnginePeer.Id.self, forKey: .peerId), id: try container.decode(Int64.self, forKey: .id))
2105+
case 2:
2106+
self = .slug(slug: try container.decode(String.self, forKey: .slug))
21032107
default:
21042108
throw DecodingError.generic
21052109
}
@@ -2116,6 +2120,9 @@ public enum StarGiftReference: Equatable, Hashable, Codable {
21162120
try container.encode(1 as Int32, forKey: .type)
21172121
try container.encode(peerId, forKey: .peerId)
21182122
try container.encode(id, forKey: .id)
2123+
case let .slug(slug):
2124+
try container.encode(2 as Int32, forKey: .type)
2125+
try container.encode(slug, forKey: .slug)
21192126
}
21202127
}
21212128
}
@@ -2130,6 +2137,8 @@ extension StarGiftReference {
21302137
return nil
21312138
}
21322139
return .inputSavedStarGiftChat(peer: inputPeer, savedId: id)
2140+
case let .slug(slug):
2141+
return .inputSavedStarGiftSlug(slug: slug)
21332142
}
21342143
}
21352144
}
@@ -2265,19 +2274,27 @@ func _internal_toggleStarGiftsNotifications(account: Account, peerId: EnginePeer
22652274
}
22662275
}
22672276

2268-
func _internal_updateStarGiftResalePrice(account: Account, slug: String, price: Int64?) -> Signal<Never, NoError> {
2269-
return account.network.request(Api.functions.payments.updateStarGiftPrice(slug: slug, resellStars: price ?? 0))
2270-
|> map(Optional.init)
2271-
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
2272-
return .single(nil)
2277+
func _internal_updateStarGiftResalePrice(account: Account, reference: StarGiftReference, price: Int64?) -> Signal<Never, NoError> {
2278+
return account.postbox.transaction { transaction in
2279+
return reference.apiStarGiftReference(transaction: transaction)
22732280
}
2274-
|> mapToSignal { updates -> Signal<Void, NoError> in
2275-
if let updates {
2276-
account.stateManager.addUpdates(updates)
2281+
|> mapToSignal { starGift in
2282+
guard let starGift else {
2283+
return .complete()
22772284
}
2278-
return .complete()
2285+
return account.network.request(Api.functions.payments.updateStarGiftPrice(stargift: starGift, resellStars: price ?? 0))
2286+
|> map(Optional.init)
2287+
|> `catch` { _ -> Signal<Api.Updates?, NoError> in
2288+
return .single(nil)
2289+
}
2290+
|> mapToSignal { updates -> Signal<Void, NoError> in
2291+
if let updates {
2292+
account.stateManager.addUpdates(updates)
2293+
}
2294+
return .complete()
2295+
}
2296+
|> ignoreValues
22792297
}
2280-
|> ignoreValues
22812298
}
22822299

22832300
public extension StarGift.UniqueGift {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public extension TelegramEngine {
153153
return _internal_toggleStarGiftsNotifications(account: self.account, peerId: peerId, enabled: enabled)
154154
}
155155

156-
public func updateStarGiftResalePrice(slug: String, price: Int64?) -> Signal<Never, NoError> {
157-
return _internal_updateStarGiftResalePrice(account: self.account, slug: slug, price: price)
156+
public func updateStarGiftResalePrice(reference: StarGiftReference, price: Int64?) -> Signal<Never, NoError> {
157+
return _internal_updateStarGiftResalePrice(account: self.account, reference: reference, price: price)
158158
}
159159
}
160160
}

submodules/TelegramUI/Components/Gifts/GiftItemComponent/Sources/GiftItemComponent.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ public final class GiftItemComponent: Component {
866866
return (TelegramTextAttributes.URL, contents)
867867
}
868868
)
869-
let labelText = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString("#\(resellPrice)", attributes: attributes))
869+
let dateTimeFormat = component.context.sharedContext.currentPresentationData.with { $0 }.dateTimeFormat
870+
let labelText = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString("#\(presentationStringsFormattedNumber(Int32(resellPrice), dateTimeFormat.groupingSeparator))", attributes: attributes))
870871
if let range = labelText.string.range(of: "#") {
871872
labelText.addAttribute(NSAttributedString.Key.font, value: Font.semibold(10.0), range: NSRange(range, in: labelText.string))
872873
labelText.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: true)), range: NSRange(range, in: labelText.string))

submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ final class GiftSetupScreenComponent: Component {
465465
self.inProgress = false
466466
self.state?.updated()
467467

468-
let presentationData = component.context.sharedContext.currentPresentationData.with { $0 }
469468
var errorText: String?
470469
switch error {
471470
case .starGiftOutOfStock:

0 commit comments

Comments
 (0)