mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Do not show group message notifications in CarPlay
Navigate to original message on tapping reaction notifications
This commit is contained in:
parent
da558c4026
commit
d700f45c1c
@ -1054,7 +1054,12 @@ private final class NotificationServiceHandler {
|
||||
}
|
||||
|
||||
if let category = aps["category"] as? String {
|
||||
if peerId.isGroupOrChannel && ["r", "m"].contains(category) {
|
||||
content.category = "g\(category)"
|
||||
} else {
|
||||
content.category = category
|
||||
}
|
||||
|
||||
|
||||
let _ = messageId
|
||||
|
||||
|
@ -2395,7 +2395,7 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
|
||||
if let (peerId, threadId) = peerIdFromNotification(response.notification) {
|
||||
var messageId: MessageId? = nil
|
||||
if response.notification.request.content.categoryIdentifier == "watch" {
|
||||
if response.notification.request.content.categoryIdentifier == "c" {
|
||||
messageId = messageIdFromNotification(peerId: peerId, notification: response.notification)
|
||||
}
|
||||
self.openChatWhenReady(accountId: accountId, peerId: peerId, threadId: threadId, messageId: messageId)
|
||||
@ -2493,7 +2493,6 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}
|
||||
|
||||
private func registerForNotifications(replyString: String, messagePlaceholderString: String, hiddenContentString: String, includeNames: Bool, authorize: Bool = true, completion: @escaping (Bool) -> Void = { _ in }) {
|
||||
if #available(iOS 10.0, *) {
|
||||
let notificationCenter = UNUserNotificationCenter.current()
|
||||
Logger.shared.log("App \(self.episodeId)", "register for notifications: get settings (authorize: \(authorize))")
|
||||
notificationCenter.getNotificationSettings(completionHandler: { settings in
|
||||
@ -2517,13 +2516,11 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
let reply = UNTextInputNotificationAction(identifier: "reply", title: replyString, options: [], textInputButtonTitle: replyString, textInputPlaceholder: messagePlaceholderString)
|
||||
|
||||
let unknownMessageCategory: UNNotificationCategory
|
||||
let replyMessageCategory: UNNotificationCategory
|
||||
let replyLegacyMessageCategory: UNNotificationCategory
|
||||
let replyLegacyMediaMessageCategory: UNNotificationCategory
|
||||
let replyMediaMessageCategory: UNNotificationCategory
|
||||
let legacyChannelMessageCategory: UNNotificationCategory
|
||||
let muteMessageCategory: UNNotificationCategory
|
||||
let muteMediaMessageCategory: UNNotificationCategory
|
||||
let repliableMessageCategory: UNNotificationCategory
|
||||
let repliableMediaMessageCategory: UNNotificationCategory
|
||||
let groupRepliableMessageCategory: UNNotificationCategory
|
||||
let groupRepliableMediaMessageCategory: UNNotificationCategory
|
||||
let channelMessageCategory: UNNotificationCategory
|
||||
|
||||
if #available(iOS 11.0, *) {
|
||||
var options: UNNotificationCategoryOptions = []
|
||||
@ -2538,27 +2535,30 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}
|
||||
|
||||
unknownMessageCategory = UNNotificationCategory(identifier: "unknown", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
replyMessageCategory = UNNotificationCategory(identifier: "withReply", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
replyLegacyMessageCategory = UNNotificationCategory(identifier: "r", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
replyLegacyMediaMessageCategory = UNNotificationCategory(identifier: "m", actions: [reply], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
replyMediaMessageCategory = UNNotificationCategory(identifier: "withReplyMedia", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
legacyChannelMessageCategory = UNNotificationCategory(identifier: "c", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
muteMessageCategory = UNNotificationCategory(identifier: "withMute", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
muteMediaMessageCategory = UNNotificationCategory(identifier: "withMuteMedia", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
repliableMessageCategory = UNNotificationCategory(identifier: "r", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
repliableMediaMessageCategory = UNNotificationCategory(identifier: "m", actions: [reply], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: carPlayOptions)
|
||||
groupRepliableMessageCategory = UNNotificationCategory(identifier: "gr", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
groupRepliableMediaMessageCategory = UNNotificationCategory(identifier: "gm", actions: [reply], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
channelMessageCategory = UNNotificationCategory(identifier: "c", actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: hiddenContentString, options: options)
|
||||
} else {
|
||||
let carPlayOptions: UNNotificationCategoryOptions = [.allowInCarPlay]
|
||||
|
||||
unknownMessageCategory = UNNotificationCategory(identifier: "unknown", actions: [], intentIdentifiers: [], options: [])
|
||||
replyMessageCategory = UNNotificationCategory(identifier: "withReply", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], options: carPlayOptions)
|
||||
replyLegacyMessageCategory = UNNotificationCategory(identifier: "r", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], options: carPlayOptions)
|
||||
replyLegacyMediaMessageCategory = UNNotificationCategory(identifier: "m", actions: [reply], intentIdentifiers: [], options: [])
|
||||
replyMediaMessageCategory = UNNotificationCategory(identifier: "withReplyMedia", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], options: carPlayOptions)
|
||||
legacyChannelMessageCategory = UNNotificationCategory(identifier: "c", actions: [], intentIdentifiers: [], options: [])
|
||||
muteMessageCategory = UNNotificationCategory(identifier: "withMute", actions: [], intentIdentifiers: [], options: [])
|
||||
muteMediaMessageCategory = UNNotificationCategory(identifier: "withMuteMedia", actions: [], intentIdentifiers: [], options: [])
|
||||
repliableMessageCategory = UNNotificationCategory(identifier: "r", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], options: carPlayOptions)
|
||||
repliableMediaMessageCategory = UNNotificationCategory(identifier: "m", actions: [reply], intentIdentifiers: [], options: [])
|
||||
groupRepliableMessageCategory = UNNotificationCategory(identifier: "gr", actions: [reply], intentIdentifiers: [INSearchForMessagesIntentIdentifier], options: [])
|
||||
groupRepliableMediaMessageCategory = UNNotificationCategory(identifier: "gm", actions: [reply], intentIdentifiers: [], options: [])
|
||||
channelMessageCategory = UNNotificationCategory(identifier: "c", actions: [], intentIdentifiers: [], options: [])
|
||||
}
|
||||
|
||||
UNUserNotificationCenter.current().setNotificationCategories([unknownMessageCategory, replyMessageCategory, replyLegacyMessageCategory, replyLegacyMediaMessageCategory, replyMediaMessageCategory, legacyChannelMessageCategory, muteMessageCategory, muteMediaMessageCategory])
|
||||
UNUserNotificationCenter.current().setNotificationCategories([
|
||||
unknownMessageCategory,
|
||||
repliableMessageCategory,
|
||||
repliableMediaMessageCategory,
|
||||
channelMessageCategory,
|
||||
groupRepliableMessageCategory,
|
||||
groupRepliableMediaMessageCategory
|
||||
])
|
||||
|
||||
Logger.shared.log("App \(self.episodeId)", "register for notifications: invoke registerForRemoteNotifications")
|
||||
UIApplication.shared.registerForRemoteNotifications()
|
||||
@ -2569,47 +2569,6 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
break
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let reply = UIMutableUserNotificationAction()
|
||||
reply.identifier = "reply"
|
||||
reply.title = replyString
|
||||
reply.isDestructive = false
|
||||
reply.isAuthenticationRequired = false
|
||||
reply.behavior = .textInput
|
||||
reply.activationMode = .background
|
||||
|
||||
let unknownMessageCategory = UIMutableUserNotificationCategory()
|
||||
unknownMessageCategory.identifier = "unknown"
|
||||
|
||||
let replyMessageCategory = UIMutableUserNotificationCategory()
|
||||
replyMessageCategory.identifier = "withReply"
|
||||
replyMessageCategory.setActions([reply], for: .default)
|
||||
|
||||
let replyLegacyMessageCategory = UIMutableUserNotificationCategory()
|
||||
replyLegacyMessageCategory.identifier = "r"
|
||||
replyLegacyMessageCategory.setActions([reply], for: .default)
|
||||
|
||||
let replyLegacyMediaMessageCategory = UIMutableUserNotificationCategory()
|
||||
replyLegacyMediaMessageCategory.identifier = "m"
|
||||
replyLegacyMediaMessageCategory.setActions([reply], for: .default)
|
||||
|
||||
let replyMediaMessageCategory = UIMutableUserNotificationCategory()
|
||||
replyMediaMessageCategory.identifier = "withReplyMedia"
|
||||
replyMediaMessageCategory.setActions([reply], for: .default)
|
||||
|
||||
let legacyChannelMessageCategory = UIMutableUserNotificationCategory()
|
||||
legacyChannelMessageCategory.identifier = "c"
|
||||
|
||||
let muteMessageCategory = UIMutableUserNotificationCategory()
|
||||
muteMessageCategory.identifier = "withMute"
|
||||
|
||||
let muteMediaMessageCategory = UIMutableUserNotificationCategory()
|
||||
muteMediaMessageCategory.identifier = "withMuteMedia"
|
||||
|
||||
let settings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: [])
|
||||
UIApplication.shared.registerUserNotificationSettings(settings)
|
||||
UIApplication.shared.registerForRemoteNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 10.0, *)
|
||||
|
@ -101,8 +101,6 @@ final class AuthorizedApplicationContext {
|
||||
let rootController: TelegramRootController
|
||||
let notificationController: NotificationContainerController
|
||||
|
||||
private var scheduledOpenNotificationSettings: Bool = false
|
||||
private var scheduledOpenChatWithPeerId: (PeerId, MessageId?, Bool)?
|
||||
private let scheduledCallPeerDisposable = MetaDisposable()
|
||||
private var scheduledOpenExternalUrl: URL?
|
||||
|
||||
@ -833,11 +831,7 @@ final class AuthorizedApplicationContext {
|
||||
}
|
||||
|
||||
func openNotificationSettings() {
|
||||
if self.rootController.rootTabController != nil {
|
||||
self.rootController.pushViewController(notificationsAndSoundsController(context: self.context, exceptionsList: nil))
|
||||
} else {
|
||||
self.scheduledOpenNotificationSettings = true
|
||||
}
|
||||
}
|
||||
|
||||
func startCall(peerId: PeerId, isVideo: Bool) {
|
||||
@ -864,9 +858,25 @@ final class AuthorizedApplicationContext {
|
||||
}
|
||||
|
||||
if visiblePeerId != peerId || messageId != nil {
|
||||
if self.rootController.rootTabController != nil {
|
||||
let _ = (self.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId))
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
let isOutgoingMessage: Signal<Bool, NoError>
|
||||
if let messageId {
|
||||
let accountPeerId = self.context.account.peerId
|
||||
isOutgoingMessage = self.context.engine.data.get(TelegramEngine.EngineData.Item.Messages.Message(id: messageId))
|
||||
|> map { message -> Bool in
|
||||
if let message {
|
||||
return !message._asMessage().effectivelyIncoming(accountPeerId)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isOutgoingMessage = .single(false)
|
||||
}
|
||||
let _ = combineLatest(
|
||||
queue: Queue.mainQueue(),
|
||||
self.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)),
|
||||
isOutgoingMessage
|
||||
).start(next: { peer, isOutgoingMessage in
|
||||
guard let peer = peer else {
|
||||
return
|
||||
}
|
||||
@ -880,11 +890,8 @@ final class AuthorizedApplicationContext {
|
||||
chatLocation = .peer(peer)
|
||||
}
|
||||
|
||||
self.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: self.rootController, context: self.context, chatLocation: chatLocation, subject: messageId.flatMap { .message(id: .id($0), highlight: true, timecode: nil) }, activateInput: activateInput ? .text : nil))
|
||||
self.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: self.rootController, context: self.context, chatLocation: chatLocation, subject: isOutgoingMessage ? messageId.flatMap { .message(id: .id($0), highlight: true, timecode: nil) } : nil, activateInput: activateInput ? .text : nil))
|
||||
})
|
||||
} else {
|
||||
self.scheduledOpenChatWithPeerId = (peerId, messageId, activateInput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user