mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Notification sound file reference revalidation
This commit is contained in:
parent
d8a9913b40
commit
0ed361e34c
@ -204,7 +204,7 @@ public class ItemListCheckboxItemNode: ItemListRevealOptionsItemNode {
|
|||||||
titleColor = item.presentationData.theme.list.itemAccentColor
|
titleColor = item.presentationData.theme.list.itemAccentColor
|
||||||
}
|
}
|
||||||
|
|
||||||
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.title, font: titleFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 20.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.title, font: titleFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 28.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||||
|
|
||||||
let separatorHeight = UIScreenPixel
|
let separatorHeight = UIScreenPixel
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ public func playSound(context: AccountContext, notificationSoundList: Notificati
|
|||||||
deactivateImpl?()
|
deactivateImpl?()
|
||||||
})
|
})
|
||||||
currentPlayer?.play()
|
currentPlayer?.play()
|
||||||
} else {
|
} else if !filePath.isEmpty {
|
||||||
if let url = getAppBundle().url(forResource: filePath, withExtension: "m4a") {
|
if let url = getAppBundle().url(forResource: filePath, withExtension: "m4a") {
|
||||||
currentPlayer = AudioPlayerWrapper(url: url, completed: {
|
currentPlayer = AudioPlayerWrapper(url: url, completed: {
|
||||||
deactivateImpl?()
|
deactivateImpl?()
|
||||||
|
@ -226,6 +226,7 @@ private enum MediaReferenceRevalidationKey: Hashable {
|
|||||||
case themes
|
case themes
|
||||||
case peerAvatars(peer: PeerReference)
|
case peerAvatars(peer: PeerReference)
|
||||||
case attachBot(peer: PeerReference)
|
case attachBot(peer: PeerReference)
|
||||||
|
case notificationSoundList
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class MediaReferenceRevalidationItemContext {
|
private final class MediaReferenceRevalidationItemContext {
|
||||||
@ -556,6 +557,24 @@ final class MediaReferenceRevalidationContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notificationSoundList(postbox: Postbox, network: Network, background: Bool) -> Signal<[TelegramMediaFile], RevalidateMediaReferenceError> {
|
||||||
|
return self.genericItem(key: .notificationSoundList, background: background, request: { next, error in
|
||||||
|
return (requestNotificationSoundList(network: network, hash: 0)
|
||||||
|
|> map { result -> [TelegramMediaFile] in
|
||||||
|
guard let result = result else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return result.sounds.map(\.file)
|
||||||
|
}).start(next: next)
|
||||||
|
}) |> mapToSignal { next -> Signal<[TelegramMediaFile], RevalidateMediaReferenceError> in
|
||||||
|
if let next = next as? [TelegramMediaFile] {
|
||||||
|
return .single(next)
|
||||||
|
} else {
|
||||||
|
return .fail(.generic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RevalidatedMediaResource {
|
struct RevalidatedMediaResource {
|
||||||
@ -799,6 +818,16 @@ func revalidateMediaResourceReference(postbox: Postbox, network: Network, revali
|
|||||||
}
|
}
|
||||||
return .fail(.generic)
|
return .fail(.generic)
|
||||||
}
|
}
|
||||||
|
case let .soundList(resource):
|
||||||
|
return revalidationContext.notificationSoundList(postbox: postbox, network: network, background: info.preferBackgroundReferenceRevalidation)
|
||||||
|
|> mapToSignal { files -> Signal<RevalidatedMediaResource, RevalidateMediaReferenceError> in
|
||||||
|
for file in files {
|
||||||
|
if file.resource.id == resource.id {
|
||||||
|
return .single(RevalidatedMediaResource(updatedResource: file.resource, updatedReference: nil))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return .fail(.generic)
|
||||||
|
}
|
||||||
case .standalone:
|
case .standalone:
|
||||||
return .fail(.generic)
|
return .fail(.generic)
|
||||||
}
|
}
|
||||||
|
@ -569,6 +569,7 @@ public enum MediaResourceReference: Equatable {
|
|||||||
case wallpaper(wallpaper: WallpaperReference?, resource: MediaResource)
|
case wallpaper(wallpaper: WallpaperReference?, resource: MediaResource)
|
||||||
case stickerPackThumbnail(stickerPack: StickerPackReference, resource: MediaResource)
|
case stickerPackThumbnail(stickerPack: StickerPackReference, resource: MediaResource)
|
||||||
case theme(theme: ThemeReference, resource: MediaResource)
|
case theme(theme: ThemeReference, resource: MediaResource)
|
||||||
|
case soundList(resource: MediaResource)
|
||||||
|
|
||||||
public var resource: MediaResource {
|
public var resource: MediaResource {
|
||||||
switch self {
|
switch self {
|
||||||
@ -588,6 +589,8 @@ public enum MediaResourceReference: Equatable {
|
|||||||
return resource
|
return resource
|
||||||
case let .theme(_, resource):
|
case let .theme(_, resource):
|
||||||
return resource
|
return resource
|
||||||
|
case let .soundList(resource):
|
||||||
|
return resource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,6 +644,12 @@ public enum MediaResourceReference: Equatable {
|
|||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
case let .soundList(lhsResource):
|
||||||
|
if case let .soundList(rhsResource) = rhs, lhsResource.isEqual(to: rhsResource) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ public func ensureDownloadedNotificationSoundList(postbox: Postbox) -> Signal<Ne
|
|||||||
|
|
||||||
for resource in resources {
|
for resource in resources {
|
||||||
signals.append(
|
signals.append(
|
||||||
fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .standalone(resource: resource))
|
fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .soundList(resource: resource))
|
||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
|> `catch` { _ -> Signal<Never, NoError> in
|
|> `catch` { _ -> Signal<Never, NoError> in
|
||||||
return .complete()
|
return .complete()
|
||||||
@ -168,6 +168,30 @@ public func ensureDownloadedNotificationSoundList(postbox: Postbox) -> Signal<Ne
|
|||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func requestNotificationSoundList(network: Network, hash: Int64) -> Signal<NotificationSoundList?, NoError> {
|
||||||
|
return network.request(Api.functions.account.getSavedRingtones(hash: hash))
|
||||||
|
|> map(Optional.init)
|
||||||
|
|> `catch` { _ -> Signal<Api.account.SavedRingtones?, NoError> in
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
|> map { result -> NotificationSoundList? in
|
||||||
|
guard let result = result else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch result {
|
||||||
|
case let .savedRingtones(hash, ringtones):
|
||||||
|
let notificationSoundList = NotificationSoundList(
|
||||||
|
hash: hash,
|
||||||
|
sounds: ringtones.compactMap(NotificationSoundList.NotificationSound.init(apiDocument:))
|
||||||
|
)
|
||||||
|
return notificationSoundList
|
||||||
|
case .savedRingtonesNotModified:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Signal<Never, NoError> {
|
private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Signal<Never, NoError> {
|
||||||
return Signal<Never, NoError> { subscriber in
|
return Signal<Never, NoError> { subscriber in
|
||||||
let signal: Signal<Never, NoError> = _internal_cachedNotificationSoundList(postbox: postbox)
|
let signal: Signal<Never, NoError> = _internal_cachedNotificationSoundList(postbox: postbox)
|
||||||
@ -204,7 +228,7 @@ private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Si
|
|||||||
|
|
||||||
for resource in resources {
|
for resource in resources {
|
||||||
signals.append(
|
signals.append(
|
||||||
fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .standalone(resource: resource))
|
fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .soundList(resource: resource))
|
||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
|> `catch` { _ -> Signal<Never, NoError> in
|
|> `catch` { _ -> Signal<Never, NoError> in
|
||||||
return .complete()
|
return .complete()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user