mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'beta'
This commit is contained in:
commit
f735b1a96c
@ -21,6 +21,7 @@ swift_library(
|
|||||||
"//submodules/rlottie:RLottieBinding",
|
"//submodules/rlottie:RLottieBinding",
|
||||||
"//submodules/GZip:GZip",
|
"//submodules/GZip:GZip",
|
||||||
"//submodules/PersistentStringHash:PersistentStringHash",
|
"//submodules/PersistentStringHash:PersistentStringHash",
|
||||||
|
|
||||||
],
|
],
|
||||||
visibility = [
|
visibility = [
|
||||||
"//visibility:public",
|
"//visibility:public",
|
||||||
|
@ -13,6 +13,8 @@ import UIKit
|
|||||||
import Intents
|
import Intents
|
||||||
import PersistentStringHash
|
import PersistentStringHash
|
||||||
import CallKit
|
import CallKit
|
||||||
|
import AppLockState
|
||||||
|
import NotificationsPresentationData
|
||||||
|
|
||||||
private let queue = Queue()
|
private let queue = Queue()
|
||||||
|
|
||||||
@ -438,6 +440,12 @@ private struct NotificationContent: CustomStringConvertible {
|
|||||||
|
|
||||||
var senderPerson: INPerson?
|
var senderPerson: INPerson?
|
||||||
var senderImage: INImage?
|
var senderImage: INImage?
|
||||||
|
|
||||||
|
var isLockedMessage: String?
|
||||||
|
|
||||||
|
init(isLockedMessage: String?) {
|
||||||
|
self.isLockedMessage = isLockedMessage
|
||||||
|
}
|
||||||
|
|
||||||
var description: String {
|
var description: String {
|
||||||
var string = "{"
|
var string = "{"
|
||||||
@ -450,6 +458,7 @@ private struct NotificationContent: CustomStringConvertible {
|
|||||||
string += " category: \(String(describing: self.category)),\n"
|
string += " category: \(String(describing: self.category)),\n"
|
||||||
string += " userInfo: \(String(describing: self.userInfo)),\n"
|
string += " userInfo: \(String(describing: self.userInfo)),\n"
|
||||||
string += " senderImage: \(self.senderImage != nil ? "non-empty" : "empty"),\n"
|
string += " senderImage: \(self.senderImage != nil ? "non-empty" : "empty"),\n"
|
||||||
|
string += " isLockedMessage: \(String(describing: self.isLockedMessage)),\n"
|
||||||
string += "}"
|
string += "}"
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
@ -479,14 +488,18 @@ private struct NotificationContent: CustomStringConvertible {
|
|||||||
func generate() -> UNNotificationContent {
|
func generate() -> UNNotificationContent {
|
||||||
var content = UNMutableNotificationContent()
|
var content = UNMutableNotificationContent()
|
||||||
|
|
||||||
if let title = self.title {
|
if let isLockedMessage = self.isLockedMessage {
|
||||||
content.title = title
|
content.body = isLockedMessage
|
||||||
}
|
} else {
|
||||||
if let subtitle = self.subtitle {
|
if let title = self.title {
|
||||||
content.subtitle = subtitle
|
content.title = title
|
||||||
}
|
}
|
||||||
if let body = self.body {
|
if let subtitle = self.subtitle {
|
||||||
content.body = body
|
content.subtitle = subtitle
|
||||||
|
}
|
||||||
|
if let body = self.body {
|
||||||
|
content.body = body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let threadId = self.threadId {
|
if let threadId = self.threadId {
|
||||||
content.threadIdentifier = threadId
|
content.threadIdentifier = threadId
|
||||||
@ -508,7 +521,7 @@ private struct NotificationContent: CustomStringConvertible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if #available(iOS 15.0, *) {
|
if #available(iOS 15.0, *) {
|
||||||
if let senderPerson = self.senderPerson, let customIdentifier = senderPerson.customIdentifier {
|
if self.isLockedMessage == nil, let senderPerson = self.senderPerson, let customIdentifier = senderPerson.customIdentifier {
|
||||||
let mePerson = INPerson(
|
let mePerson = INPerson(
|
||||||
personHandle: INPersonHandle(value: "0", type: .unknown),
|
personHandle: INPersonHandle(value: "0", type: .unknown),
|
||||||
nameComponents: nil,
|
nameComponents: nil,
|
||||||
@ -603,6 +616,17 @@ private final class NotificationServiceHandler {
|
|||||||
self.encryptionParameters = ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: deviceSpecificEncryptionParameters.key)!, salt: ValueBoxEncryptionParameters.Salt(data: deviceSpecificEncryptionParameters.salt)!)
|
self.encryptionParameters = ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: deviceSpecificEncryptionParameters.key)!, salt: ValueBoxEncryptionParameters.Salt(data: deviceSpecificEncryptionParameters.salt)!)
|
||||||
|
|
||||||
let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, voipVersions: [], appData: .single(buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider(), resolvedDeviceName: nil)
|
let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, voipVersions: [], appData: .single(buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider(), resolvedDeviceName: nil)
|
||||||
|
|
||||||
|
let isLockedMessage: String?
|
||||||
|
if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data), isAppLocked(state: state) {
|
||||||
|
if let notificationsPresentationData = try? Data(contentsOf: URL(fileURLWithPath: notificationsPresentationDataPath(rootPath: rootPath))), let notificationsPresentationDataValue = try? JSONDecoder().decode(NotificationsPresentationData.self, from: notificationsPresentationData) {
|
||||||
|
isLockedMessage = notificationsPresentationDataValue.applicationLockedMessageString
|
||||||
|
} else {
|
||||||
|
isLockedMessage = "You have a new message"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
isLockedMessage = nil
|
||||||
|
}
|
||||||
|
|
||||||
Logger.shared.log("NotificationService \(episode)", "Begin processing payload \(payload)")
|
Logger.shared.log("NotificationService \(episode)", "Begin processing payload \(payload)")
|
||||||
|
|
||||||
@ -650,7 +674,7 @@ private final class NotificationServiceHandler {
|
|||||||
guard let strongSelf = self, let recordId = recordId else {
|
guard let strongSelf = self, let recordId = recordId else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Couldn't find a matching decryption key")
|
Logger.shared.log("NotificationService \(episode)", "Couldn't find a matching decryption key")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
|
|
||||||
@ -672,7 +696,7 @@ private final class NotificationServiceHandler {
|
|||||||
guard let stateManager = stateManager else {
|
guard let stateManager = stateManager else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Didn't receive stateManager")
|
Logger.shared.log("NotificationService \(episode)", "Didn't receive stateManager")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
return
|
return
|
||||||
@ -682,7 +706,7 @@ private final class NotificationServiceHandler {
|
|||||||
strongSelf.notificationKeyDisposable.set((existingMasterNotificationsKey(postbox: stateManager.postbox)
|
strongSelf.notificationKeyDisposable.set((existingMasterNotificationsKey(postbox: stateManager.postbox)
|
||||||
|> deliverOn(strongSelf.queue)).start(next: { notificationsKey in
|
|> deliverOn(strongSelf.queue)).start(next: { notificationsKey in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
|
|
||||||
@ -691,7 +715,7 @@ private final class NotificationServiceHandler {
|
|||||||
guard let notificationsKey = notificationsKey else {
|
guard let notificationsKey = notificationsKey else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Didn't receive decryption key")
|
Logger.shared.log("NotificationService \(episode)", "Didn't receive decryption key")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
|
|
||||||
@ -700,7 +724,7 @@ private final class NotificationServiceHandler {
|
|||||||
guard let decryptedPayload = decryptedNotificationPayload(key: notificationsKey, data: payloadData) else {
|
guard let decryptedPayload = decryptedNotificationPayload(key: notificationsKey, data: payloadData) else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Couldn't decrypt payload")
|
Logger.shared.log("NotificationService \(episode)", "Couldn't decrypt payload")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
|
|
||||||
@ -709,7 +733,7 @@ private final class NotificationServiceHandler {
|
|||||||
guard let payloadJson = try? JSONSerialization.jsonObject(with: decryptedPayload, options: []) as? [String: Any] else {
|
guard let payloadJson = try? JSONSerialization.jsonObject(with: decryptedPayload, options: []) as? [String: Any] else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Couldn't process payload as JSON")
|
Logger.shared.log("NotificationService \(episode)", "Couldn't process payload as JSON")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
|
|
||||||
@ -786,7 +810,7 @@ private final class NotificationServiceHandler {
|
|||||||
action = .logout
|
action = .logout
|
||||||
case "MESSAGE_MUTED":
|
case "MESSAGE_MUTED":
|
||||||
if let peerId = peerId {
|
if let peerId = peerId {
|
||||||
action = .poll(peerId: peerId, content: NotificationContent())
|
action = .poll(peerId: peerId, content: NotificationContent(isLockedMessage: isLockedMessage))
|
||||||
}
|
}
|
||||||
case "MESSAGE_DELETED":
|
case "MESSAGE_DELETED":
|
||||||
if let peerId = peerId {
|
if let peerId = peerId {
|
||||||
@ -815,7 +839,7 @@ private final class NotificationServiceHandler {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let aps = payloadJson["aps"] as? [String: Any], let peerId = peerId {
|
if let aps = payloadJson["aps"] as? [String: Any], let peerId = peerId {
|
||||||
var content: NotificationContent = NotificationContent()
|
var content: NotificationContent = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
if let alert = aps["alert"] as? [String: Any] {
|
if let alert = aps["alert"] as? [String: Any] {
|
||||||
content.title = alert["title"] as? String
|
content.title = alert["title"] as? String
|
||||||
content.subtitle = alert["subtitle"] as? String
|
content.subtitle = alert["subtitle"] as? String
|
||||||
@ -914,7 +938,7 @@ private final class NotificationServiceHandler {
|
|||||||
"accountId": "\(callData.accountId)"
|
"accountId": "\(callData.accountId)"
|
||||||
]
|
]
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
|
|
||||||
if #available(iOS 14.5, *) {
|
if #available(iOS 14.5, *) {
|
||||||
@ -929,7 +953,7 @@ private final class NotificationServiceHandler {
|
|||||||
case .logout:
|
case .logout:
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will logout")
|
Logger.shared.log("NotificationService \(episode)", "Will logout")
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
case let .poll(peerId, initialContent):
|
case let .poll(peerId, initialContent):
|
||||||
@ -941,7 +965,7 @@ private final class NotificationServiceHandler {
|
|||||||
queue.async {
|
queue.async {
|
||||||
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
||||||
|
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
return
|
return
|
||||||
@ -1185,7 +1209,7 @@ private final class NotificationServiceHandler {
|
|||||||
postbox: stateManager.postbox
|
postbox: stateManager.postbox
|
||||||
)
|
)
|
||||||
|> deliverOn(strongSelf.queue)).start(next: { value in
|
|> deliverOn(strongSelf.queue)).start(next: { value in
|
||||||
var content = NotificationContent()
|
var content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
if isCurrentAccount {
|
if isCurrentAccount {
|
||||||
content.badge = Int(value.0)
|
content.badge = Int(value.0)
|
||||||
}
|
}
|
||||||
@ -1234,7 +1258,7 @@ private final class NotificationServiceHandler {
|
|||||||
postbox: stateManager.postbox
|
postbox: stateManager.postbox
|
||||||
)
|
)
|
||||||
|> deliverOn(strongSelf.queue)).start(next: { value in
|
|> deliverOn(strongSelf.queue)).start(next: { value in
|
||||||
var content = NotificationContent()
|
var content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
if isCurrentAccount {
|
if isCurrentAccount {
|
||||||
content.badge = Int(value.0)
|
content.badge = Int(value.0)
|
||||||
}
|
}
|
||||||
@ -1261,7 +1285,7 @@ private final class NotificationServiceHandler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let content = NotificationContent()
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
|
|
||||||
completed()
|
completed()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user