Skip to content

Commit 40345ce

Browse files
author
overtake
committed
- bug fixes and improvements
1 parent a9780a5 commit 40345ce

File tree

12 files changed

+154
-16
lines changed

12 files changed

+154
-16
lines changed

‎Telegram-Mac/ApplicationContext.swift

+8
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ private final class AuthModalController : ModalController {
2424
}
2525

2626

27+
28+
29+
2730
final class UnauthorizedApplicationContext {
2831
let account: UnauthorizedAccount
2932
let rootController: MajorNavigationController
3033
let window:Window
3134
let modal: ModalController
3235
let sharedContext: SharedAccountContext
3336

37+
private let updatesDisposable: DisposableSet = DisposableSet()
38+
3439
var rootView: NSView {
3540
return rootController.view
3641
}
@@ -42,6 +47,8 @@ final class UnauthorizedApplicationContext {
4247
window.minSize = NSMakeSize(380, 500)
4348

4449

50+
updatesDisposable.add(managedAppConfigurationUpdates(postbox: account.postbox, network: account.network).start())
51+
4552
if !window.initFromSaver {
4653
window.setFrame(NSMakeRect(0, 0, 800, 650), display: true)
4754
window.center()
@@ -70,6 +77,7 @@ final class UnauthorizedApplicationContext {
7077

7178
deinit {
7279
account.shouldBeServiceTaskMaster.set(.single(.never))
80+
updatesDisposable.dispose()
7381
NSWorkspace.shared.notificationCenter.removeObserver(self)
7482
}
7583

‎Telegram-Mac/AuthController.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,18 @@ class AuthHeaderView : View {
359359
descLayout.measure(width: 300)
360360
desc.update(descLayout)
361361

362-
nextButton.set(text: self.isQrEnabled != nil && self.isQrEnabled! ? L10n.loginQRLogin : L10n.loginNext, for: .Normal)
363-
_ = nextButton.sizeToFit(NSMakeSize(30, 0), NSMakeSize(0, 36), thatFit: true)
364-
nextButton.style = ControlStyle(font: .medium(15.0), foregroundColor: .white, backgroundColor: theme.colors.accent)
362+
363+
if let isQrEnabled = self.isQrEnabled, isQrEnabled {
364+
nextButton.set(text: L10n.loginQRLogin, for: .Normal)
365+
_ = nextButton.sizeToFit(NSMakeSize(30, 0), NSMakeSize(0, 36), thatFit: true)
366+
nextButton.style = ControlStyle(font: .medium(15.0), foregroundColor: theme.colors.accent, backgroundColor: .clear)
367+
} else {
368+
nextButton.set(text: L10n.loginNext, for: .Normal)
369+
_ = nextButton.sizeToFit(NSMakeSize(30, 0), NSMakeSize(0, 36), thatFit: true)
370+
nextButton.style = ControlStyle(font: .medium(15.0), foregroundColor: theme.colors.underSelectedColor, backgroundColor: theme.colors.accent)
371+
}
372+
373+
365374
proxyConnecting.progressColor = theme.colors.accentIcon
366375

367376

@@ -986,7 +995,7 @@ class AuthController : GenericViewController<AuthHeaderView> {
986995
}))
987996

988997

989-
configurationDisposable.set((unauthorizedConfiguration(network: self.account.network) |> castError(Void.self) |> timeout(25.0, queue: .mainQueue(), alternate: .fail(Void())) |> deliverOnMainQueue).start(next: { [weak self] value in
998+
configurationDisposable.set((unauthorizedConfiguration(postbox: self.account.postbox) |> take(1) |> castError(Void.self) |> timeout(25.0, queue: .mainQueue(), alternate: .fail(Void())) |> deliverOnMainQueue).start(next: { [weak self] value in
990999

9911000
self?.qrType = value.qr
9921001
self?.genericView.isQrEnabled = value.qr != .disabled

‎Telegram-Mac/ContextMediaRowItem.swift

+26-4
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,24 @@ class ContextMediaRowView: TableRowView, ModalPreviewRowViewProtocol {
133133

134134
override func set(item: TableRowItem, animated: Bool) {
135135
super.set(item: item, animated: animated)
136+
137+
var subviews = self.subviews
138+
139+
self.removeAllSubviews()
136140

137-
removeAllSubviews()
138141
if let item = item as? ContextMediaRowItem {
139142
var inset:CGFloat = 0
140143
for i in 0 ..< item.result.entries.count {
141144
let container:NSView
142145
switch item.result.entries[i] {
143146
case let .gif(data):
144-
let view = GIFContainerView()
147+
let view: GIFContainerView
148+
let index = subviews.firstIndex(where: { $0 is GIFContainerView})
149+
if let index = index {
150+
view = subviews.remove(at: index) as! GIFContainerView
151+
} else {
152+
view = GIFContainerView()
153+
}
145154
let signal:Signal<ImageDataTransformation, NoError> = chatMessageVideo(postbox: item.context.account.postbox, fileReference: data.file, scale: backingScaleFactor)
146155

147156
view.set(handler: { [weak item] control in
@@ -160,13 +169,26 @@ class ContextMediaRowView: TableRowView, ModalPreviewRowViewProtocol {
160169
container = view
161170
case let .sticker(data):
162171
if data.file.isAnimatedSticker {
163-
let view = MediaAnimatedStickerView(frame: NSZeroRect)
172+
let view: MediaAnimatedStickerView
173+
let index = subviews.firstIndex(where: { $0 is MediaAnimatedStickerView})
174+
if let index = index {
175+
view = subviews.remove(at: index) as! MediaAnimatedStickerView
176+
} else {
177+
view = MediaAnimatedStickerView(frame: NSZeroRect)
178+
}
164179
let size = NSMakeSize(round(item.result.sizes[i].width), round(item.result.sizes[i].height))
165180
view.update(with: data.file, size: size, context: item.context, parent: nil, table: item.table, parameters: nil, animated: false, positionFlags: nil, approximateSynchronousValue: false)
166181
view.userInteractionEnabled = false
167182
container = view
168183
} else {
169-
let view = TransformImageView()
184+
let view: TransformImageView
185+
let index = subviews.firstIndex(where: { $0 is TransformImageView})
186+
if let index = index {
187+
view = subviews.remove(at: index) as! TransformImageView
188+
} else {
189+
view = TransformImageView()
190+
}
191+
170192
view.setSignal(chatMessageSticker(postbox: item.context.account.postbox, file: data.file, small: true, scale: backingScaleFactor, fetched: true))
171193
let imageSize = item.result.sizes[i].aspectFitted(NSMakeSize(item.height, item.height - 8))
172194
view.set(arguments: TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: NSEdgeInsets()))

‎Telegram-Mac/EmojiViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class EmojiViewController: TelegramGenericViewController<EmojiControllerView>, T
263263

264264
override func viewWillAppear(_ animated: Bool) {
265265
super.viewWillAppear(animated)
266+
genericView.needsLayout = true
266267
}
267268

268269
override func viewDidAppear(_ animated: Bool) {

‎Telegram-Mac/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>186428</string>
39+
<string>186443</string>
4040
<key>LSApplicationCategoryType</key>
4141
<string>public.app-category.social-networking</string>
4242
<key>LSFileQuarantineEnabled</key>

‎Telegram-Mac/QRLoginConfiguration.swift

+20-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,29 @@ func unauthorizedConfiguration(network: Network) -> Signal<UnauthorizedConfigura
3636
return network.request(Api.functions.help.getAppConfig()) |> retryRequest
3737
|> map { result -> UnauthorizedConfiguration in
3838
if let data = JSON(apiJson: result), let rawQr = data["qr_login_code"] as? String, let qr = QRLoginType(rawValue: rawQr) {
39-
return UnauthorizedConfiguration(qr: qr)
39+
return UnauthorizedConfiguration(qr: .secondary)
4040
} else {
4141
return .defaultValue
4242
}
4343
}
4444
}
4545

46+
47+
func managedAppConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<Void, NoError> {
48+
let poll = Signal<Void, NoError> { subscriber in
49+
return (network.request(Api.functions.help.getAppConfig())
50+
|> retryRequest
51+
|> mapToSignal { result -> Signal<Void, NoError> in
52+
return postbox.transaction { transaction -> Void in
53+
if let data = JSON(apiJson: result) {
54+
updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in
55+
var configuration = configuration
56+
configuration.data = data
57+
return configuration
58+
})
59+
}
60+
}
61+
}).start()
62+
}
63+
return (poll |> then(.complete() |> suspendAwareDelay(12.0 * 60.0 * 60.0, queue: Queue.concurrentDefaultQueue()))) |> restart
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// QRLoginConfiguration.swift
3+
// Telegram
4+
//
5+
// Created by Mikhail Filimonov on 26.11.2019.
6+
// Copyright © 2019 Telegram. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
import TelegramCore
11+
import SyncCore
12+
import Postbox
13+
import SwiftSignalKit
14+
import TelegramApi
15+
16+
enum QRLoginType : String {
17+
case primary = "primary"
18+
case secondary = "secondary"
19+
case disabled = "disabled"
20+
}
21+
struct UnauthorizedConfiguration {
22+
static var defaultValue: UnauthorizedConfiguration {
23+
return UnauthorizedConfiguration(qr: .disabled)
24+
}
25+
26+
let qr: QRLoginType
27+
28+
fileprivate init(qr: QRLoginType) {
29+
self.qr = qr
30+
}
31+
public static func with(appConfiguration: AppConfiguration) -> UnauthorizedConfiguration {
32+
if let data = appConfiguration.data, let rawType = data["qr_login_code"] as? String, let qr = QRLoginType(rawValue: rawType) {
33+
return UnauthorizedConfiguration(qr: qr)
34+
} else {
35+
return .defaultValue
36+
}
37+
}
38+
}
39+
40+
41+
func unauthorizedConfiguration(postbox: Postbox) -> Signal<UnauthorizedConfiguration, NoError> {
42+
return postbox.preferencesView(keys: [PreferencesKeys.appConfiguration]) |> mapToSignal { view in
43+
if let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration {
44+
let configuration = UnauthorizedConfiguration.with(appConfiguration: appConfiguration)
45+
return .single(configuration)
46+
} else {
47+
return .never()
48+
}
49+
} |> deliverOnMainQueue
50+
}
51+
52+
53+
private func updateAppConfiguration(transaction: Transaction, _ f: (AppConfiguration) -> AppConfiguration) {
54+
let current = currentAppConfiguration(transaction: transaction)
55+
let updated = f(current)
56+
if updated != current {
57+
transaction.setPreferencesEntry(key: PreferencesKeys.appConfiguration, value: updated)
58+
}
59+
}
60+
61+
62+
func managedAppConfigurationUpdates(postbox: Postbox, network: Network) -> Signal<Void, NoError> {
63+
let poll = Signal<Void, NoError> { subscriber in
64+
return (network.request(Api.functions.help.getAppConfig())
65+
|> retryRequest
66+
|> mapToSignal { result -> Signal<Void, NoError> in
67+
return postbox.transaction { transaction -> Void in
68+
if let data = JSON(apiJson: result) {
69+
updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in
70+
var configuration = configuration
71+
configuration.data = data
72+
return configuration
73+
})
74+
}
75+
}
76+
}).start()
77+
}
78+
return (poll |> then(.complete() |> suspendAwareDelay(12.0 * 60.0 * 60.0, queue: Queue.concurrentDefaultQueue()))) |> restart
79+
}
76 Bytes
Binary file not shown.

‎Telegram.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
A7D28259236C70A50000A9BF /* SSignalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7D2823B236C69070000A9BF /* SSignalKit.framework */; };
237237
A7DF1B6C237415AD00ACC01F /* Zip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7DF1B6B237415AD00ACC01F /* Zip.framework */; };
238238
A7ED5DAF236C7CE100040372 /* RLottie.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7ED5DAE236C7CE100040372 /* RLottie.framework */; };
239-
A7F282B2238D122900742C20 /* QRLoginConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F282B1238D122900742C20 /* QRLoginConfiguration.swift */; };
239+
A7F282B2238D122900742C20 /* UnauthorizedConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F282B1238D122900742C20 /* UnauthorizedConfiguration.swift */; };
240240
C2016F3B1EAA4538003AF981 /* RecentPeerRowItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2016F3A1EAA4538003AF981 /* RecentPeerRowItem.swift */; };
241241
C2016F681EAE0A68003AF981 /* PhoneCallWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2016F671EAE0A68003AF981 /* PhoneCallWindowController.swift */; };
242242
C201C2321E3B2D1C0026C21E /* FastSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = C201C2311E3B2D1C0026C21E /* FastSettings.swift */; };
@@ -1237,7 +1237,7 @@
12371237
A7D2823B236C69070000A9BF /* SSignalKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SSignalKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
12381238
A7DF1B6B237415AD00ACC01F /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
12391239
A7ED5DAE236C7CE100040372 /* RLottie.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = RLottie.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1240-
A7F282B1238D122900742C20 /* QRLoginConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRLoginConfiguration.swift; sourceTree = "<group>"; };
1240+
A7F282B1238D122900742C20 /* UnauthorizedConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnauthorizedConfiguration.swift; sourceTree = "<group>"; };
12411241
C2016F3A1EAA4538003AF981 /* RecentPeerRowItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecentPeerRowItem.swift; sourceTree = "<group>"; };
12421242
C2016F431EAA4967003AF981 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/ShareViewController.strings"; sourceTree = "<group>"; };
12431243
C2016F451EAA4967003AF981 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
@@ -3474,7 +3474,7 @@
34743474
9F1890922238F3DC00665EF5 /* DownloadedFilesPaths.swift */,
34753475
D07450F02340DC8200769D7F /* WalletConfiguration.swift */,
34763476
A766493E236D6BFD00163DF4 /* PasscodeSettings.swift */,
3477-
A7F282B1238D122900742C20 /* QRLoginConfiguration.swift */,
3477+
A7F282B1238D122900742C20 /* UnauthorizedConfiguration.swift */,
34783478
);
34793479
name = "inapp-settings";
34803480
sourceTree = "<group>";
@@ -5476,7 +5476,7 @@
54765476
C29C3E711E43881500193A7E /* ModalPreviewViews.swift in Sources */,
54775477
9F7B74032227F492006610E4 /* ManageSharedAccountInfo.swift in Sources */,
54785478
D0CD3095221970F8005D23DD /* FFMpegRemuxer.m in Sources */,
5479-
A7F282B2238D122900742C20 /* QRLoginConfiguration.swift in Sources */,
5479+
A7F282B2238D122900742C20 /* UnauthorizedConfiguration.swift in Sources */,
54805480
9FC4DA9C21DD187C003E2A62 /* SearchPeerMembers.swift in Sources */,
54815481
C22E06321D8044CC00A11C88 /* ChatListController.swift in Sources */,
54825482
C246D6281FAB72D4004C17FA /* MediaGroupPreviewRowItem.swift in Sources */,

‎TelegramShare/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleShortVersionString</key>
2222
<string>5.8.2</string>
2323
<key>CFBundleVersion</key>
24-
<string>186428</string>
24+
<string>186443</string>
2525
<key>LSMinimumSystemVersion</key>
2626
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2727
<key>NSExtension</key>

‎submodules/telegram-ios

Submodule telegram-ios updated from c113e9e to cb6377b

0 commit comments

Comments
 (0)