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

@@ -28,41 +28,52 @@ private let classicSoundNamePaths: [KeyPath<PresentationStrings, String>] = [
\.NotificationsSound_Telegraph
]
private func soundName(strings: PresentationStrings, sound: PeerMessageSound) -> String {
private func soundName(strings: PresentationStrings, sound: PeerMessageSound, notificationSoundList: NotificationSoundList?) -> String {
switch sound {
case .none:
return strings.NotificationsSound_None
case .default:
return ""
case let .bundledModern(id):
if id >= 0 && Int(id) < modernSoundsNamePaths.count {
return strings[keyPath: modernSoundsNamePaths[Int(id)]]
case .none:
return strings.NotificationsSound_None
case .default:
return ""
case let .bundledModern(id):
if id >= 0 && Int(id) < modernSoundsNamePaths.count {
return strings[keyPath: modernSoundsNamePaths[Int(id)]]
}
return "Sound \(id)"
case let .bundledClassic(id):
if id >= 0 && Int(id) < classicSoundNamePaths.count {
return strings[keyPath: classicSoundNamePaths[Int(id)]]
}
return "Sound \(id)"
case let .cloud(fileId):
guard let notificationSoundList = notificationSoundList else {
//TODO:localize
return "Loading..."
}
for sound in notificationSoundList.sounds {
if sound.file.fileId.id == fileId {
return sound.file.fileName ?? "Cloud Tone"
}
return "Sound \(id)"
case let .bundledClassic(id):
if id >= 0 && Int(id) < classicSoundNamePaths.count {
return strings[keyPath: classicSoundNamePaths[Int(id)]]
}
return "Sound \(id)"
}
return ""
}
}
public func localizedPeerNotificationSoundString(strings: PresentationStrings, sound: PeerMessageSound, default: PeerMessageSound? = nil) -> String {
public func localizedPeerNotificationSoundString(strings: PresentationStrings, notificationSoundList: NotificationSoundList?, sound: PeerMessageSound, default: PeerMessageSound? = nil) -> String {
switch sound {
case .default:
if let defaultSound = `default` {
let name = soundName(strings: strings, sound: defaultSound)
let actualName: String
if name.isEmpty {
actualName = soundName(strings: strings, sound: .bundledModern(id: 0))
} else {
actualName = name
}
return strings.UserInfo_NotificationsDefaultSound(actualName).string
case .default:
if let defaultSound = `default` {
let name = soundName(strings: strings, sound: defaultSound, notificationSoundList: notificationSoundList)
let actualName: String
if name.isEmpty {
actualName = soundName(strings: strings, sound: .bundledModern(id: 0), notificationSoundList: notificationSoundList)
} else {
return strings.UserInfo_NotificationsDefault
actualName = name
}
default:
return soundName(strings: strings, sound: sound)
return strings.UserInfo_NotificationsDefaultSound(actualName).string
} else {
return strings.UserInfo_NotificationsDefault
}
default:
return soundName(strings: strings, sound: sound, notificationSoundList: notificationSoundList)
}
}