Skip to content

Commit

Permalink
1.9.4 (404)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Dec 23, 2024
1 parent 314ecb8 commit aaf68ec
Show file tree
Hide file tree
Showing 11,207 changed files with 1,305,349 additions and 826,995 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
[submodule "submodules/LottieCpp/lottiecpp"]
path = submodules/LottieCpp/lottiecpp
url = https://github.com/ali-fareed/lottiecpp.git
[submodule "third-party/dav1d/dav1d"]
path = third-party/dav1d/dav1d
url = https://github.com/ali-fareed/dav1d.git
1 change: 1 addition & 0 deletions Telegram/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,7 @@ ios_extension(
":SwiftSignalKitFramework",
":PostboxFramework",
":TelegramCoreFramework",
":TelegramUIFramework",
],
)

Expand Down
1 change: 1 addition & 0 deletions Telegram/NotificationService/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ swift_library(
"//submodules/GZip:GZip",
"//submodules/PersistentStringHash:PersistentStringHash",
"//submodules/Utils/RangeSet",
"//submodules/Media/ConvertOpusToAAC",

],
visibility = [
Expand Down
82 changes: 59 additions & 23 deletions Telegram/NotificationService/Sources/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import CallKit
import AppLockState
import NotificationsPresentationData
import RangeSet
import ConvertOpusToAAC

private let queue = Queue()

Expand Down Expand Up @@ -440,11 +441,11 @@ private func avatarImage(path: String?, peerId: PeerId, letters: [String], size:
}
}

private func storeTemporaryImage(path: String) -> String {
private func storeTemporaryImage(path: String, fileExtension: String) -> String {
let imagesPath = NSTemporaryDirectory() + "/aps-data"
let _ = try? FileManager.default.createDirectory(at: URL(fileURLWithPath: imagesPath), withIntermediateDirectories: true, attributes: nil)

let tempPath = imagesPath + "\(path.persistentHashValue)"
let tempPath = imagesPath + "\(path.persistentHashValue).\(fileExtension)"
if FileManager.default.fileExists(atPath: tempPath) {
return tempPath
}
Expand All @@ -459,27 +460,27 @@ private func peerAvatar(mediaBox: MediaBox, accountPeerId: PeerId, peer: Peer, i
if let resource = smallestImageRepresentation(peer.profileImageRepresentations)?.resource, let path = mediaBox.completedResourcePath(resource) {
let cachedPath = mediaBox.cachedRepresentationPathForId(resource.id.stringRepresentation, representationId: "intents\(isStory ? "-story2" : "").png", keepDuration: .shortLived)
if let _ = fileSize(cachedPath), !"".isEmpty {
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath)))
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath, fileExtension: "jpg")))
} else {
let image = avatarImage(path: path, peerId: peer.id, letters: peer.displayLetters, size: CGSize(width: 50.0, height: 50.0), isStory: isStory)
if let data = image.pngData() {
let _ = try? FileManager.default.removeItem(atPath: cachedPath)
let _ = try? data.write(to: URL(fileURLWithPath: cachedPath), options: .atomic)
}

return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath)))
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath, fileExtension: "jpg")))
}
}

let cachedPath = mediaBox.cachedRepresentationPathForId("lettersAvatar2-\(peer.displayLetters.joined(separator: ","))\(isStory ? "-story" : "")", representationId: "intents.png", keepDuration: .shortLived)
if let _ = fileSize(cachedPath) {
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath)))
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath, fileExtension: "jpg")))
} else {
let image = avatarImage(path: nil, peerId: peer.id, letters: peer.displayLetters, size: CGSize(width: 50.0, height: 50.0), isStory: isStory)
if let data = image.pngData() {
let _ = try? data.write(to: URL(fileURLWithPath: cachedPath), options: .atomic)
}
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath)))
return INImage(url: URL(fileURLWithPath: storeTemporaryImage(path: cachedPath, fileExtension: "jpg")))
}
}

