mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Refactoring
This commit is contained in:
parent
b4f35689f0
commit
2c7264dff0
@ -1048,7 +1048,7 @@ private final class WidgetIntentHandler {
|
||||
accountResults.append(accountTransaction(rootPath: rootPath, id: accountId, encryptionParameters: encryptionParameters, isReadOnly: true, useCopy: false, transaction: { postbox, transaction -> [Friend] in
|
||||
var peers: [Peer] = []
|
||||
|
||||
for id in getRecentPeers(transaction: transaction) {
|
||||
for id in _internal_getRecentPeers(transaction: transaction) {
|
||||
if let peer = transaction.getPeer(id), !(peer is TelegramSecretChat), !peer.isDeleted {
|
||||
peers.append(peer)
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public final class ChatListSearchRecentPeersNode: ASDisplayNode {
|
||||
|
||||
let peersDisposable = DisposableSet()
|
||||
|
||||
let recent: Signal<([Peer], [PeerId: (Int32, Bool)], [PeerId : PeerPresence]), NoError> = recentPeers(account: context.account)
|
||||
let recent: Signal<([Peer], [PeerId: (Int32, Bool)], [PeerId : PeerPresence]), NoError> = context.engine.peers.recentPeers()
|
||||
|> filter { value -> Bool in
|
||||
switch value {
|
||||
case .disabled:
|
||||
@ -224,7 +224,7 @@ public final class ChatListSearchRecentPeersNode: ASDisplayNode {
|
||||
}
|
||||
}))
|
||||
if case .actionSheet = mode {
|
||||
peersDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start())
|
||||
peersDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start())
|
||||
}
|
||||
self.disposable.set(peersDisposable)
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
|
||||
switch search {
|
||||
case .recentPeers:
|
||||
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 _ = (removeRecentPeer(account: context.account, peerId: peerId)
|
||||
let _ = (context.engine.peers.removeRecentPeer(peerId: peerId)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
f(.default)
|
||||
})
|
||||
|
@ -744,7 +744,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
|
||||
actionSheet?.dismissAnimated()
|
||||
|
||||
if let strongSelf = self {
|
||||
let _ = removeRecentPeer(account: strongSelf.context.account, peerId: peer.id).start()
|
||||
let _ = strongSelf.context.engine.peers.removeRecentPeer(peerId: peer.id).start()
|
||||
}
|
||||
})
|
||||
]),
|
||||
|
@ -1395,7 +1395,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
}))
|
||||
|
||||
let previousRecentItems = Atomic<[ChatListRecentEntry]?>(value: nil)
|
||||
let hasRecentPeers = recentPeers(account: context.account)
|
||||
let hasRecentPeers = context.engine.peers.recentPeers()
|
||||
|> map { value -> Bool in
|
||||
switch value {
|
||||
case let .peers(peers):
|
||||
@ -1465,7 +1465,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
|
||||
}
|
||||
|
||||
if tagMask == nil && !peersFilter.contains(.excludeRecent) {
|
||||
self.updatedRecentPeersDisposable.set(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start())
|
||||
self.updatedRecentPeersDisposable.set(context.engine.peers.managedUpdatedRecentPeers().start())
|
||||
}
|
||||
|
||||
self.recentDisposable.set((combineLatest(queue: .mainQueue(),
|
||||
|
@ -391,7 +391,7 @@ public func channelBlacklistController(context: AccountContext, peerId: PeerId)
|
||||
let signal = context.peerChannelMemberCategoriesContextsManager.updateMemberBannedRights(engine: context.engine, peerId: peerId, memberId: memberId, bannedRights: nil)
|
||||
|> ignoreValues
|
||||
|> then(
|
||||
context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: peerId, memberId: memberId)
|
||||
context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: peerId, memberId: memberId)
|
||||
|> map { _ -> Void in
|
||||
return Void()
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ public func channelMembersController(context: AccountContext, peerId: PeerId) ->
|
||||
contacts = peerIdsValue
|
||||
}
|
||||
|
||||
let signal = context.peerChannelMemberCategoriesContextsManager.addMembers(account: context.account, peerId: peerId, memberIds: contacts.compactMap({ contact -> PeerId? in
|
||||
let signal = context.peerChannelMemberCategoriesContextsManager.addMembers(engine: context.engine, peerId: peerId, memberIds: contacts.compactMap({ contact -> PeerId? in
|
||||
switch contact {
|
||||
case let .peer(contactId):
|
||||
return contactId
|
||||
|
@ -1357,7 +1357,7 @@ public func channelVisibilityController(context: AccountContext, peerId: PeerId,
|
||||
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, chatController: nil, context: context, chatLocation: .peer(peerId), keepStack: .never, animated: true))
|
||||
} else {
|
||||
selectionController.displayProgress = true
|
||||
let _ = (addChannelMembers(account: context.account, peerId: peerId, memberIds: filteredPeerIds)
|
||||
let _ = (context.engine.peers.addChannelMembers(peerId: peerId, memberIds: filteredPeerIds)
|
||||
|> deliverOnMainQueue).start(error: { [weak selectionController] _ in
|
||||
guard let selectionController = selectionController, let navigationController = selectionController.navigationController as? NavigationController else {
|
||||
return
|
||||
|
@ -453,7 +453,7 @@ public func dataPrivacyController(context: AccountContext) -> ViewController {
|
||||
state.updatedSuggestFrequentContacts = value
|
||||
return state
|
||||
}
|
||||
let _ = updateRecentPeersEnabled(postbox: context.account.postbox, network: context.account.network, enabled: value).start()
|
||||
let _ = context.engine.peers.updateRecentPeersEnabled(enabled: value).start()
|
||||
}
|
||||
if !value {
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
@ -503,9 +503,9 @@ public func dataPrivacyController(context: AccountContext) -> ViewController {
|
||||
|
||||
let previousState = Atomic<DataPrivacyControllerState?>(value: nil)
|
||||
|
||||
actionsDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start())
|
||||
actionsDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start())
|
||||
|
||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), recentPeers(account: context.account))
|
||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.engine.peers.recentPeers())
|
||||
|> map { presentationData, state, noticeView, sharedData, preferences, recentPeers -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
let secretChatLinkPreviews = noticeView.value.flatMap({ ApplicationSpecificNotice.getSecretChatLinkPreviews($0) })
|
||||
|
||||
|
@ -851,7 +851,7 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting
|
||||
pushControllerImpl?(dataPrivacyController(context: context), true)
|
||||
})
|
||||
|
||||
actionsDisposable.add(managedUpdatedRecentPeers(accountPeerId: context.account.peerId, postbox: context.account.postbox, network: context.account.network).start())
|
||||
actionsDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start())
|
||||
|
||||
actionsDisposable.add((privacySettingsPromise.get()
|
||||
|> deliverOnMainQueue).start(next: { settings in
|
||||
@ -865,7 +865,7 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting
|
||||
|
||||
let preferencesKey: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.appConfiguration]))
|
||||
|
||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), privacySettingsPromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), recentPeers(account: context.account), blockedPeersState.get(), webSessionsContext.state, context.sharedContext.accountManager.accessChallengeData(), combineLatest(twoStepAuth.get(), twoStepAuthDataValue.get()), context.account.postbox.combinedView(keys: [preferencesKey]))
|
||||
let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), privacySettingsPromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.engine.peers.recentPeers(), blockedPeersState.get(), webSessionsContext.state, context.sharedContext.accountManager.accessChallengeData(), combineLatest(twoStepAuth.get(), twoStepAuthDataValue.get()), context.account.postbox.combinedView(keys: [preferencesKey]))
|
||||
|> map { presentationData, state, privacySettings, noticeView, sharedData, recentPeers, blockedPeersState, activeWebsitesState, accessChallengeData, twoStepAuth, preferences -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var canAutoarchive = false
|
||||
if let view = preferences.views[preferencesKey] as? PreferencesView, let appConfiguration = view.values[PreferencesKeys.appConfiguration] as? AppConfiguration, let data = appConfiguration.data, let hasAutoarchive = data["autoarchive_setting_available"] as? Bool {
|
||||
|
@ -435,7 +435,7 @@ public final class ShareController: ViewController {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
let _ = (exportMessageLink(account: strongSelf.currentAccount, peerId: chatPeer.id, messageId: message.id)
|
||||
let _ = (TelegramEngine(account: strongSelf.currentAccount).messages.exportMessageLink(peerId: chatPeer.id, messageId: message.id)
|
||||
|> map { result -> String? in
|
||||
return result
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode {
|
||||
self?.searchQuery.set(text)
|
||||
}
|
||||
|
||||
let hasRecentPeers = recentPeers(account: context.account)
|
||||
let hasRecentPeers = context.engine.peers.recentPeers()
|
||||
|> map { value -> Bool in
|
||||
switch value {
|
||||
case let .peers(peers):
|
||||
|
@ -1286,7 +1286,7 @@ public final class VoiceChatController: ViewController {
|
||||
if let groupPeer = groupPeer as? TelegramChannel {
|
||||
let selfController = strongSelf.controller
|
||||
let inviteDisposable = strongSelf.inviteDisposable
|
||||
var inviteSignal = strongSelf.context.peerChannelMemberCategoriesContextsManager.addMembers(account: strongSelf.context.account, peerId: groupPeer.id, memberIds: [peer.id])
|
||||
var inviteSignal = strongSelf.context.peerChannelMemberCategoriesContextsManager.addMembers(engine: strongSelf.context.engine, peerId: groupPeer.id, memberIds: [peer.id])
|
||||
var cancelImpl: (() -> Void)?
|
||||
let progressSignal = Signal<Never, NoError> { [weak selfController] subscriber in
|
||||
let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: {
|
||||
@ -1358,7 +1358,7 @@ public final class VoiceChatController: ViewController {
|
||||
} else if let groupPeer = groupPeer as? TelegramGroup {
|
||||
let selfController = strongSelf.controller
|
||||
let inviteDisposable = strongSelf.inviteDisposable
|
||||
var inviteSignal = addGroupMember(account: strongSelf.context.account, peerId: groupPeer.id, memberId: peer.id)
|
||||
var inviteSignal = strongSelf.context.engine.peers.addGroupMember(peerId: groupPeer.id, memberId: peer.id)
|
||||
var cancelImpl: (() -> Void)?
|
||||
let progressSignal = Signal<Never, NoError> { [weak selfController] subscriber in
|
||||
let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: {
|
||||
|
@ -1055,7 +1055,7 @@ public class Account {
|
||||
self.managedOperationsDisposable.add(managedSynchronizeRecentlyUsedMediaOperations(postbox: self.postbox, network: self.network, category: .stickers, revalidationContext: self.mediaReferenceRevalidationContext).start())
|
||||
self.managedOperationsDisposable.add(managedSynchronizeSavedGifsOperations(postbox: self.postbox, network: self.network, revalidationContext: self.mediaReferenceRevalidationContext).start())
|
||||
self.managedOperationsDisposable.add(managedSynchronizeSavedStickersOperations(postbox: self.postbox, network: self.network, revalidationContext: self.mediaReferenceRevalidationContext).start())
|
||||
self.managedOperationsDisposable.add(managedRecentlyUsedInlineBots(postbox: self.postbox, network: self.network, accountPeerId: peerId).start())
|
||||
self.managedOperationsDisposable.add(_internal_managedRecentlyUsedInlineBots(postbox: self.postbox, network: self.network, accountPeerId: peerId).start())
|
||||
self.managedOperationsDisposable.add(managedLocalTypingActivities(activities: self.localInputActivityManager.allActivities(), postbox: self.postbox, network: self.network, accountPeerId: self.peerId).start())
|
||||
self.managedOperationsDisposable.add(managedSynchronizeConsumeMessageContentOperations(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start())
|
||||
self.managedOperationsDisposable.add(managedConsumePersonalMessagesActions(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start())
|
||||
|
@ -3,7 +3,7 @@ import Postbox
|
||||
import TelegramApi
|
||||
import SwiftSignalKit
|
||||
|
||||
public func exportMessageLink(account: Account, peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal<String?, NoError> {
|
||||
func _internal_exportMessageLink(account: Account, peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal<String?, NoError> {
|
||||
return account.postbox.transaction { transaction -> (Peer, MessageId)? in
|
||||
var peer: Peer? = transaction.getPeer(messageId.peerId)
|
||||
if let peer = peer {
|
@ -147,5 +147,9 @@ public extension TelegramEngine {
|
||||
public func earliestUnseenPersonalMentionMessage(peerId: PeerId) -> Signal<EarliestUnseenPersonalMentionMessageResult, NoError> {
|
||||
return _internal_earliestUnseenPersonalMentionMessage(account: self.account, peerId: peerId)
|
||||
}
|
||||
|
||||
public func exportMessageLink(peerId: PeerId, messageId: MessageId, isThread: Bool = false) -> Signal<String?, NoError> {
|
||||
return _internal_exportMessageLink(account: self.account, peerId: peerId, messageId: messageId, isThread: isThread)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public enum AddGroupMemberError {
|
||||
case tooManyChannels
|
||||
}
|
||||
|
||||
public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<Void, AddGroupMemberError> {
|
||||
func _internal_addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<Void, AddGroupMemberError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, AddGroupMemberError> in
|
||||
if let peer = transaction.getPeer(peerId), let memberPeer = transaction.getPeer(memberId), let inputUser = apiInputUser(memberPeer) {
|
||||
if let group = peer as? TelegramGroup {
|
||||
@ -79,7 +79,7 @@ public enum AddChannelMemberError {
|
||||
case tooMuchBots
|
||||
}
|
||||
|
||||
public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> {
|
||||
func _internal_addChannelMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> {
|
||||
return _internal_fetchChannelParticipant(account: account, peerId: peerId, participantId: memberId)
|
||||
|> mapError { error -> AddChannelMemberError in
|
||||
}
|
||||
@ -180,7 +180,7 @@ public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId)
|
||||
}
|
||||
}
|
||||
|
||||
public func addChannelMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal<Void, AddChannelMemberError> {
|
||||
func _internal_addChannelMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal<Void, AddChannelMemberError> {
|
||||
let signal = account.postbox.transaction { transaction -> Signal<Void, AddChannelMemberError> in
|
||||
var memberPeerIds: [PeerId:Peer] = [:]
|
||||
var inputUsers: [Api.InputUser] = []
|
@ -65,7 +65,7 @@ func _internal_addGroupAdmin(account: Account, peerId: PeerId, adminId: PeerId)
|
||||
return account.network.request(Api.functions.messages.editChatAdmin(chatId: group.id.id._internalGetInt32Value(), userId: inputUser, isAdmin: .boolTrue))
|
||||
|> `catch` { error -> Signal<Api.Bool, AddGroupAdminError> in
|
||||
if error.errorDescription == "USER_NOT_PARTICIPANT" {
|
||||
return addGroupMember(account: account, peerId: peerId, memberId: adminId)
|
||||
return _internal_addGroupMember(account: account, peerId: peerId, memberId: adminId)
|
||||
|> mapError { error -> AddGroupAdminError in
|
||||
return .addMemberError(error)
|
||||
}
|
||||
@ -188,7 +188,7 @@ func _internal_updateChannelAdminRights(account: Account, peerId: PeerId, adminI
|
||||
|> map { [$0] }
|
||||
|> `catch` { error -> Signal<[Api.Updates], UpdateChannelAdminRightsError> in
|
||||
if error.errorDescription == "USER_NOT_PARTICIPANT" {
|
||||
return addChannelMember(account: account, peerId: peerId, memberId: adminId)
|
||||
return _internal_addChannelMember(account: account, peerId: peerId, memberId: adminId)
|
||||
|> map { _ -> [Api.Updates] in
|
||||
return []
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ private func cachedRecentPeersEntryId() -> ItemCacheEntryId {
|
||||
return ItemCacheEntryId(collectionId: 101, key: CachedRecentPeers.cacheKey())
|
||||
}
|
||||
|
||||
public func recentPeers(account: Account) -> Signal<RecentPeers, NoError> {
|
||||
func _internal_recentPeers(account: Account) -> Signal<RecentPeers, NoError> {
|
||||
let key = PostboxViewKey.cachedItem(cachedRecentPeersEntryId())
|
||||
return account.postbox.combinedView(keys: [key])
|
||||
|> mapToSignal { views -> Signal<RecentPeers, NoError> in
|
||||
@ -41,14 +41,14 @@ public func recentPeers(account: Account) -> Signal<RecentPeers, NoError> {
|
||||
}
|
||||
}
|
||||
|
||||
public func getRecentPeers(transaction: Transaction) -> [PeerId] {
|
||||
public func _internal_getRecentPeers(transaction: Transaction) -> [PeerId] {
|
||||
guard let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers else {
|
||||
return []
|
||||
}
|
||||
return entry.ids
|
||||
}
|
||||
|
||||
public func managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, network: Network) -> Signal<Void, NoError> {
|
||||
func _internal_managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, network: Network) -> Signal<Void, NoError> {
|
||||
let key = PostboxViewKey.cachedItem(cachedRecentPeersEntryId())
|
||||
let peersEnabled = postbox.combinedView(keys: [key])
|
||||
|> map { views -> Bool in
|
||||
@ -96,7 +96,7 @@ public func managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox, n
|
||||
}
|
||||
}
|
||||
|
||||
public func removeRecentPeer(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
func _internal_removeRecentPeer(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
|
||||
guard let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers else {
|
||||
return .complete()
|
||||
@ -121,7 +121,7 @@ public func removeRecentPeer(account: Account, peerId: PeerId) -> Signal<Void, N
|
||||
} |> switchToLatest
|
||||
}
|
||||
|
||||
public func updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled: Bool) -> Signal<Void, NoError> {
|
||||
func _internal_updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled: Bool) -> Signal<Void, NoError> {
|
||||
return postbox.transaction { transaction -> Signal<Void, NoError> in
|
||||
var currentValue = true
|
||||
if let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId()) as? CachedRecentPeers {
|
||||
@ -149,7 +149,7 @@ public func updateRecentPeersEnabled(postbox: Postbox, network: Network, enabled
|
||||
} |> switchToLatest
|
||||
}
|
||||
|
||||
public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal<Void, NoError> {
|
||||
func _internal_managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, accountPeerId: PeerId) -> Signal<Void, NoError> {
|
||||
let remotePeers = network.request(Api.functions.contacts.getTopPeers(flags: 1 << 2, offset: 0, limit: 16, hash: 0))
|
||||
|> retryRequest
|
||||
|> map { result -> ([Peer], [PeerId: PeerPresence], [(PeerId, Double)])? in
|
||||
@ -207,7 +207,7 @@ public func managedRecentlyUsedInlineBots(postbox: Postbox, network: Network, ac
|
||||
return updatedRemotePeers
|
||||
}
|
||||
|
||||
public func addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
func _internal_addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return postbox.transaction { transaction -> Void in
|
||||
var maxRating = 1.0
|
||||
for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots) {
|
||||
@ -219,7 +219,7 @@ public func addRecentlyUsedInlineBot(postbox: Postbox, peerId: PeerId) -> Signal
|
||||
}
|
||||
}
|
||||
|
||||
public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], NoError> {
|
||||
func _internal_recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)], NoError> {
|
||||
return postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentInlineBots)])
|
||||
|> take(1)
|
||||
|> mapToSignal { view -> Signal<[(Peer, Double)], NoError> in
|
||||
@ -238,7 +238,7 @@ public func recentlyUsedInlineBots(postbox: Postbox) -> Signal<[(Peer, Double)],
|
||||
}
|
||||
}
|
||||
|
||||
public func removeRecentlyUsedInlineBot(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
func _internal_removeRecentlyUsedInlineBot(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
|
||||
transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentInlineBots, itemId: RecentPeerItemId(peerId).rawValue)
|
||||
|
@ -287,5 +287,45 @@ public extension TelegramEngine {
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func addGroupMember(peerId: PeerId, memberId: PeerId) -> Signal<Void, AddGroupMemberError> {
|
||||
return _internal_addGroupMember(account: self.account, peerId: peerId, memberId: memberId)
|
||||
}
|
||||
|
||||
public func addChannelMember(peerId: PeerId, memberId: PeerId) -> Signal<(ChannelParticipant?, RenderedChannelParticipant), AddChannelMemberError> {
|
||||
return _internal_addChannelMember(account: self.account, peerId: peerId, memberId: memberId)
|
||||
}
|
||||
|
||||
public func addChannelMembers(peerId: PeerId, memberIds: [PeerId]) -> Signal<Void, AddChannelMemberError> {
|
||||
return _internal_addChannelMembers(account: self.account, peerId: peerId, memberIds: memberIds)
|
||||
}
|
||||
|
||||
public func recentPeers() -> Signal<RecentPeers, NoError> {
|
||||
return _internal_recentPeers(account: self.account)
|
||||
}
|
||||
|
||||
public func managedUpdatedRecentPeers() -> Signal<Void, NoError> {
|
||||
return _internal_managedUpdatedRecentPeers(accountPeerId: self.account.peerId, postbox: self.account.postbox, network: self.account.network)
|
||||
}
|
||||
|
||||
public func removeRecentPeer(peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return _internal_removeRecentPeer(account: self.account, peerId: peerId)
|
||||
}
|
||||
|
||||
public func updateRecentPeersEnabled(enabled: Bool) -> Signal<Void, NoError> {
|
||||
return _internal_updateRecentPeersEnabled(postbox: self.account.postbox, network: self.account.network, enabled: enabled)
|
||||
}
|
||||
|
||||
public func addRecentlyUsedInlineBot(peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return _internal_addRecentlyUsedInlineBot(postbox: self.account.postbox, peerId: peerId)
|
||||
}
|
||||
|
||||
public func recentlyUsedInlineBots() -> Signal<[(Peer, Double)], NoError> {
|
||||
return _internal_recentlyUsedInlineBots(postbox: self.account.postbox)
|
||||
}
|
||||
|
||||
public func removeRecentlyUsedInlineBot(peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return _internal_removeRecentlyUsedInlineBot(account: self.account, peerId: peerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1902,7 +1902,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
if case let .replyThread(replyThreadMessage) = chatPresentationInterfaceState.chatLocation {
|
||||
threadMessageId = replyThreadMessage.messageId
|
||||
}
|
||||
let _ = (exportMessageLink(account: context.account, peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil)
|
||||
let _ = (context.engine.messages.exportMessageLink(peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil)
|
||||
|> map { result -> String? in
|
||||
return result
|
||||
}
|
||||
@ -7056,7 +7056,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
|
||||
self.chatDisplayNode.loadInputPanels(theme: self.presentationInterfaceState.theme, strings: self.presentationInterfaceState.strings, fontSize: self.presentationInterfaceState.fontSize)
|
||||
|
||||
self.recentlyUsedInlineBotsDisposable = (recentlyUsedInlineBots(postbox: self.context.account.postbox) |> deliverOnMainQueue).start(next: { [weak self] peers in
|
||||
self.recentlyUsedInlineBotsDisposable = (self.context.engine.peers.recentlyUsedInlineBots() |> deliverOnMainQueue).start(next: { [weak self] peers in
|
||||
self?.recentlyUsedInlineBotsValue = peers.filter({ $0.1 >= 0.14 }).map({ $0.0 })
|
||||
})
|
||||
|
||||
|
@ -797,7 +797,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
if case let .replyThread(replyThreadMessage) = chatPresentationInterfaceState.chatLocation {
|
||||
threadMessageId = replyThreadMessage.messageId
|
||||
}
|
||||
let _ = (exportMessageLink(account: context.account, peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil)
|
||||
let _ = (context.engine.messages.exportMessageLink(peerId: message.id.peerId, messageId: message.id, isThread: threadMessageId != nil)
|
||||
|> map { result -> String? in
|
||||
return result
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee
|
||||
signal = .single({ _ in return .mentions([]) })
|
||||
}
|
||||
|
||||
let inlineBots: Signal<[(Peer, Double)], NoError> = types.contains(.contextBots) ? recentlyUsedInlineBots(postbox: context.account.postbox) : .single([])
|
||||
let inlineBots: Signal<[(Peer, Double)], NoError> = types.contains(.contextBots) ? context.engine.peers.recentlyUsedInlineBots() : .single([])
|
||||
let participants = combineLatest(inlineBots, searchPeerMembers(context: context, peerId: peer.id, chatLocation: chatLocation, query: query, scope: .mention))
|
||||
|> map { inlineBots, peers -> (ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult? in
|
||||
let filteredInlineBots = inlineBots.sorted(by: { $0.1 > $1.1 }).filter { peer, rating in
|
||||
|
@ -165,7 +165,7 @@ final class MentionChatInputContextPanelNode: ChatInputContextPanelNode {
|
||||
}
|
||||
}, removeRequested: { [weak self] peerId in
|
||||
if let strongSelf = self {
|
||||
let _ = removeRecentlyUsedInlineBot(account: strongSelf.context.account, peerId: peerId).start()
|
||||
let _ = strongSelf.context.engine.peers.removeRecentlyUsedInlineBot(peerId: peerId).start()
|
||||
|
||||
strongSelf.revealedPeerId = nil
|
||||
strongSelf.currentResults = strongSelf.currentResults.filter { $0.id != peerId }
|
||||
|
@ -67,12 +67,12 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
|
||||
|
||||
if payload.isEmpty {
|
||||
if peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||
let _ = (addGroupMember(account: context.account, peerId: peerId, memberId: botPeerId)
|
||||
let _ = (context.engine.peers.addGroupMember(peerId: peerId, memberId: botPeerId)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
controller?.dismiss()
|
||||
})
|
||||
} else {
|
||||
let _ = (addChannelMember(account: context.account, peerId: peerId, memberId: botPeerId)
|
||||
let _ = (context.engine.peers.addChannelMember(peerId: peerId, memberId: botPeerId)
|
||||
|> deliverOnMainQueue).start(completed: {
|
||||
controller?.dismiss()
|
||||
})
|
||||
|
@ -7209,14 +7209,14 @@ func presentAddMembers(context: AccountContext, parentController: ViewController
|
||||
if case let .peer(selectedPeer, _, _) = memberPeer {
|
||||
let memberId = selectedPeer.id
|
||||
if groupPeer.id.namespace == Namespaces.Peer.CloudChannel {
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: groupPeer.id, memberId: memberId)
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: groupPeer.id, memberId: memberId)
|
||||
|> map { _ -> Void in
|
||||
}
|
||||
|> `catch` { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
} else {
|
||||
return addGroupMember(account: context.account, peerId: groupPeer.id, memberId: memberId)
|
||||
return context.engine.peers.addGroupMember(peerId: groupPeer.id, memberId: memberId)
|
||||
|> deliverOnMainQueue
|
||||
|> `catch` { error -> Signal<Void, NoError> in
|
||||
switch error {
|
||||
@ -7264,7 +7264,7 @@ func presentAddMembers(context: AccountContext, parentController: ViewController
|
||||
guard let upgradedPeerId = upgradedPeerId else {
|
||||
return .single(nil)
|
||||
}
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: upgradedPeerId, memberId: memberId)
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: upgradedPeerId, memberId: memberId)
|
||||
|> `catch` { _ -> Signal<Never, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
@ -7300,11 +7300,11 @@ func presentAddMembers(context: AccountContext, parentController: ViewController
|
||||
|> castError(AddChannelMemberError.self)
|
||||
|> mapToSignal { view -> Signal<Void, AddChannelMemberError> in
|
||||
if memberIds.count == 1 {
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(account: context.account, peerId: groupPeer.id, memberId: memberIds[0])
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMember(engine: context.engine, peerId: groupPeer.id, memberId: memberIds[0])
|
||||
|> map { _ -> Void in
|
||||
}
|
||||
} else {
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMembers(account: context.account, peerId: groupPeer.id, memberIds: memberIds) |> map { _ in
|
||||
return context.peerChannelMemberCategoriesContextsManager.addMembers(engine: context.engine, peerId: groupPeer.id, memberIds: memberIds) |> map { _ in
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -435,8 +435,8 @@ public final class PeerChannelMemberCategoriesContextsManager {
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func addMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal<Never, AddChannelMemberError> {
|
||||
return addChannelMember(account: account, peerId: peerId, memberId: memberId)
|
||||
public func addMember(engine: TelegramEngine, peerId: PeerId, memberId: PeerId) -> Signal<Never, AddChannelMemberError> {
|
||||
return engine.peers.addChannelMember(peerId: peerId, memberId: memberId)
|
||||
|> deliverOnMainQueue
|
||||
|> beforeNext { [weak self] result in
|
||||
if let strongSelf = self {
|
||||
@ -453,9 +453,9 @@ public final class PeerChannelMemberCategoriesContextsManager {
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
public func addMembers(account: Account, peerId: PeerId, memberIds: [PeerId]) -> Signal<Void, AddChannelMemberError> {
|
||||
public func addMembers(engine: TelegramEngine, peerId: PeerId, memberIds: [PeerId]) -> Signal<Void, AddChannelMemberError> {
|
||||
let signals: [Signal<(ChannelParticipant?, RenderedChannelParticipant)?, AddChannelMemberError>] = memberIds.map({ memberId in
|
||||
return addChannelMember(account: account, peerId: peerId, memberId: memberId)
|
||||
return engine.peers.addChannelMember(peerId: peerId, memberId: memberId)
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<(ChannelParticipant?, RenderedChannelParticipant)?, AddChannelMemberError> in
|
||||
return .fail(error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user