mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Peer sound and message removal update
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user