mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Pre-release improvements
This commit is contained in:
@@ -722,9 +722,15 @@ private final class NotificationServiceHandler {
|
||||
return
|
||||
}
|
||||
strongSelf.stateManager = stateManager
|
||||
|
||||
let settings = stateManager.postbox.transaction { transaction -> NotificationSoundList? in
|
||||
return _internal_cachedNotificationSoundList(transaction: transaction)
|
||||
}
|
||||
|
||||
strongSelf.notificationKeyDisposable.set((existingMasterNotificationsKey(postbox: stateManager.postbox)
|
||||
|> deliverOn(strongSelf.queue)).start(next: { notificationsKey in
|
||||
strongSelf.notificationKeyDisposable.set((combineLatest(queue: strongSelf.queue,
|
||||
existingMasterNotificationsKey(postbox: stateManager.postbox),
|
||||
settings
|
||||
) |> deliverOn(strongSelf.queue)).start(next: { notificationsKey, notificationSoundList in
|
||||
guard let strongSelf = self else {
|
||||
let content = NotificationContent(isLockedMessage: nil)
|
||||
updateCurrentContent(content)
|
||||
@@ -765,6 +771,7 @@ private final class NotificationServiceHandler {
|
||||
var peerId: PeerId?
|
||||
var messageId: MessageId.Id?
|
||||
var mediaAttachment: Media?
|
||||
var downloadNotificationSound: (file: TelegramMediaFile, path: String, fileName: String)?
|
||||
|
||||
var interactionAuthorId: PeerId?
|
||||
|
||||
@@ -925,12 +932,31 @@ private final class NotificationServiceHandler {
|
||||
content.threadId = threadId
|
||||
}
|
||||
|
||||
if let sound = aps["sound"] as? String {
|
||||
if let customSoundPath = customSoundPath {
|
||||
content.sound = customSoundPath
|
||||
} else {
|
||||
content.sound = sound
|
||||
if let ringtoneString = aps["ringtone"] as? String, let fileId = Int64(ringtoneString) {
|
||||
content.sound = "0.m4a"
|
||||
if let notificationSoundList = notificationSoundList {
|
||||
for sound in notificationSoundList.sounds {
|
||||
if sound.file.fileId.id == fileId {
|
||||
let containerSoundsPath = appGroupUrl.path + "/Library/Sounds"
|
||||
let soundFileName = "\(fileId).mp3"
|
||||
let soundFilePath = containerSoundsPath + "/\(soundFileName)"
|
||||
|
||||
if !FileManager.default.fileExists(atPath: soundFilePath) {
|
||||
let _ = try? FileManager.default.createDirectory(atPath: containerSoundsPath, withIntermediateDirectories: true, attributes: nil)
|
||||
if let filePath = stateManager.postbox.mediaBox.completedResourcePath(id: sound.file.resource.id, pathExtension: nil) {
|
||||
let _ = try? FileManager.default.copyItem(atPath: filePath, toPath: soundFilePath)
|
||||
} else {
|
||||
downloadNotificationSound = (sound.file, soundFilePath, soundFileName)
|
||||
}
|
||||
}
|
||||
|
||||
content.sound = soundFileName
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let sound = aps["sound"] as? String {
|
||||
content.sound = sound
|
||||
}
|
||||
|
||||
if let category = aps["category"] as? String {
|
||||
@@ -1014,7 +1040,6 @@ private final class NotificationServiceHandler {
|
||||
|
||||
queue.async {
|
||||
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
||||
|
||||
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||
updateCurrentContent(content)
|
||||
completed()
|
||||
@@ -1078,17 +1103,79 @@ private final class NotificationServiceHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var fetchNotificationSoundSignal: Signal<Data?, NoError> = .single(nil)
|
||||
if let (downloadNotificationSound, _, _) = downloadNotificationSound {
|
||||
var fetchResource: TelegramMultipartFetchableResource?
|
||||
fetchResource = downloadNotificationSound.resource as? TelegramMultipartFetchableResource
|
||||
|
||||
if let resource = fetchResource {
|
||||
if let _ = strongSelf.stateManager?.postbox.mediaBox.completedResourcePath(resource) {
|
||||
} else {
|
||||
let intervals: Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError> = .single([(0 ..< Int(Int32.max), MediaBoxFetchPriority.maximum)])
|
||||
fetchNotificationSoundSignal = Signal { subscriber in
|
||||
let collectedData = Atomic<Data>(value: Data())
|
||||
return standaloneMultipartFetch(
|
||||
postbox: stateManager.postbox,
|
||||
network: stateManager.network,
|
||||
resource: resource,
|
||||
datacenterId: resource.datacenterId,
|
||||
size: nil,
|
||||
intervals: intervals,
|
||||
parameters: MediaResourceFetchParameters(
|
||||
tag: nil,
|
||||
info: resourceFetchInfo(resource: resource),
|
||||
isRandomAccessAllowed: true
|
||||
),
|
||||
encryptionKey: nil,
|
||||
decryptedSize: nil,
|
||||
continueInBackground: false,
|
||||
useMainConnection: true
|
||||
).start(next: { result in
|
||||
switch result {
|
||||
case let .dataPart(_, data, _, _):
|
||||
let _ = collectedData.modify { current in
|
||||
var current = current
|
||||
current.append(data)
|
||||
return current
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}, error: { _ in
|
||||
subscriber.putNext(nil)
|
||||
subscriber.putCompletion()
|
||||
}, completed: {
|
||||
subscriber.putNext(collectedData.with({ $0 }))
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger.shared.log("NotificationService \(episode)", "Will fetch media")
|
||||
let _ = (fetchMediaSignal
|
||||
|> timeout(10.0, queue: queue, alternate: .single(nil))
|
||||
|> deliverOn(queue)).start(next: { mediaData in
|
||||
let _ = (combineLatest(queue: queue,
|
||||
fetchMediaSignal
|
||||
|> timeout(10.0, queue: queue, alternate: .single(nil)),
|
||||
fetchNotificationSoundSignal
|
||||
|> timeout(10.0, queue: queue, alternate: .single(nil))
|
||||
)
|
||||
|> deliverOn(queue)).start(next: { mediaData, notificationSoundData in
|
||||
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
||||
completed()
|
||||
return
|
||||
}
|
||||
|
||||
Logger.shared.log("NotificationService \(episode)", "Did fetch media \(mediaData == nil ? "Non-empty" : "Empty")")
|
||||
|
||||
if let notificationSoundData = notificationSoundData {
|
||||
Logger.shared.log("NotificationService \(episode)", "Did fetch notificationSoundData")
|
||||
|
||||
if let (_, filePath, fileName) = downloadNotificationSound {
|
||||
let _ = try? notificationSoundData.write(to: URL(fileURLWithPath: filePath))
|
||||
}
|
||||
}
|
||||
|
||||
Logger.shared.log("NotificationService \(episode)", "Will get unread count")
|
||||
let _ = (getCurrentRenderedTotalUnreadCount(
|
||||
|
||||
Reference in New Issue
Block a user