Expand Down Expand Up @@ -1250,7 +1251,9 @@ private final class NotificationServiceHandler {
case let .poll(peerId, initialContent, messageId):
Logger.shared.log("NotificationService \(episode)", "Will poll")
if let stateManager = strongSelf.stateManager {
let pollCompletion: (NotificationContent) -> Void = { content in
let shouldKeepConnection = stateManager.network.shouldKeepConnection

let pollCompletion: (NotificationContent, Media?) -> Void = { content, customMedia in
var content = content

queue.async {
Expand All @@ -1260,6 +1263,8 @@ private final class NotificationServiceHandler {
completed()
return
}

let mediaAttachment = mediaAttachment ?? customMedia

var fetchMediaSignal: Signal<Data?, NoError> = .single(nil)
if let mediaAttachment = mediaAttachment {
Expand All @@ -1275,6 +1280,9 @@ private final class NotificationServiceHandler {
} else if file.isVideo {
fetchResource = file.previewRepresentations.first?.resource as? TelegramMultipartFetchableResource
contentType = .video
} else if file.isVoice {
fetchResource = file.resource as? TelegramMultipartFetchableResource
contentType = .audio
} else {
contentType = .file
}
Expand Down Expand Up @@ -1446,8 +1454,10 @@ private final class NotificationServiceHandler {
completed()
return
}

shouldKeepConnection.set(.single(false))

Logger.shared.log("NotificationService \(episode)", "Did fetch media \(mediaData == nil ? "Non-empty" : "Empty")")
Logger.shared.log("NotificationService \(episode)", "Did fetch media \(mediaData == nil ? "Empty" : "Non-empty")")

if let notificationSoundData = notificationSoundData {
Logger.shared.log("NotificationService \(episode)", "Did fetch notificationSoundData")
Expand Down Expand Up @@ -1530,6 +1540,24 @@ private final class NotificationServiceHandler {
content.attachments.append(attachment)
}
}
} else if file.isVoice {
if let mediaData = mediaData {
stateManager.postbox.mediaBox.storeResourceData(file.resource.id, data: mediaData, synchronous: true)
}
if let storedPath = stateManager.postbox.mediaBox.completedResourcePath(file.resource, pathExtension: nil) {
let semaphore = DispatchSemaphore(value: 0)
let tempFile = TempBox.shared.tempFile(fileName: "audio.m4a")
let _ = (convertOpusToAAC(sourcePath: storedPath, allocateTempFile: {
return tempFile.path
})
|> timeout(5.0, queue: .concurrentDefaultQueue(), alternate: .single(nil))).startStandalone(next: { _ in
semaphore.signal()
})
semaphore.wait()
if let attachment = try? UNNotificationAttachment(identifier: "audio", url: URL(fileURLWithPath: tempFile.path), options: nil) {
content.attachments.append(attachment)
}
}
}
}

Expand All @@ -1553,11 +1581,10 @@ private final class NotificationServiceHandler {
}

let pollSignal: Signal<Never, NoError>

if !shouldSynchronizeState {
pollSignal = .complete()
} else {
let shouldKeepConnection = stateManager.network.shouldKeepConnection
shouldKeepConnection.set(.single(true))
if peerId.namespace == Namespaces.Peer.CloudChannel {
Logger.shared.log("NotificationService \(episode)", "Will poll channel \(peerId)")
Expand All @@ -1569,9 +1596,6 @@ private final class NotificationServiceHandler {
peerId: peerId,
stateManager: stateManager
)
|> afterDisposed { [weak shouldKeepConnection] in
shouldKeepConnection?.set(.single(false))
}
} else {
Logger.shared.log("NotificationService \(episode)", "Will perform non-specific getDifference")
enum ControlError {
Expand All @@ -1587,17 +1611,14 @@ private final class NotificationServiceHandler {
}
}
|> restartIfError
|> afterDisposed { [weak shouldKeepConnection] in
shouldKeepConnection?.set(.single(false))
}

pollSignal = signal
}
}

let pollWithUpdatedContent: Signal<NotificationContent, NoError>
let pollWithUpdatedContent: Signal<(NotificationContent, Media?), NoError>
if interactionAuthorId != nil || messageId != nil {
pollWithUpdatedContent = stateManager.postbox.transaction { transaction -> NotificationContent in
pollWithUpdatedContent = stateManager.postbox.transaction { transaction -> (NotificationContent, Media?) in
var content = initialContent

if let interactionAuthorId = interactionAuthorId {
Expand Down Expand Up @@ -1642,22 +1663,37 @@ private final class NotificationServiceHandler {
}
}

return content
return (content, nil)
}
|> then(
pollSignal
|> map { _ -> NotificationContent in }
|> map { _ -> (NotificationContent, Media?) in }
)
|> takeLast
|> mapToSignal { content, _ -> Signal<(NotificationContent, Media?), NoError> in
return stateManager.postbox.transaction { transaction -> (NotificationContent, Media?) in
var parsedMedia: Media?
if let messageId, let message = transaction.getMessage(messageId) {
if let media = message.media.first {
parsedMedia = media
}
}

return (content, parsedMedia)
}
}
} else {
pollWithUpdatedContent = pollSignal
|> map { _ -> NotificationContent in }
|> map { _ -> (NotificationContent, Media?) in }
}

var updatedContent = initialContent
strongSelf.pollDisposable.set(pollWithUpdatedContent.start(next: { content in
var updatedMedia: Media?
strongSelf.pollDisposable.set(pollWithUpdatedContent.start(next: { content, media in
updatedContent = content
updatedMedia = media
}, completed: {
pollCompletion(updatedContent)
pollCompletion(updatedContent, updatedMedia)
}))
} else {
completed()
Expand Down
Loading

0 comments on commit aaf68ec

Please sign in to comment.