mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Modernize weak references
This commit is contained in:
parent
3c38b4df89
commit
99d210e364
@ -887,29 +887,33 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
|
||||
let controllerInteraction = ChatControllerInteraction(openMessage: { [weak self] message, params in
|
||||
guard let strongSelf = self, strongSelf.isNodeLoaded, let message = strongSelf.chatDisplayNode.historyNode.messageInCurrentHistoryView(message.id) else {
|
||||
guard let self, self.isNodeLoaded, let message = self.chatDisplayNode.historyNode.messageInCurrentHistoryView(message.id) else {
|
||||
return false
|
||||
}
|
||||
|
||||
let mode = params.mode
|
||||
|
||||
let displayVoiceMessageDiscardAlert: () -> Bool = {
|
||||
if strongSelf.presentVoiceMessageDiscardAlert(action: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
Queue.mainQueue().after(0.1, {
|
||||
let _ = strongSelf.controllerInteraction?.openMessage(message, params)
|
||||
})
|
||||
let displayVoiceMessageDiscardAlert: () -> Bool = { [weak self] in
|
||||
guard let self else {
|
||||
return true
|
||||
}
|
||||
if self.presentVoiceMessageDiscardAlert(action: { [weak self] in
|
||||
Queue.mainQueue().after(0.1, {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
let _ = self.controllerInteraction?.openMessage(message, params)
|
||||
})
|
||||
}, performAction: false) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
strongSelf.commitPurposefulAction()
|
||||
strongSelf.dismissAllTooltips()
|
||||
self.commitPurposefulAction()
|
||||
self.dismissAllTooltips()
|
||||
|
||||
strongSelf.chatDisplayNode.messageTransitionNode.dismissMessageReactionContexts()
|
||||
self.chatDisplayNode.messageTransitionNode.dismissMessageReactionContexts()
|
||||
|
||||
var openMessageByAction = false
|
||||
var isLocation = false
|
||||
@ -923,9 +927,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
if let file = media as? TelegramMediaFile {
|
||||
if file.isInstantVideo {
|
||||
if strongSelf.chatDisplayNode.isInputViewFocused {
|
||||
strongSelf.returnInputViewFocus = true
|
||||
strongSelf.chatDisplayNode.dismissInput()
|
||||
if self.chatDisplayNode.isInputViewFocused {
|
||||
self.returnInputViewFocus = true
|
||||
self.chatDisplayNode.dismissInput()
|
||||
}
|
||||
}
|
||||
if file.isMusic || file.isVoice || file.isInstantVideo {
|
||||
@ -934,7 +938,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
|
||||
if (file.isVoice || file.isInstantVideo) && message.minAutoremoveOrClearTimeout == viewOnceTimeout {
|
||||
strongSelf.openViewOnceMediaMessage(message)
|
||||
self.openViewOnceMediaMessage(message)
|
||||
return false
|
||||
}
|
||||
} else if file.isVideo {
|
||||
@ -947,7 +951,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
switch extendedMedia {
|
||||
case .preview:
|
||||
if displayVoiceMessageDiscardAlert() {
|
||||
strongSelf.controllerInteraction?.openCheckoutOrReceipt(message.id, params)
|
||||
self.controllerInteraction?.openCheckoutOrReceipt(message.id, params)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -959,7 +963,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
switch extendedMedia {
|
||||
case .preview:
|
||||
if displayVoiceMessageDiscardAlert() {
|
||||
strongSelf.controllerInteraction?.openCheckoutOrReceipt(message.id, nil)
|
||||
self.controllerInteraction?.openCheckoutOrReceipt(message.id, nil)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -969,15 +973,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
} else if media is TelegramMediaGiveaway || media is TelegramMediaGiveawayResults {
|
||||
let progress = params.progress
|
||||
let presentationData = strongSelf.presentationData
|
||||
let presentationData = self.presentationData
|
||||
|
||||
var signal = strongSelf.context.engine.payments.premiumGiveawayInfo(peerId: message.id.peerId, messageId: message.id)
|
||||
var signal = self.context.engine.payments.premiumGiveawayInfo(peerId: message.id.peerId, messageId: message.id)
|
||||
let disposable: MetaDisposable
|
||||
if let current = strongSelf.giveawayStatusDisposable {
|
||||
if let current = self.giveawayStatusDisposable {
|
||||
disposable = current
|
||||
} else {
|
||||
disposable = MetaDisposable()
|
||||
strongSelf.giveawayStatusDisposable = disposable
|
||||
self.giveawayStatusDisposable = disposable
|
||||
}
|
||||
|
||||
let progressSignal = Signal<Never, NoError> { [weak self] subscriber in
|
||||
@ -1010,8 +1014,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
disposable.set((signal
|
||||
|> deliverOnMainQueue).startStrict(next: { [weak self] info in
|
||||
if let strongSelf = self, let info {
|
||||
strongSelf.displayGiveawayStatusInfo(messageId: message.id, giveawayInfo: info)
|
||||
if let self, let info {
|
||||
self.displayGiveawayStatusInfo(messageId: message.id, giveawayInfo: info)
|
||||
}
|
||||
}))
|
||||
|
||||
@ -1024,22 +1028,22 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
case .pinnedMessageUpdated, .gameScore, .setSameChatWallpaper, .giveawayResults, .customText:
|
||||
for attribute in message.attributes {
|
||||
if let attribute = attribute as? ReplyMessageAttribute {
|
||||
strongSelf.navigateToMessage(from: message.id, to: .id(attribute.messageId, NavigateToMessageParams(timestamp: nil, quote: attribute.isQuote ? attribute.quote.flatMap { quote in NavigateToMessageParams.Quote(string: quote.text, offset: quote.offset) } : nil)))
|
||||
self.navigateToMessage(from: message.id, to: .id(attribute.messageId, NavigateToMessageParams(timestamp: nil, quote: attribute.isQuote ? attribute.quote.flatMap { quote in NavigateToMessageParams.Quote(string: quote.text, offset: quote.offset) } : nil)))
|
||||
break
|
||||
}
|
||||
}
|
||||
case let .photoUpdated(image):
|
||||
openMessageByAction = image != nil
|
||||
case .groupPhoneCall, .inviteToGroupPhoneCall:
|
||||
if let activeCall = strongSelf.presentationInterfaceState.activeGroupCallInfo?.activeCall {
|
||||
strongSelf.joinGroupCall(peerId: message.id.peerId, invite: nil, activeCall: EngineGroupCallDescription(id: activeCall.id, accessHash: activeCall.accessHash, title: activeCall.title, scheduleTimestamp: activeCall.scheduleTimestamp, subscribedToScheduled: activeCall.subscribedToScheduled, isStream: activeCall.isStream))
|
||||
if let activeCall = self.presentationInterfaceState.activeGroupCallInfo?.activeCall {
|
||||
self.joinGroupCall(peerId: message.id.peerId, invite: nil, activeCall: EngineGroupCallDescription(id: activeCall.id, accessHash: activeCall.accessHash, title: activeCall.title, scheduleTimestamp: activeCall.scheduleTimestamp, subscribedToScheduled: activeCall.subscribedToScheduled, isStream: activeCall.isStream))
|
||||
} else {
|
||||
var canManageGroupCalls = false
|
||||
if let channel = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramChannel {
|
||||
if let channel = self.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramChannel {
|
||||
if channel.flags.contains(.isCreator) || channel.hasPermission(.manageCalls) {
|
||||
canManageGroupCalls = true
|
||||
}
|
||||
} else if let group = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramGroup {
|
||||
} else if let group = self.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramGroup {
|
||||
if case .creator = group.role {
|
||||
canManageGroupCalls = true
|
||||
} else if case let .admin(rights, _) = group.role {
|
||||
@ -1051,80 +1055,80 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
|
||||
if canManageGroupCalls {
|
||||
let text: String
|
||||
if let channel = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramChannel, case .broadcast = channel.info {
|
||||
text = strongSelf.presentationData.strings.LiveStream_CreateNewVoiceChatText
|
||||
if let channel = self.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramChannel, case .broadcast = channel.info {
|
||||
text = self.presentationData.strings.LiveStream_CreateNewVoiceChatText
|
||||
} else {
|
||||
text = strongSelf.presentationData.strings.VoiceChat_CreateNewVoiceChatText
|
||||
text = self.presentationData.strings.VoiceChat_CreateNewVoiceChatText
|
||||
}
|
||||
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.VoiceChat_CreateNewVoiceChatStartNow, action: {
|
||||
if let strongSelf = self {
|
||||
self.present(textAlertController(context: self.context, updatedPresentationData: self.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.VoiceChat_CreateNewVoiceChatStartNow, action: { [weak self] in
|
||||
if let self {
|
||||
var dismissStatus: (() -> Void)?
|
||||
let statusController = OverlayStatusController(theme: strongSelf.presentationData.theme, type: .loading(cancelled: {
|
||||
let statusController = OverlayStatusController(theme: self.presentationData.theme, type: .loading(cancelled: {
|
||||
dismissStatus?()
|
||||
}))
|
||||
dismissStatus = { [weak self, weak statusController] in
|
||||
self?.createVoiceChatDisposable.set(nil)
|
||||
statusController?.dismiss()
|
||||
}
|
||||
strongSelf.present(statusController, in: .window(.root))
|
||||
strongSelf.createVoiceChatDisposable.set((strongSelf.context.engine.calls.createGroupCall(peerId: message.id.peerId, title: nil, scheduleDate: nil, isExternalStream: false)
|
||||
self.present(statusController, in: .window(.root))
|
||||
self.createVoiceChatDisposable.set((self.context.engine.calls.createGroupCall(peerId: message.id.peerId, title: nil, scheduleDate: nil, isExternalStream: false)
|
||||
|> deliverOnMainQueue).startStrict(next: { [weak self] info in
|
||||
guard let strongSelf = self else {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
strongSelf.joinGroupCall(peerId: message.id.peerId, invite: nil, activeCall: EngineGroupCallDescription(id: info.id, accessHash: info.accessHash, title: info.title, scheduleTimestamp: info.scheduleTimestamp, subscribedToScheduled: info.subscribedToScheduled, isStream: info.isStream))
|
||||
self.joinGroupCall(peerId: message.id.peerId, invite: nil, activeCall: EngineGroupCallDescription(id: info.id, accessHash: info.accessHash, title: info.title, scheduleTimestamp: info.scheduleTimestamp, subscribedToScheduled: info.subscribedToScheduled, isStream: info.isStream))
|
||||
}, error: { [weak self] error in
|
||||
dismissStatus?()
|
||||
|
||||
guard let strongSelf = self else {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
let text: String
|
||||
switch error {
|
||||
case .generic, .scheduledTooLate:
|
||||
text = strongSelf.presentationData.strings.Login_UnknownError
|
||||
text = self.presentationData.strings.Login_UnknownError
|
||||
case .anonymousNotAllowed:
|
||||
if let channel = message.peers[message.id.peerId] as? TelegramChannel, case .broadcast = channel.info {
|
||||
text = strongSelf.presentationData.strings.LiveStream_AnonymousDisabledAlertText
|
||||
text = self.presentationData.strings.LiveStream_AnonymousDisabledAlertText
|
||||
} else {
|
||||
text = strongSelf.presentationData.strings.VoiceChat_AnonymousDisabledAlertText
|
||||
text = self.presentationData.strings.VoiceChat_AnonymousDisabledAlertText
|
||||
}
|
||||
}
|
||||
strongSelf.present(textAlertController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
||||
self.present(textAlertController(context: self.context, updatedPresentationData: self.updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
|
||||
}, completed: {
|
||||
dismissStatus?()
|
||||
}))
|
||||
}
|
||||
}), TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.VoiceChat_CreateNewVoiceChatSchedule, action: {
|
||||
if let strongSelf = self {
|
||||
strongSelf.context.scheduleGroupCall(peerId: message.id.peerId, parentController: strongSelf)
|
||||
}), TextAlertAction(type: .genericAction, title: self.presentationData.strings.VoiceChat_CreateNewVoiceChatSchedule, action: { [weak self] in
|
||||
if let self {
|
||||
self.context.scheduleGroupCall(peerId: message.id.peerId, parentController: self)
|
||||
}
|
||||
}), TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {})], actionLayout: .vertical), in: .window(.root))
|
||||
}), TextAlertAction(type: .genericAction, title: self.presentationData.strings.Common_Cancel, action: {})], actionLayout: .vertical), in: .window(.root))
|
||||
}
|
||||
}
|
||||
return true
|
||||
case .messageAutoremoveTimeoutUpdated:
|
||||
var canSetupAutoremoveTimeout = false
|
||||
|
||||
if let _ = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat {
|
||||
if let _ = self.presentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat {
|
||||
canSetupAutoremoveTimeout = false
|
||||
} else if let group = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramGroup {
|
||||
} else if let group = self.presentationInterfaceState.renderedPeer?.peer as? TelegramGroup {
|
||||
if !group.hasBannedPermission(.banChangeInfo) {
|
||||
canSetupAutoremoveTimeout = true
|
||||
}
|
||||
} else if let user = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramUser {
|
||||
if user.id != strongSelf.context.account.peerId && user.botInfo == nil {
|
||||
} else if let user = self.presentationInterfaceState.renderedPeer?.peer as? TelegramUser {
|
||||
if user.id != self.context.account.peerId && user.botInfo == nil {
|
||||
canSetupAutoremoveTimeout = true
|
||||
}
|
||||
} else if let channel = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramChannel {
|
||||
} else if let channel = self.presentationInterfaceState.renderedPeer?.peer as? TelegramChannel {
|
||||
if channel.hasPermission(.changeInfo) {
|
||||
canSetupAutoremoveTimeout = true
|
||||
}
|
||||
}
|
||||
|
||||
if canSetupAutoremoveTimeout {
|
||||
strongSelf.presentAutoremoveSetup()
|
||||
self.presentAutoremoveSetup()
|
||||
}
|
||||
case let .paymentSent(currency, _, _, _, _):
|
||||
if currency == "XTR" {
|
||||
@ -1136,14 +1140,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
self.push(self.context.sharedContext.makeStarsReceiptScreen(context: self.context, receipt: receipt))
|
||||
})
|
||||
} else {
|
||||
strongSelf.present(BotReceiptController(context: strongSelf.context, messageId: message.id), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
self.present(BotReceiptController(context: self.context, messageId: message.id), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
}
|
||||
return true
|
||||
case .setChatTheme:
|
||||
strongSelf.presentThemeSelection()
|
||||
self.presentThemeSelection()
|
||||
return true
|
||||
case let .setChatWallpaper(wallpaper, _):
|
||||
guard let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else {
|
||||
guard let peer = self.presentationInterfaceState.renderedPeer?.peer else {
|
||||
return true
|
||||
}
|
||||
if let peer = peer as? TelegramChannel {
|
||||
@ -1158,11 +1162,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
return true
|
||||
}
|
||||
guard message.effectivelyIncoming(strongSelf.context.account.peerId), let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer else {
|
||||
strongSelf.presentThemeSelection()
|
||||
guard message.effectivelyIncoming(self.context.account.peerId), let peer = self.presentationInterfaceState.renderedPeer?.peer else {
|
||||
self.presentThemeSelection()
|
||||
return true
|
||||
}
|
||||
strongSelf.chatDisplayNode.dismissInput()
|
||||
self.chatDisplayNode.dismissInput()
|
||||
var options = WallpaperPresentationOptions()
|
||||
var intensity: Int32?
|
||||
if let settings = wallpaper.settings {
|
||||
@ -1176,7 +1180,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
intensity = settings.intensity
|
||||
}
|
||||
}
|
||||
let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, options, [], intensity, nil, nil), mode: .peer(EnginePeer(peer), true))
|
||||
let wallpaperPreviewController = WallpaperGalleryController(context: self.context, source: .wallpaper(wallpaper, options, [], intensity, nil, nil), mode: .peer(EnginePeer(peer), true))
|
||||
wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _, brightness, forBoth in
|
||||
var settings: WallpaperSettings?
|
||||
if case let .wallpaper(wallpaper, _) = entry {
|
||||
@ -1189,69 +1193,69 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
settings = WallpaperSettings(blur: options.contains(.blur), motion: options.contains(.motion), colors: baseSettings?.colors ?? [], intensity: intensity, rotation: baseSettings?.rotation)
|
||||
}
|
||||
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: settings, forBoth: forBoth)
|
||||
let _ = (self.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: settings, forBoth: forBoth)
|
||||
|> deliverOnMainQueue).startStandalone()
|
||||
Queue.mainQueue().after(0.1) {
|
||||
wallpaperPreviewController?.dismiss()
|
||||
}
|
||||
}
|
||||
strongSelf.push(wallpaperPreviewController)
|
||||
self.push(wallpaperPreviewController)
|
||||
return true
|
||||
case let .giftPremium(_, _, duration, _, _, _, _):
|
||||
strongSelf.chatDisplayNode.dismissInput()
|
||||
let fromPeerId: PeerId = message.author?.id == strongSelf.context.account.peerId ? strongSelf.context.account.peerId : message.id.peerId
|
||||
let toPeerId: PeerId = message.author?.id == strongSelf.context.account.peerId ? message.id.peerId : strongSelf.context.account.peerId
|
||||
let controller = PremiumIntroScreen(context: strongSelf.context, source: .gift(from: fromPeerId, to: toPeerId, duration: duration, giftCode: nil))
|
||||
strongSelf.push(controller)
|
||||
self.chatDisplayNode.dismissInput()
|
||||
let fromPeerId: PeerId = message.author?.id == self.context.account.peerId ? self.context.account.peerId : message.id.peerId
|
||||
let toPeerId: PeerId = message.author?.id == self.context.account.peerId ? message.id.peerId : self.context.account.peerId
|
||||
let controller = PremiumIntroScreen(context: self.context, source: .gift(from: fromPeerId, to: toPeerId, duration: duration, giftCode: nil))
|
||||
self.push(controller)
|
||||
return true
|
||||
case .starGift, .starGiftUnique:
|
||||
let controller = strongSelf.context.sharedContext.makeGiftViewScreen(context: strongSelf.context, message: EngineMessage(message), shareStory: { [weak self] uniqueGift in
|
||||
if let self {
|
||||
let controller = self.context.sharedContext.makeGiftViewScreen(context: self.context, message: EngineMessage(message), shareStory: { [weak self] uniqueGift in
|
||||
Queue.mainQueue().after(0.15) {
|
||||
if let self {
|
||||
let controller = self.context.sharedContext.makeStorySharingScreen(context: self.context, subject: .gift(uniqueGift), parentController: self)
|
||||
self.push(controller)
|
||||
}
|
||||
}
|
||||
})
|
||||
strongSelf.push(controller)
|
||||
self.push(controller)
|
||||
return true
|
||||
case .giftStars:
|
||||
let controller = strongSelf.context.sharedContext.makeStarsGiftScreen(context: strongSelf.context, message: EngineMessage(message))
|
||||
strongSelf.push(controller)
|
||||
let controller = self.context.sharedContext.makeStarsGiftScreen(context: self.context, message: EngineMessage(message))
|
||||
self.push(controller)
|
||||
return true
|
||||
case let .giftCode(slug, _, _, _, _, _, _, _, _, _, _):
|
||||
strongSelf.openResolved(result: .premiumGiftCode(slug: slug), sourceMessageId: message.id, progress: params.progress)
|
||||
self.openResolved(result: .premiumGiftCode(slug: slug), sourceMessageId: message.id, progress: params.progress)
|
||||
return true
|
||||
case .prizeStars:
|
||||
let controller = strongSelf.context.sharedContext.makeStarsGiftScreen(context: strongSelf.context, message: EngineMessage(message))
|
||||
strongSelf.push(controller)
|
||||
let controller = self.context.sharedContext.makeStarsGiftScreen(context: self.context, message: EngineMessage(message))
|
||||
self.push(controller)
|
||||
return true
|
||||
case let .suggestedProfilePhoto(image):
|
||||
strongSelf.chatDisplayNode.dismissInput()
|
||||
self.chatDisplayNode.dismissInput()
|
||||
if let image = image {
|
||||
if message.effectivelyIncoming(strongSelf.context.account.peerId) {
|
||||
if message.effectivelyIncoming(self.context.account.peerId) {
|
||||
if let emojiMarkup = image.emojiMarkup {
|
||||
let controller = AvatarEditorScreen(context: strongSelf.context, inputData: AvatarEditorScreen.inputData(context: strongSelf.context, isGroup: false), peerType: .user, markup: emojiMarkup)
|
||||
let controller = AvatarEditorScreen(context: self.context, inputData: AvatarEditorScreen.inputData(context: self.context, isGroup: false), peerType: .user, markup: emojiMarkup)
|
||||
controller.imageCompletion = { [weak self] image, commit in
|
||||
if let strongSelf = self {
|
||||
if let rootController = strongSelf.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
if let self {
|
||||
if let rootController = self.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
settingsController.updateProfilePhoto(image, mode: .accept, uploadStatus: nil)
|
||||
commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
controller.videoCompletion = { [weak self] image, url, values, markup, commit in
|
||||
if let strongSelf = self {
|
||||
if let rootController = strongSelf.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
if let self {
|
||||
if let rootController = self.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
settingsController.updateProfileVideo(image, video: nil, values: nil, markup: markup, mode: .accept, uploadStatus: nil)
|
||||
commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
strongSelf.push(controller)
|
||||
self.push(controller)
|
||||
} else {
|
||||
var selectedNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))?
|
||||
strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
self.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
if let itemNode = itemNode as? ChatMessageItemView {
|
||||
if let result = itemNode.transitionNode(id: message.id, media: image, adjustRect: false) {
|
||||
selectedNode = result
|
||||
@ -1267,17 +1271,17 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
senderName = nil
|
||||
}
|
||||
|
||||
legacyAvatarEditor(context: strongSelf.context, media: .message(message: MessageReference(message), media: image), transitionView: transitionView, senderName: senderName, present: { [weak self] c, a in
|
||||
legacyAvatarEditor(context: self.context, media: .message(message: MessageReference(message), media: image), transitionView: transitionView, senderName: senderName, present: { [weak self] c, a in
|
||||
self?.present(c, in: .window(.root), with: a)
|
||||
}, imageCompletion: { [weak self] image in
|
||||
if let strongSelf = self {
|
||||
if let rootController = strongSelf.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
if let self {
|
||||
if let rootController = self.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
settingsController.updateProfilePhoto(image, mode: .accept, uploadStatus: nil)
|
||||
}
|
||||
}
|
||||
}, videoCompletion: { [weak self] image, url, adjustments in
|
||||
if let strongSelf = self {
|
||||
if let rootController = strongSelf.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
if let self {
|
||||
if let rootController = self.effectiveNavigationController as? TelegramRootController, let settingsController = rootController.accountSettingsController as? PeerInfoScreenImpl {
|
||||
settingsController.oldUpdateProfileVideo(image, asset: AVURLAsset(url: url), adjustments: adjustments, mode: .accept)
|
||||
}
|
||||
}
|
||||
@ -1288,7 +1292,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}
|
||||
case .boostsApplied:
|
||||
strongSelf.controllerInteraction?.openGroupBoostInfo(nil, 0)
|
||||
self.controllerInteraction?.openGroupBoostInfo(nil, 0)
|
||||
return true
|
||||
default:
|
||||
break
|
||||
@ -1299,29 +1303,33 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}
|
||||
|
||||
let openChatLocation = strongSelf.chatLocation
|
||||
let openChatLocation = self.chatLocation
|
||||
var chatFilterTag: MemoryBuffer?
|
||||
if case let .customTag(value, _) = strongSelf.chatDisplayNode.historyNode.tag {
|
||||
if case let .customTag(value, _) = self.chatDisplayNode.historyNode.tag {
|
||||
chatFilterTag = value
|
||||
}
|
||||
|
||||
var standalone = false
|
||||
if case .customChatContents = strongSelf.chatLocation {
|
||||
if case .customChatContents = self.chatLocation {
|
||||
standalone = true
|
||||
}
|
||||
|
||||
if let adAttribute = message.attributes.first(where: { $0 is AdMessageAttribute }) as? AdMessageAttribute {
|
||||
if let file = message.media.first(where: { $0 is TelegramMediaFile}) as? TelegramMediaFile, file.isVideo && !file.isAnimated {
|
||||
strongSelf.chatDisplayNode.historyNode.adMessagesContext?.markAction(opaqueId: adAttribute.opaqueId, media: true, fullscreen: false)
|
||||
self.chatDisplayNode.historyNode.adMessagesContext?.markAction(opaqueId: adAttribute.opaqueId, media: true, fullscreen: false)
|
||||
} else {
|
||||
strongSelf.controllerInteraction?.activateAdAction(message.id, nil, true, false)
|
||||
self.controllerInteraction?.activateAdAction(message.id, nil, true, false)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return context.sharedContext.openChatMessage(OpenChatMessageParams(context: context, updatedPresentationData: strongSelf.updatedPresentationData, chatLocation: openChatLocation, chatFilterTag: chatFilterTag, chatLocationContextHolder: strongSelf.chatLocationContextHolder, message: message, mediaIndex: params.mediaIndex, standalone: standalone, reverseMessageGalleryOrder: false, mode: mode, navigationController: strongSelf.effectiveNavigationController, dismissInput: {
|
||||
let openChatMessageParams = OpenChatMessageParams(context: context, updatedPresentationData: self.updatedPresentationData, chatLocation: openChatLocation, chatFilterTag: chatFilterTag, chatLocationContextHolder: self.chatLocationContextHolder, message: message, mediaIndex: params.mediaIndex, standalone: standalone, reverseMessageGalleryOrder: false, mode: mode, navigationController: self.effectiveNavigationController, dismissInput: { [weak self] in
|
||||
self?.chatDisplayNode.dismissInput()
|
||||
}, present: { c, a, i in
|
||||
}, present: { [weak self] c, a, i in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
if case .current = i {
|
||||
c.presentationArguments = a
|
||||
c.statusBar.alphaUpdated = { [weak self] transition in
|
||||
@ -1330,14 +1338,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
self.updateStatusBarPresentation(animated: transition.isAnimated)
|
||||
}
|
||||
self?.galleryPresentationContext.present(c, on: PresentationSurfaceLevel(rawValue: 0), blockInteraction: true, completion: {})
|
||||
self.galleryPresentationContext.present(c, on: PresentationSurfaceLevel(rawValue: 0), blockInteraction: true, completion: {})
|
||||
} else {
|
||||
self?.present(c, in: .window(.root), with: a, blockInteraction: true)
|
||||
self.present(c, in: .window(.root), with: a, blockInteraction: true)
|
||||
}
|
||||
}, transitionNode: { messageId, media, adjustRect in
|
||||
}, transitionNode: { [weak self] messageId, media, adjustRect in
|
||||
var selectedNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))?
|
||||
if let strongSelf = self {
|
||||
strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
if let self {
|
||||
self.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
if let itemNode = itemNode as? ChatMessageItemView {
|
||||
if let result = itemNode.transitionNode(id: messageId, media: media, adjustRect: adjustRect) {
|
||||
selectedNode = result
|
||||
@ -1346,27 +1354,27 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}
|
||||
return selectedNode
|
||||
}, addToTransitionSurface: { view in
|
||||
guard let strongSelf = self else {
|
||||
}, addToTransitionSurface: { [weak self] view in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
strongSelf.chatDisplayNode.historyNode.view.superview?.insertSubview(view, aboveSubview: strongSelf.chatDisplayNode.historyNode.view)
|
||||
}, openUrl: { url in
|
||||
self.chatDisplayNode.historyNode.view.superview?.insertSubview(view, aboveSubview: self.chatDisplayNode.historyNode.view)
|
||||
}, openUrl: { [weak self] url in
|
||||
self?.openUrl(url, concealed: false, skipConcealedAlert: isLocation, message: nil)
|
||||
}, openPeer: { peer, navigation in
|
||||
}, openPeer: { [weak self] peer, navigation in
|
||||
self?.openPeer(peer: EnginePeer(peer), navigation: navigation, fromMessage: nil)
|
||||
}, callPeer: { peerId, isVideo in
|
||||
}, callPeer: { [weak self] peerId, isVideo in
|
||||
self?.controllerInteraction?.callPeer(peerId, isVideo)
|
||||
}, enqueueMessage: { message in
|
||||
}, enqueueMessage: { [weak self] message in
|
||||
self?.sendMessages([message])
|
||||
}, sendSticker: canSendMessagesToChat(strongSelf.presentationInterfaceState) ? { fileReference, sourceNode, sourceRect in
|
||||
}, sendSticker: canSendMessagesToChat(self.presentationInterfaceState) ? { [weak self] fileReference, sourceNode, sourceRect in
|
||||
return self?.controllerInteraction?.sendSticker(fileReference, false, false, nil, false, sourceNode, sourceRect, nil, []) ?? false
|
||||
} : nil, sendEmoji: canSendMessagesToChat(strongSelf.presentationInterfaceState) ? { text, attribute in
|
||||
} : nil, sendEmoji: canSendMessagesToChat(self.presentationInterfaceState) ? { [weak self] text, attribute in
|
||||
self?.controllerInteraction?.sendEmoji(text, attribute, false)
|
||||
} : nil, setupTemporaryHiddenMedia: { signal, centralIndex, galleryMedia in
|
||||
if let strongSelf = self {
|
||||
strongSelf.temporaryHiddenGalleryMediaDisposable.set((signal |> deliverOnMainQueue).startStrict(next: { entry in
|
||||
if let strongSelf = self, let controllerInteraction = strongSelf.controllerInteraction {
|
||||
} : nil, setupTemporaryHiddenMedia: { [weak self] signal, centralIndex, galleryMedia in
|
||||
if let self {
|
||||
self.temporaryHiddenGalleryMediaDisposable.set((signal |> deliverOnMainQueue).startStrict(next: { [weak self] entry in
|
||||
if let self, let controllerInteraction = self.controllerInteraction {
|
||||
var messageIdAndMedia: [MessageId: [Media]] = [:]
|
||||
|
||||
if let entry = entry as? InstantPageGalleryEntry, entry.index == centralIndex {
|
||||
@ -1375,7 +1383,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
|
||||
controllerInteraction.hiddenMedia = messageIdAndMedia
|
||||
|
||||
strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
self.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
if let itemNode = itemNode as? ChatMessageItemView {
|
||||
itemNode.updateHiddenMedia()
|
||||
}
|
||||
@ -1383,10 +1391,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}))
|
||||
}
|
||||
}, chatAvatarHiddenMedia: { signal, media in
|
||||
if let strongSelf = self {
|
||||
strongSelf.temporaryHiddenGalleryMediaDisposable.set((signal |> deliverOnMainQueue).startStrict(next: { messageId in
|
||||
if let strongSelf = self, let controllerInteraction = strongSelf.controllerInteraction {
|
||||
}, chatAvatarHiddenMedia: { [weak self] signal, media in
|
||||
if let self {
|
||||
self.temporaryHiddenGalleryMediaDisposable.set((signal |> deliverOnMainQueue).startStrict(next: { [weak self] messageId in
|
||||
if let self, let controllerInteraction = self.controllerInteraction {
|
||||
var messageIdAndMedia: [MessageId: [Media]] = [:]
|
||||
|
||||
if let messageId = messageId {
|
||||
@ -1395,7 +1403,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
|
||||
controllerInteraction.hiddenMedia = messageIdAndMedia
|
||||
|
||||
strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
self.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||
if let itemNode = itemNode as? ChatMessageItemView {
|
||||
itemNode.updateHiddenMedia()
|
||||
}
|
||||
@ -1405,54 +1413,54 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
}, actionInteraction: GalleryControllerActionInteraction(
|
||||
openUrl: { [weak self] url, concealed in
|
||||
if let strongSelf = self {
|
||||
strongSelf.openUrl(url, concealed: concealed, message: nil)
|
||||
if let self {
|
||||
self.openUrl(url, concealed: concealed, message: nil)
|
||||
}
|
||||
}, openUrlIn: { [weak self] url in
|
||||
if let strongSelf = self {
|
||||
strongSelf.openUrlIn(url)
|
||||
if let self {
|
||||
self.openUrlIn(url)
|
||||
}
|
||||
}, openPeerMention: { [weak self] mention in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.openPeerMention(mention, nil)
|
||||
if let self {
|
||||
self.controllerInteraction?.openPeerMention(mention, nil)
|
||||
}
|
||||
}, openPeer: { [weak self] peer in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.openPeer(peer, .default, nil, .default)
|
||||
if let self {
|
||||
self.controllerInteraction?.openPeer(peer, .default, nil, .default)
|
||||
}
|
||||
}, openHashtag: { [weak self] peerName, hashtag in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.openHashtag(peerName, hashtag)
|
||||
if let self {
|
||||
self.controllerInteraction?.openHashtag(peerName, hashtag)
|
||||
}
|
||||
}, openBotCommand: { [weak self] command in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.sendBotCommand(nil, command)
|
||||
if let self {
|
||||
self.controllerInteraction?.sendBotCommand(nil, command)
|
||||
}
|
||||
}, openAd: { [weak self] messageId in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.activateAdAction(messageId, nil, true, true)
|
||||
if let self {
|
||||
self.controllerInteraction?.activateAdAction(messageId, nil, true, true)
|
||||
}
|
||||
}, addContact: { [weak self] phoneNumber in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerInteraction?.addContact(phoneNumber)
|
||||
if let self {
|
||||
self.controllerInteraction?.addContact(phoneNumber)
|
||||
}
|
||||
}, storeMediaPlaybackState: { [weak self] messageId, timestamp, playbackRate in
|
||||
guard let strongSelf = self else {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
var storedState: MediaPlaybackStoredState?
|
||||
if let timestamp = timestamp {
|
||||
storedState = MediaPlaybackStoredState(timestamp: timestamp, playbackRate: AudioPlaybackRate(playbackRate))
|
||||
}
|
||||
let _ = updateMediaPlaybackStoredStateInteractively(engine: strongSelf.context.engine, messageId: messageId, state: storedState).startStandalone()
|
||||
let _ = updateMediaPlaybackStoredStateInteractively(engine: self.context.engine, messageId: messageId, state: storedState).startStandalone()
|
||||
}, editMedia: { [weak self] messageId, snapshots, transitionCompletion in
|
||||
guard let strongSelf = self else {
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
let _ = (strongSelf.context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: messageId))
|
||||
let _ = (self.context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: messageId))
|
||||
|> deliverOnMainQueue).startStandalone(next: { [weak self] message in
|
||||
guard let strongSelf = self, let message = message else {
|
||||
guard let self, let message = message else {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1472,17 +1480,17 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
|
||||
if let mediaReference = mediaReference, let peer = message.peers[message.id.peerId] {
|
||||
legacyMediaEditor(context: strongSelf.context, peer: peer, threadTitle: strongSelf.threadInfo?.title, media: mediaReference, mode: .draw, initialCaption: NSAttributedString(), snapshots: snapshots, transitionCompletion: {
|
||||
legacyMediaEditor(context: self.context, peer: peer, threadTitle: self.threadInfo?.title, media: mediaReference, mode: .draw, initialCaption: NSAttributedString(), snapshots: snapshots, transitionCompletion: {
|
||||
transitionCompletion()
|
||||
}, getCaptionPanelView: { [weak self] in
|
||||
return self?.getCaptionPanelView(isFile: false)
|
||||
}, sendMessagesWithSignals: { [weak self] signals, _, _, isCaptionAbove in
|
||||
if let strongSelf = self {
|
||||
if let self {
|
||||
var parameters: ChatSendMessageActionSheetController.SendParameters?
|
||||
if isCaptionAbove {
|
||||
parameters = ChatSendMessageActionSheetController.SendParameters(effect: nil, textIsAboveMedia: true)
|
||||
}
|
||||
strongSelf.enqueueMediaMessages(signals: signals, silentPosting: false, parameters: parameters)
|
||||
self.enqueueMediaMessages(signals: signals, silentPosting: false, parameters: parameters)
|
||||
}
|
||||
}, present: { [weak self] c, a in
|
||||
self?.present(c, in: .window(.root), with: a)
|
||||
@ -1493,18 +1501,22 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
self?.canReadHistory.set(canReadHistory)
|
||||
}),
|
||||
getSourceRect: { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
guard let self else {
|
||||
return nil
|
||||
}
|
||||
var rect: CGRect?
|
||||
strongSelf.chatDisplayNode.historyNode.forEachVisibleMessageItemNode({ itemNode in
|
||||
self.chatDisplayNode.historyNode.forEachVisibleMessageItemNode({ itemNode in
|
||||
if itemNode.item?.message.id == message.id {
|
||||
rect = itemNode.view.convert(itemNode.contentFrame(), to: nil)
|
||||
}
|
||||
})
|
||||
return rect
|
||||
}
|
||||
))
|
||||
)
|
||||
|
||||
self.controllerInteraction?.isOpeningMediaSignal = openChatMessageParams.blockInteraction.get()
|
||||
|
||||
return context.sharedContext.openChatMessage(openChatMessageParams)
|
||||
}, openPeer: { [weak self] peer, navigation, fromMessage, source in
|
||||
var expandAvatar = false
|
||||
if case let .groupParticipant(storyStats, avatarHeaderNode) = source {
|
||||
|
Loading…
x
Reference in New Issue
Block a user