mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
ff27340f5e
@ -1110,7 +1110,8 @@ private final class NotificationServiceHandler {
|
||||
fetchResource = downloadNotificationSound.resource as? TelegramMultipartFetchableResource
|
||||
|
||||
if let resource = fetchResource {
|
||||
if let _ = strongSelf.stateManager?.postbox.mediaBox.completedResourcePath(resource) {
|
||||
if let path = strongSelf.stateManager?.postbox.mediaBox.completedResourcePath(resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
|
||||
fetchNotificationSoundSignal = .single(data)
|
||||
} else {
|
||||
let intervals: Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError> = .single([(0 ..< Int(Int32.max), MediaBoxFetchPriority.maximum)])
|
||||
fetchNotificationSoundSignal = Signal { subscriber in
|
||||
@ -1172,7 +1173,7 @@ private final class NotificationServiceHandler {
|
||||
if let notificationSoundData = notificationSoundData {
|
||||
Logger.shared.log("NotificationService \(episode)", "Did fetch notificationSoundData")
|
||||
|
||||
if let (_, filePath, fileName) = downloadNotificationSound {
|
||||
if let (_, filePath, _) = downloadNotificationSound {
|
||||
let _ = try? notificationSoundData.write(to: URL(fileURLWithPath: filePath))
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,13 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
|
||||
let presentationData = context.sharedContext.currentPresentationData.with({ $0 })
|
||||
let strings = presentationData.strings
|
||||
|
||||
return context.account.postbox.transaction { transaction -> (PeerGroupId, ChatListIndex)? in
|
||||
transaction.getPeerChatListIndex(peerId)
|
||||
}
|
||||
|> mapToSignal { groupAndIndex -> Signal<[ContextMenuItem], NoError> in
|
||||
return combineLatest(
|
||||
context.account.postbox.transaction { transaction -> (PeerGroupId, ChatListIndex)? in
|
||||
transaction.getPeerChatListIndex(peerId)
|
||||
},
|
||||
context.engine.peers.recentlySearchedPeers() |> take(1)
|
||||
)
|
||||
|> mapToSignal { groupAndIndex, recentlySearchedPeers -> Signal<[ContextMenuItem], NoError> in
|
||||
let location: TogglePeerChatPinnedLocation
|
||||
var chatListFilter: ChatListFilter?
|
||||
if case let .chatList(filter) = source, let chatFilter = filter {
|
||||
@ -100,7 +103,15 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
|
||||
})))
|
||||
items.append(.separator)
|
||||
case .search:
|
||||
break
|
||||
if recentlySearchedPeers.contains(where: { $0.peer.peerId == peerId }) {
|
||||
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_RemoveFromRecents, textColor: .destructive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Clear"), color: theme.contextMenu.destructiveColor) }, action: { _, f in
|
||||
let _ = (context.engine.peers.removeRecentlySearchedPeer(peerId: peerId)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
f(.default)
|
||||
})
|
||||
})))
|
||||
items.append(.separator)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1082,6 +1082,12 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
downloadItems = .single(([], []))
|
||||
}
|
||||
|
||||
struct SearchedPeersState {
|
||||
var ids: [EnginePeer.Id] = []
|
||||
var query: String?
|
||||
}
|
||||
let previousRecentlySearchedPeersState = Atomic<SearchedPeersState?>(value: nil)
|
||||
|
||||
let foundItems = combineLatest(queue: .mainQueue(), searchQuery, searchOptions, downloadItems)
|
||||
|> mapToSignal { [weak self] query, options, downloadItems -> Signal<([ChatListSearchEntry], Bool)?, NoError> in
|
||||
if query == nil && options == nil && key == .chats {
|
||||
@ -1185,9 +1191,42 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
let accountPeer = context.account.postbox.loadedPeerWithId(context.account.peerId) |> take(1)
|
||||
let foundLocalPeers: Signal<(peers: [EngineRenderedPeer], unread: [EnginePeer.Id: (Int32, Bool)], recentlySearchedPeerIds: Set<EnginePeer.Id>), NoError>
|
||||
if let query = query {
|
||||
let fixedOrRemovedRecentlySearchedPeers = context.engine.peers.recentlySearchedPeers()
|
||||
|> map { peers -> [RecentlySearchedPeer] in
|
||||
let allIds = peers.map(\.peer.peerId)
|
||||
|
||||
let updatedState = previousRecentlySearchedPeersState.modify { current in
|
||||
if var current = current, current.query == query {
|
||||
current.ids = current.ids.filter { id in
|
||||
allIds.contains(id)
|
||||
}
|
||||
|
||||
return current
|
||||
} else {
|
||||
var state = SearchedPeersState()
|
||||
state.ids = allIds
|
||||
state.query = query
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
var result: [RecentlySearchedPeer] = []
|
||||
if let updatedState = updatedState {
|
||||
for id in updatedState.ids {
|
||||
for peer in peers {
|
||||
if id == peer.peer.peerId {
|
||||
result.append(peer)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
foundLocalPeers = combineLatest(
|
||||
context.engine.contacts.searchLocalPeers(query: query.lowercased()),
|
||||
context.engine.peers.recentlySearchedPeers() |> take(1)
|
||||
fixedOrRemovedRecentlySearchedPeers
|
||||
)
|
||||
|> mapToSignal { local, allRecentlySearched -> Signal<([EnginePeer.Id: Optional<EnginePeer.NotificationSettings>], [EnginePeer.Id: Int], [EngineRenderedPeer], Set<EnginePeer.Id>), NoError> in
|
||||
let recentlySearched = allRecentlySearched.filter { peer in
|
||||
@ -1251,6 +1290,8 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
}
|
||||
} else {
|
||||
foundLocalPeers = .single((peers: [], unread: [:], recentlySearchedPeerIds: Set()))
|
||||
|
||||
let _ = previousRecentlySearchedPeersState.swap(nil)
|
||||
}
|
||||
|
||||
let foundRemotePeers: Signal<([FoundPeer], [FoundPeer], Bool), NoError>
|
||||
|
@ -377,6 +377,7 @@ public func notificationSoundSelectionController(context: AccountContext, update
|
||||
|
||||
let playSoundDisposable = MetaDisposable()
|
||||
let soundActionDisposable = MetaDisposable()
|
||||
let fetchedSoundsDisposable = ensureDownloadedNotificationSoundList(postbox: context.account.postbox).start()
|
||||
|
||||
let arguments = NotificationSoundSelectionArguments(account: context.account, selectSound: { sound in
|
||||
updateState { state in
|
||||
@ -422,6 +423,7 @@ public func notificationSoundSelectionController(context: AccountContext, update
|
||||
let controller = ItemListController(context: context, state: signal |> afterDisposed {
|
||||
playSoundDisposable.dispose()
|
||||
soundActionDisposable.dispose()
|
||||
fetchedSoundsDisposable.dispose()
|
||||
})
|
||||
controller.enableInteractiveDismiss = true
|
||||
if isModal {
|
||||
|
@ -694,6 +694,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
|
||||
|
||||
private let presentationDataValue = Promise<(PresentationTheme, PresentationStrings)>()
|
||||
private var listDisposable: Disposable?
|
||||
private var fetchedSoundsDisposable: Disposable?
|
||||
|
||||
private var arguments: NotificationExceptionArguments?
|
||||
private let stateValue: Atomic<NotificationExceptionState>
|
||||
@ -996,12 +997,15 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
|
||||
|
||||
self?.enqueueTransition(transition)
|
||||
})
|
||||
|
||||
self.fetchedSoundsDisposable = ensureDownloadedNotificationSoundList(postbox: context.account.postbox).start()
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.listDisposable?.dispose()
|
||||
self.navigationActionDisposable.dispose()
|
||||
self.updateNotificationsDisposable.dispose()
|
||||
self.fetchedSoundsDisposable?.dispose()
|
||||
}
|
||||
|
||||
func updatePresentationData(_ presentationData: PresentationData) {
|
||||
|
@ -139,6 +139,35 @@ func _internal_setCachedNotificationSoundList(transaction: Transaction, notifica
|
||||
}
|
||||
}
|
||||
|
||||
public func ensureDownloadedNotificationSoundList(postbox: Postbox) -> Signal<Never, NoError> {
|
||||
return postbox.transaction { transaction -> Signal<Never, NoError> in
|
||||
var signals: [Signal<Never, NoError>] = []
|
||||
|
||||
if let notificationSoundList = _internal_cachedNotificationSoundList(transaction: transaction) {
|
||||
var resources: [MediaResource] = []
|
||||
|
||||
for sound in notificationSoundList.sounds {
|
||||
resources.append(sound.file.resource)
|
||||
}
|
||||
|
||||
for resource in resources {
|
||||
signals.append(
|
||||
fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .standalone(resource: resource))
|
||||
|> ignoreValues
|
||||
|> `catch` { _ -> Signal<Never, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return combineLatest(signals)
|
||||
|> ignoreValues
|
||||
}
|
||||
|> switchToLatest
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Signal<Never, NoError> {
|
||||
return Signal<Never, NoError> { subscriber in
|
||||
let signal: Signal<Never, NoError> = _internal_cachedNotificationSoundList(postbox: postbox)
|
||||
|
Loading…
x
Reference in New Issue
Block a user