Peer sound and message removal update

This commit is contained in:
Ali
2022-03-30 01:22:44 +04:00
parent 0e55dd7db7
commit 235302c7c4
63 changed files with 3906 additions and 1934 deletions

View File

@@ -29,6 +29,7 @@ import TranslateUI
import DebugSettingsUI
import ChatPresentationInterfaceState
import Pasteboard
import SettingsUI
private struct MessageContextMenuData {
let starStatus: Bool?
@@ -819,51 +820,6 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
}
f(.default)
})))
if resourceAvailable {
for media in message.media {
if let file = media as? TelegramMediaFile, (["audio/mp3", "audio/mpeg3"] as [String]).contains(file.mimeType.lowercased()) {
actions.append(.action(ContextMenuActionItem(text: "Set as Message Tone", icon: { _ in
return nil
}, action: { _, f in
for media in message.media {
if let file = media as? TelegramMediaFile {
let _ = (context.account.postbox.mediaBox.resourceData(file.resource, option: .incremental(waitUntilFetchStatus: false))
|> take(1)
|> deliverOnMainQueue).start(next: { data in
if data.complete {
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let soundsDirectoryPath = documentsDirectoryPath + "/Sounds"
let _ = try? FileManager.default.createDirectory(atPath: soundsDirectoryPath, withIntermediateDirectories: true, attributes: nil)
let containerSoundsPath = context.sharedContext.applicationBindings.containerPath + "/Library/Sounds"
let _ = try? FileManager.default.createDirectory(atPath: containerSoundsPath, withIntermediateDirectories: true, attributes: nil)
let soundFileName = "\(UInt32.random(in: 0 ..< UInt32.max)).mp3"
let soundPath = soundsDirectoryPath + "/\(soundFileName)"
let _ = try? FileManager.default.copyItem(atPath: data.path, toPath: soundPath)
let _ = try? FileManager.default.copyItem(atPath: data.path, toPath: "\(containerSoundsPath)/\(soundFileName)")
let _ = updateInAppNotificationSettingsInteractively(accountManager: context.sharedContext.accountManager, { settings in
var settings = settings
settings.customSound = soundFileName
return settings
}).start()
}
})
}
}
f(.default)
})))
}
}
}
}
let (canTranslate, _) = canTranslateText(context: context, text: messageText, showTranslate: translationSettings.showTranslate, ignoredLanguages: translationSettings.ignoredLanguages)
@@ -914,6 +870,54 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
}
}
for media in message.media {
if let file = media as? TelegramMediaFile, let size = file.size, size < 200 * 1024, (["audio/mpeg", "audio/mp3", "audio/mpeg3"] as [String]).contains(file.mimeType.lowercased()) {
actions.append(.action(ContextMenuActionItem(text: "Save for Notifications", icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/DownloadTone"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in
let _ = context.engine.peers.saveNotificationSound(file: file).start(completed: {
//TODO:localize
controllerInteraction.displayUndo(.notificationSoundAdded(title: "Sound added", text: "You can now use this sound as a notification tone in your [custom notification settings]().", action: {
controllerInteraction.navigationController()?.pushViewController(notificationsAndSoundsController(context: context, exceptionsList: nil))
}))
})
f(.default)
})))
/*
let _ = (context.account.postbox.mediaBox.resourceData(file.resource, option: .incremental(waitUntilFetchStatus: false))
|> take(1)
|> deliverOnMainQueue).start(next: { data in
if data.complete {
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
let soundsDirectoryPath = documentsDirectoryPath + "/Sounds"
let _ = try? FileManager.default.createDirectory(atPath: soundsDirectoryPath, withIntermediateDirectories: true, attributes: nil)
let containerSoundsPath = context.sharedContext.applicationBindings.containerPath + "/Library/Sounds"
let _ = try? FileManager.default.createDirectory(atPath: containerSoundsPath, withIntermediateDirectories: true, attributes: nil)
let soundFileName = "\(UInt32.random(in: 0 ..< UInt32.max)).mp3"
let soundPath = soundsDirectoryPath + "/\(soundFileName)"
let _ = try? FileManager.default.copyItem(atPath: data.path, toPath: soundPath)
let _ = try? FileManager.default.copyItem(atPath: data.path, toPath: "\(containerSoundsPath)/\(soundFileName)")
let _ = updateInAppNotificationSettingsInteractively(accountManager: context.sharedContext.accountManager, { settings in
var settings = settings
settings.customSound = soundFileName
return settings
}).start()
}
})*/
}
}
var downloadableMediaResourceInfos: [String] = []
for media in message.media {
if let file = media as? TelegramMediaFile {