Update contact management

This commit is contained in:
Peter 2019-06-11 16:07:29 +01:00
parent 5603d1fc09
commit 9cfe296c53
2 changed files with 230 additions and 222 deletions

View File

@ -108,8 +108,8 @@ func syncContactsOnce(network: Network, postbox: Postbox, accountPeerId: PeerId)
return appliedUpdatedPeers return appliedUpdatedPeers
} }
public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal<Void, NoError> { public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal<Never, NoError> {
return account.postbox.transaction { transaction -> Signal<Void, NoError> in return account.postbox.transaction { transaction -> Signal<Never, NoError> in
if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) { if let peer = transaction.getPeer(peerId), let inputUser = apiInputUser(peer) {
return account.network.request(Api.functions.contacts.deleteContacts(id: [inputUser])) return account.network.request(Api.functions.contacts.deleteContacts(id: [inputUser]))
|> map(Optional.init) |> map(Optional.init)
@ -128,6 +128,7 @@ public func deleteContactPeerInteractively(account: Account, peerId: PeerId) ->
} }
} }
} }
|> ignoreValues
} else { } else {
return .complete() return .complete()
} }

View File

@ -104,9 +104,16 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} }
func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> { func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network: Network, postbox: Postbox) -> Signal<Void, NoError> {
return postbox.loadedPeerWithId(peerId) return postbox.transaction { transaction -> (Api.InputUser?, Peer?) in
|> mapToSignal { peer -> Signal<Void, NoError> in if peerId == accountPeerId {
if let inputUser = apiInputUser(peer) { return (.inputUserSelf, transaction.getPeer(peerId))
} else {
let peer = transaction.getPeer(peerId)
return (peer.flatMap(apiInputUser), peer)
}
}
|> mapToSignal { inputUser, maybePeer -> Signal<Void, NoError> in
if let inputUser = inputUser {
return network.request(Api.functions.users.getFullUser(id: inputUser)) return network.request(Api.functions.users.getFullUser(id: inputUser))
|> retryRequest |> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in |> mapToSignal { result -> Signal<Void, NoError> in
@ -119,7 +126,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
}) })
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: userFull.notifySettings)]) transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: userFull.notifySettings)])
if let presence = TelegramUserPresence(apiUser: userFull.user) { if let presence = TelegramUserPresence(apiUser: userFull.user) {
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: [peer.id: presence]) updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: [telegramUser.id: presence])
} }
} }
transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in
@ -145,7 +152,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
}) })
} }
} }
} else if let _ = peer as? TelegramGroup { } else if peerId.namespace == Namespaces.Peer.CloudGroup {
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id)) return network.request(Api.functions.messages.getFullChat(chatId: peerId.id))
|> retryRequest |> retryRequest
|> mapToSignal { result -> Signal<Void, NoError> in |> mapToSignal { result -> Signal<Void, NoError> in
@ -221,7 +228,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
} }
} }
} }
} else if let inputChannel = apiInputChannel(peer) { } else if let inputChannel = maybePeer.flatMap(apiInputChannel) {
return network.request(Api.functions.channels.getFullChannel(channel: inputChannel)) return network.request(Api.functions.channels.getFullChannel(channel: inputChannel))
|> map(Optional.init) |> map(Optional.init)
|> `catch` { error -> Signal<Api.messages.ChatFull?, NoError> in |> `catch` { error -> Signal<Api.messages.ChatFull?, NoError> in