Skip to content

Commit 00190dc

Browse files
committed
- some improvements.
1 parent 2345c77 commit 00190dc

29 files changed

+168
-93
lines changed

Telegram-Mac/AddContactModalController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func AddContactModalController(_ context: AccountContext) -> InputDataModalContr
125125
} else {
126126
_ = (showModalProgress(signal: context.engine.contacts.importContact(firstName: state.firstName, lastName: state.lastName, phoneNumber: state.phoneNumber), for: context.window) |> deliverOnMainQueue).start(next: { peerId in
127127
if let peerId = peerId {
128-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(peerId)))
128+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId))
129129
close?()
130130
} else {
131131
updateState {

Telegram-Mac/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ class AppDelegate: NSResponder, NSApplicationDelegate, NSUserNotificationCenterD
16111611
if context.account.id == identifier.recordId {
16121612
switch identifier.source {
16131613
case let .peerId(peerId):
1614-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(peerId)))
1614+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId))
16151615
}
16161616
} else {
16171617
switch identifier.source {

Telegram-Mac/ApplicationContext.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,48 @@ import Dock
1313
import PrivateCallScreen
1414
import DetectSpeech
1515

16+
17+
func navigateToChat(navigation: NavigationViewController?, context: AccountContext, chatLocation:ChatLocation, mode: ChatMode = .history, focusTarget:ChatFocusTarget? = nil, initialAction: ChatInitialAction? = nil, chatLocationContextHolder: Atomic<ChatLocationContextHolder?>? = nil, additional: Bool = false, animated: Bool = true, navigationStyle: ViewControllerStyle? = nil) {
18+
19+
let open:()->Void = { [weak navigation] in
20+
if additional {
21+
navigation?.push(ChatAdditionController(context: context, chatLocation: chatLocation, mode: mode, focusTarget: focusTarget, chatLocationContextHolder: chatLocationContextHolder), animated, style: navigationStyle)
22+
} else {
23+
navigation?.push(ChatController(context: context, chatLocation: chatLocation, mode: mode, focusTarget: focusTarget, chatLocationContextHolder: chatLocationContextHolder), animated, style: navigationStyle)
24+
}
25+
}
26+
27+
let signal = context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: chatLocation.peerId)) |> deliverOnMainQueue
28+
29+
_ = signal.start(next: { peer in
30+
if let peer = peer?._asPeer() {
31+
if peer.hasSensitiveContent(platform: "ios") {
32+
if !context.contentConfig.sensitiveContentEnabled, context.contentConfig.canAdjustSensitiveContent {
33+
let need_verification = context.appConfiguration.getBoolValue("need_age_video_verification", orElse: false)
34+
35+
if need_verification {
36+
showModal(with: VerifyAgeAlertController(context: context), for: context.window)
37+
return
38+
}
39+
}
40+
if context.contentConfig.sensitiveContentEnabled {
41+
open()
42+
} else {
43+
verifyAlert(for: context.window, header: strings().chatSensitiveContent, information: strings().chatSensitiveContentConfirm, ok: strings().chatSensitiveContentConfirmOk, option: context.contentConfig.canAdjustSensitiveContent ? strings().chatSensitiveContentConfirmThird : nil, optionIsSelected: false, successHandler: { result in
44+
45+
if result == .thrid {
46+
let _ = updateRemoteContentSettingsConfiguration(postbox: context.account.postbox, network: context.account.network, sensitiveContentEnabled: true).start()
47+
}
48+
open()
49+
})
50+
}
51+
} else {
52+
open()
53+
}
54+
}
55+
})
56+
}
57+
1658
private final class AuthModalController : ModalController {
1759
override var background: NSColor {
1860
return theme.colors.background

Telegram-Mac/BrowserState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ final class BrowserStateContext {
422422

423423
let data = ModalAlertData(title: nil, info: strings().webAppFirstOpenTerms(privacyUrl), description: nil, ok: strings().botLaunchApp, options: [], mode: .confirm(text: strings().modalCancel, isThird: false), header: .init(value: { initialSize, stableId, presentation in
424424
return AlertHeaderItem(initialSize, stableId: stableId, presentation: presentation, context: context, peer: peer, info: strings().botMoreAbout, callback: { _ in
425-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(peerId)))
425+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId))
426426
closeAllModals(window: context.window)
427427
})
428428
}))

