mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various fixes
This commit is contained in:
parent
93f09734ff
commit
9f1f1b49e7
@ -202,7 +202,6 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
|
|||||||
private var disposable: Disposable?
|
private var disposable: Disposable?
|
||||||
private var state: LocationViewState
|
private var state: LocationViewState
|
||||||
private let statePromise: Promise<LocationViewState>
|
private let statePromise: Promise<LocationViewState>
|
||||||
private var geocodingDisposable = MetaDisposable()
|
|
||||||
|
|
||||||
private var validLayout: (layout: ContainerViewLayout, navigationHeight: CGFloat)?
|
private var validLayout: (layout: ContainerViewLayout, navigationHeight: CGFloat)?
|
||||||
private var listOffset: CGFloat?
|
private var listOffset: CGFloat?
|
||||||
@ -271,7 +270,7 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
|
|||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
setupProximityNotificationImpl = { reset in
|
setupProximityNotificationImpl = { [weak self] reset in
|
||||||
let _ = (liveLocations
|
let _ = (liveLocations
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] messages in
|
|> deliverOnMainQueue).start(next: { [weak self] messages in
|
||||||
@ -540,7 +539,6 @@ final class LocationViewControllerNode: ViewControllerTracingNode, CLLocationMan
|
|||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
self.disposable?.dispose()
|
self.disposable?.dispose()
|
||||||
self.geocodingDisposable.dispose()
|
|
||||||
|
|
||||||
self.locationManager.manager.stopUpdatingHeading()
|
self.locationManager.manager.stopUpdatingHeading()
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import Emoji
|
|||||||
import Markdown
|
import Markdown
|
||||||
import ManagedAnimationNode
|
import ManagedAnimationNode
|
||||||
import SlotMachineAnimationNode
|
import SlotMachineAnimationNode
|
||||||
|
import UniversalMediaPlayer
|
||||||
|
|
||||||
private let nameFont = Font.medium(14.0)
|
private let nameFont = Font.medium(14.0)
|
||||||
private let inlineBotPrefixFont = Font.regular(14.0)
|
private let inlineBotPrefixFont = Font.regular(14.0)
|
||||||
@ -1229,30 +1230,54 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
let beatingHearts: [UInt32] = [0x2764, 0x1F90E, 0x1F9E1, 0x1F499, 0x1F49A, 0x1F49C, 0x1F49B, 0x1F5A4, 0x1F90D]
|
let beatingHearts: [UInt32] = [0x2764, 0x1F90E, 0x1F9E1, 0x1F499, 0x1F49A, 0x1F49C, 0x1F49B, 0x1F5A4, 0x1F90D]
|
||||||
let peach = 0x1F351
|
let peach = 0x1F351
|
||||||
|
|
||||||
if let text = self.item?.message.text, let firstScalar = text.unicodeScalars.first, beatingHearts.contains(firstScalar.value) || firstScalar.value == peach {
|
let appConfiguration = item.context.account.postbox.preferencesView(keys: [PreferencesKeys.appConfiguration])
|
||||||
return .optionalAction({
|
|> take(1)
|
||||||
let _ = startTime.start(next: { [weak self] time in
|
|> map { view in
|
||||||
guard let strongSelf = self else {
|
return view.values[PreferencesKeys.appConfiguration] as? AppConfiguration ?? .defaultValue
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
if let text = self.item?.message.text, let firstScalar = text.unicodeScalars.first {
|
||||||
var haptic: EmojiHaptic
|
if beatingHearts.contains(firstScalar.value) || firstScalar.value == peach {
|
||||||
if let current = strongSelf.haptic {
|
return .optionalAction({
|
||||||
haptic = current
|
let _ = startTime.start(next: { [weak self] time in
|
||||||
} else {
|
guard let strongSelf = self else {
|
||||||
if beatingHearts.contains(firstScalar.value) {
|
return
|
||||||
haptic = HeartbeatHaptic()
|
|
||||||
} else {
|
|
||||||
haptic = PeachHaptic()
|
|
||||||
}
|
}
|
||||||
haptic.enabled = true
|
|
||||||
strongSelf.haptic = haptic
|
var haptic: EmojiHaptic
|
||||||
}
|
if let current = strongSelf.haptic {
|
||||||
if !haptic.active {
|
haptic = current
|
||||||
haptic.start(time: time)
|
} else {
|
||||||
}
|
if beatingHearts.contains(firstScalar.value) {
|
||||||
|
haptic = HeartbeatHaptic()
|
||||||
|
} else {
|
||||||
|
haptic = PeachHaptic()
|
||||||
|
}
|
||||||
|
haptic.enabled = true
|
||||||
|
strongSelf.haptic = haptic
|
||||||
|
}
|
||||||
|
if !haptic.active {
|
||||||
|
haptic.start(time: time)
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
} else {
|
||||||
|
return .optionalAction({
|
||||||
|
let _ = (appConfiguration
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] appConfiguration in
|
||||||
|
let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: item.context.account)
|
||||||
|
for (emoji, file) in emojiSounds.sounds {
|
||||||
|
if emoji.unicodeScalars.first == firstScalar {
|
||||||
|
let mediaManager = item.context.sharedContext.mediaManager
|
||||||
|
let mediaPlayer = MediaPlayer(audioSessionManager: mediaManager.audioSession, postbox: item.context.account.postbox, resourceReference: .standalone(resource: file.resource), streamable: .none, video: false, preferSoftwareDecoding: false, enableSound: true, fetchAutomatically: true)
|
||||||
|
mediaPlayer.togglePlayPause()
|
||||||
|
self?.mediaPlayer = mediaPlayer
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1268,6 +1293,8 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var mediaPlayer: MediaPlayer?
|
||||||
|
|
||||||
@objc private func shareButtonPressed() {
|
@objc private func shareButtonPressed() {
|
||||||
if let item = self.item {
|
if let item = self.item {
|
||||||
if case .pinnedMessages = item.associatedData.subject {
|
if case .pinnedMessages = item.associatedData.subject {
|
||||||
@ -1512,3 +1539,39 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
|||||||
self.contextSourceNode.contentNode.addSubnode(accessoryItemNode)
|
self.contextSourceNode.contentNode.addSubnode(accessoryItemNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AnimatedEmojiSoundsConfiguration {
|
||||||
|
static var defaultValue: AnimatedEmojiSoundsConfiguration {
|
||||||
|
return AnimatedEmojiSoundsConfiguration(sounds: [:])
|
||||||
|
}
|
||||||
|
|
||||||
|
public let sounds: [String: TelegramMediaFile]
|
||||||
|
|
||||||
|
fileprivate init(sounds: [String: TelegramMediaFile]) {
|
||||||
|
self.sounds = sounds
|
||||||
|
}
|
||||||
|
|
||||||
|
static func with(appConfiguration: AppConfiguration, account: Account) -> AnimatedEmojiSoundsConfiguration {
|
||||||
|
if let data = appConfiguration.data, let values = data["emojies_sounds"] as? [String: Any] {
|
||||||
|
var sounds: [String: TelegramMediaFile] = [:]
|
||||||
|
for (key, value) in values {
|
||||||
|
if let dict = value as? [String: String], var fileReferenceString = dict["file_reference_base64"] {
|
||||||
|
fileReferenceString = fileReferenceString.replacingOccurrences(of: "-", with: "+")
|
||||||
|
fileReferenceString = fileReferenceString.replacingOccurrences(of: "_", with: "/")
|
||||||
|
while fileReferenceString.count % 4 != 0 {
|
||||||
|
fileReferenceString.append("=")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let idString = dict["id"], let id = Int64(idString), let accessHashString = dict["access_hash"], let accessHash = Int64(accessHashString), let fileReference = Data(base64Encoded: fileReferenceString) {
|
||||||
|
let resource = CloudDocumentMediaResource(datacenterId: 1, fileId: id, accessHash: accessHash, size: nil, fileReference: fileReference, fileName: nil)
|
||||||
|
let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 0), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: nil, attributes: [])
|
||||||
|
sounds[key] = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AnimatedEmojiSoundsConfiguration(sounds: sounds)
|
||||||
|
} else {
|
||||||
|
return .defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -20,42 +20,6 @@ public enum PrefetchMediaItem {
|
|||||||
case animatedEmojiSticker(TelegramMediaFile)
|
case animatedEmojiSticker(TelegramMediaFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct AnimatedEmojiSoundsConfiguration {
|
|
||||||
static var defaultValue: AnimatedEmojiSoundsConfiguration {
|
|
||||||
return AnimatedEmojiSoundsConfiguration(sounds: [:])
|
|
||||||
}
|
|
||||||
|
|
||||||
public let sounds: [String: TelegramMediaFile]
|
|
||||||
|
|
||||||
fileprivate init(sounds: [String: TelegramMediaFile]) {
|
|
||||||
self.sounds = sounds
|
|
||||||
}
|
|
||||||
|
|
||||||
static func with(appConfiguration: AppConfiguration) -> AnimatedEmojiSoundsConfiguration {
|
|
||||||
if let data = appConfiguration.data, let values = data["emojies_sounds"] as? [String: Any] {
|
|
||||||
var sounds: [String: TelegramMediaFile] = [:]
|
|
||||||
for (key, value) in values {
|
|
||||||
if let dict = value as? [String: String], var fileReferenceString = dict["file_reference_base64"] {
|
|
||||||
fileReferenceString = fileReferenceString.replacingOccurrences(of: "-", with: "+")
|
|
||||||
fileReferenceString = fileReferenceString.replacingOccurrences(of: "_", with: "/")
|
|
||||||
while fileReferenceString.count % 4 != 0 {
|
|
||||||
fileReferenceString.append("=")
|
|
||||||
}
|
|
||||||
|
|
||||||
if let idString = dict["id"], let id = Int64(idString), let accessHashString = dict["access_hash"], let accessHash = Int64(accessHashString), let fileReference = Data(base64Encoded: fileReferenceString) {
|
|
||||||
let resource = CloudDocumentMediaResource(datacenterId: 0, fileId: id, accessHash: accessHash, size: nil, fileReference: fileReference, fileName: nil)
|
|
||||||
let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 0), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: nil, attributes: [])
|
|
||||||
sounds[key] = file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AnimatedEmojiSoundsConfiguration(sounds: sounds)
|
|
||||||
} else {
|
|
||||||
return .defaultValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class PrefetchManagerImpl {
|
private final class PrefetchManagerImpl {
|
||||||
private let queue: Queue
|
private let queue: Queue
|
||||||
private let account: Account
|
private let account: Account
|
||||||
@ -89,12 +53,9 @@ private final class PrefetchManagerImpl {
|
|||||||
|
|
||||||
let orderedPreloadMedia = combineLatest(account.viewTracker.orderedPreloadMedia, loadedStickerPack(postbox: account.postbox, network: account.network, reference: .animatedEmoji, forceActualized: false), appConfiguration)
|
let orderedPreloadMedia = combineLatest(account.viewTracker.orderedPreloadMedia, loadedStickerPack(postbox: account.postbox, network: account.network, reference: .animatedEmoji, forceActualized: false), appConfiguration)
|
||||||
|> map { orderedPreloadMedia, stickerPack, appConfiguration -> [PrefetchMediaItem] in
|
|> map { orderedPreloadMedia, stickerPack, appConfiguration -> [PrefetchMediaItem] in
|
||||||
let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration)
|
let emojiSounds = AnimatedEmojiSoundsConfiguration.with(appConfiguration: appConfiguration, account: account)
|
||||||
let chatHistoryMediaItems = orderedPreloadMedia.map { PrefetchMediaItem.chatHistory($0) }
|
let chatHistoryMediaItems = orderedPreloadMedia.map { PrefetchMediaItem.chatHistory($0) }
|
||||||
var stickerItems: [PrefetchMediaItem] = []
|
var stickerItems: [PrefetchMediaItem] = []
|
||||||
|
|
||||||
var prefetchItems: [PrefetchMediaItem] = []
|
|
||||||
|
|
||||||
switch stickerPack {
|
switch stickerPack {
|
||||||
case let .result(_, items, _):
|
case let .result(_, items, _):
|
||||||
var animatedEmojiStickers: [String: StickerPackItem] = [:]
|
var animatedEmojiStickers: [String: StickerPackItem] = [:]
|
||||||
@ -113,11 +74,11 @@ private final class PrefetchManagerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stickerItems
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var prefetchItems: [PrefetchMediaItem] = []
|
||||||
prefetchItems.append(contentsOf: chatHistoryMediaItems)
|
prefetchItems.append(contentsOf: chatHistoryMediaItems)
|
||||||
prefetchItems.append(contentsOf: stickerItems)
|
prefetchItems.append(contentsOf: stickerItems)
|
||||||
prefetchItems.append(contentsOf: emojiSounds.sounds.values.map { .animatedEmojiSticker($0) })
|
prefetchItems.append(contentsOf: emojiSounds.sounds.values.map { .animatedEmojiSticker($0) })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user