Telegram-Mac/ChatController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,9 +4547,9 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
45474547
}
45484548
} else {
45494549
if mode.isSavedMessagesThread {
4550-
strongSelf.navigationController?.push(ChatController(context: context, chatLocation: .peer(peerId), focusTarget: .init(messageId: postId), initialAction: action))
4550+
navigateToChat(navigation: strongSelf.navigationController, context: context, chatLocation: .peer(peerId), focusTarget: .init(messageId: postId), initialAction: action)
45514551
} else {
4552-
strongSelf.navigationController?.push(ChatAdditionController(context: context, chatLocation: .peer(peerId), focusTarget: .init(messageId: postId), initialAction: action))
4552+
navigateToChat(navigation: strongSelf.navigationController, context: context, chatLocation: .peer(peerId), focusTarget: .init(messageId: postId), initialAction: action, additional: true)
45534553
}
45544554
}
45554555
} else {
@@ -8529,7 +8529,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
85298529

85308530
items.append(ContextMenuItem(strings().chatSavedMessagesViewAsMessages, handler: { [weak self] in
85318531
context.engine.peers.updateSavedMessagesViewAsTopics(value: false)
8532-
self?.navigationController?.push(ChatController(context: context, chatLocation: .peer(context.peerId)))
8532+
navigateToChat(navigation: self?.navigationController, context: context, chatLocation: .peer(context.peerId))
85338533
}, itemImage: !displaySavedChatsAsTopics ? MenuAnimation.menu_check_selected.value : nil))
85348534

85358535
items.append(ContextMenuItem(strings().chatSavedMessagesViewAsChats, handler: { [weak self] in
@@ -8804,7 +8804,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
88048804

88058805
startSecretChatDisposable.set(signal.start(next: { [weak self] peerId in
88068806
if let strongSelf = self {
8807-
strongSelf.navigationController?.push(ChatController(context: strongSelf.context, chatLocation: .peer(peerId)))
8807+
navigateToChat(navigation: strongSelf.navigationController, context: strongSelf.context, chatLocation: .peer(peerId))
88088808
}
88098809
}))
88108810
}

Telegram-Mac/ChatListRowItem.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,8 +2267,9 @@ class ChatListRowItem: TableRowItem {
22672267
guard let peerId = peerId else {
22682268
return
22692269
}
2270-
ChatListRowItem.previewChat(peerId: peerId, context: context)
2271-
2270+
if let peer = self.peer, !peer.hasSensitiveContent(platform: "ios") {
2271+
ChatListRowItem.previewChat(peerId: peerId, context: context)
2272+
}
22722273
}
22732274

22742275
static func previewChat(peerId: PeerId, context: AccountContext) {

Telegram-Mac/ChatListRowView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ private class ChatListDraggingContainerView : View {
570570
if let tiff = sender.draggingPasteboard.data(forType: .tiff), let image = NSImage(data: tiff) {
571571
_ = (putToTemp(image: image) |> deliverOnMainQueue).start(next: { [weak item] path in
572572
guard let item = item, let chatLocation = item.chatLocation else {return}
573-
item.context.bindings.rootNavigation().push(ChatController(context: item.context, chatLocation: chatLocation, initialAction: .files(list: [path], behavior: .automatic)))
573+
574+
navigateToChat(navigation: item.context.bindings.rootNavigation(), context: item.context, chatLocation: chatLocation, initialAction: .files(list: [path], behavior: .automatic))
575+
574576
})
575577
} else {
576578
let list = sender.draggingPasteboard.propertyList(forType: .kFilenames) as? [String]
@@ -583,7 +585,7 @@ private class ChatListDraggingContainerView : View {
583585
return false
584586
}
585587
if !list.isEmpty, let chatLocation = item.chatLocation {
586-
item.context.bindings.rootNavigation().push(ChatController(context: item.context, chatLocation: chatLocation, initialAction: .files(list: list, behavior: .automatic)))
588+
navigateToChat(navigation: item.context.bindings.rootNavigation(), context: item.context, chatLocation: chatLocation, initialAction: .files(list: list, behavior: .automatic))
587589
}
588590
}
589591
}

Telegram-Mac/ComposeActions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func createGroup(with context: AccountContext, selectedPeers:Set<PeerId> = Set()
4343

4444
_ = signal.start(next: { result, complete in
4545
if let result = result, complete {
46-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(result.peerId)))
46+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(result.peerId))
4747
}
4848
}, error: { error in
4949
let text: String
@@ -132,7 +132,7 @@ func createGroupDirectly(with context: AccountContext, selectedPeers: [PeerId] =
132132
chooseName.restart(with: ComposeState(selectedPeers))
133133
_ = signal.start(next: { result, complete in
134134
if let result = result, complete {
135-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(result.peerId)))
135+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(result.peerId))
136136
onCreate(result.peerId)
137137

138138
}
@@ -222,7 +222,7 @@ func createChannel(with context: AccountContext) {
222222

223223
_ = create.start(next: { peerId in
224224
if let peerId = peerId {
225-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(peerId)))
225+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId))
226226
} else {
227227
context.bindings.rootNavigation().close()
228228
}

Telegram-Mac/CustomEmojiController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func CustomEmojiController(context: AccountContext) -> InputDataController {
116116
})
117117
}, openStickerBot: {
118118
let link = inApp(for: "@stickers", context: context, openInfo: { peerId, _, _, _ in
119-
context.bindings.rootNavigation().push(ChatController(context: context, chatLocation: .peer(peerId)))
119+
navigateToChat(navigation: context.bindings.rootNavigation(), context: context, chatLocation: .peer(peerId))
120120
})
121121
execute(inapp: link)
122122
}, toggleSuggest: {

Telegram-Mac/DownloadsController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ func DownloadsController(context: AccountContext, searchValue: Signal<String, No
167167
if current.chatInteraction.peerId == focusTarget.messageId.peerId {
168168
current.chatInteraction.focusMessageId(nil, focusTarget, .center(id: AnyHashable(0), innerId: nil, animated: true, focus: .init(focus: true, action: nil), inset: 0))
169169
} else {
170-
navigation.push(ChatController(context: context, chatLocation: .peer(focusTarget.messageId.peerId), focusTarget: focusTarget))
170+
navigateToChat(navigation: navigation, context: context, chatLocation: .peer(focusTarget.messageId.peerId), focusTarget: focusTarget)
171171
}
172172
} else {
173-
navigation.push(ChatController(context: context, chatLocation: .peer(focusTarget.messageId.peerId), focusTarget: focusTarget))
173+
navigateToChat(navigation: navigation, context: context, chatLocation: .peer(focusTarget.messageId.peerId), focusTarget: focusTarget)
174174
}
175175

176176
}

0 commit comments

Comments
 (0)