Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin
2022-08-28 15:08:55 +02:00
79 changed files with 1821 additions and 725 deletions

View File

@@ -3,9 +3,11 @@ import SwiftSignalKit
import TelegramApi
public final class MessageReadStats {
public let reactionCount: Int
public let peers: [EnginePeer]
public init(peers: [EnginePeer]) {
public init(reactionCount: Int, peers: [EnginePeer]) {
self.reactionCount = reactionCount
self.peers = peers
}
}
@@ -22,12 +24,25 @@ func _internal_messageReadStats(account: Account, id: MessageId) -> Signal<Messa
return .single(nil)
}
return account.network.request(Api.functions.messages.getMessageReadParticipants(peer: inputPeer, msgId: id.id))
let readPeers: Signal<[Int64]?, NoError> = account.network.request(Api.functions.messages.getMessageReadParticipants(peer: inputPeer, msgId: id.id))
|> map(Optional.init)
|> `catch` { _ -> Signal<[Int64]?, NoError> in
return .single(nil)
}
|> mapToSignal { result -> Signal<MessageReadStats?, NoError> in
let reactionCount: Signal<Int, NoError> = account.network.request(Api.functions.messages.getMessageReactionsList(flags: 0, peer: inputPeer, id: id.id, reaction: nil, offset: nil, limit: 1))
|> map { result -> Int in
switch result {
case let .messageReactionsList(_, count, _, _, _, _):
return Int(count)
}
}
|> `catch` { _ -> Signal<Int, NoError> in
return .single(0)
}
return combineLatest(readPeers, reactionCount)
|> mapToSignal { result, reactionCount -> Signal<MessageReadStats?, NoError> in
guard let result = result else {
return .single(nil)
}
@@ -56,7 +71,7 @@ func _internal_messageReadStats(account: Account, id: MessageId) -> Signal<Messa
|> mapToSignal { peerIds, missingPeerIds -> Signal<MessageReadStats?, NoError> in
if missingPeerIds.isEmpty || id.peerId.namespace != Namespaces.Peer.CloudChannel {
return account.postbox.transaction { transaction -> MessageReadStats? in
return MessageReadStats(peers: peerIds.compactMap { peerId -> EnginePeer? in
return MessageReadStats(reactionCount: reactionCount, peers: peerIds.compactMap { peerId -> EnginePeer? in
return transaction.getPeer(peerId).flatMap(EnginePeer.init)
})
}
@@ -64,7 +79,7 @@ func _internal_messageReadStats(account: Account, id: MessageId) -> Signal<Messa
return _internal_channelMembers(postbox: account.postbox, network: account.network, accountPeerId: account.peerId, peerId: id.peerId, category: .recent(.all), offset: 0, limit: 50, hash: 0)
|> mapToSignal { _ -> Signal<MessageReadStats?, NoError> in
return account.postbox.transaction { transaction -> MessageReadStats? in
return MessageReadStats(peers: peerIds.compactMap { peerId -> EnginePeer? in
return MessageReadStats(reactionCount: reactionCount, peers: peerIds.compactMap { peerId -> EnginePeer? in
return transaction.getPeer(peerId).flatMap(EnginePeer.init)
})
}

View File

@@ -67,7 +67,7 @@ public enum AdminLogEventAction {
case participantJoinByRequest(invitation: ExportedInvitation, approvedBy: PeerId)
case toggleCopyProtection(Bool)
case sendMessage(Message)
case changeAvailableReactions(previousValue: [String], updatedValue: [String])
case changeAvailableReactions(previousValue: PeerAllowedReactions, updatedValue: PeerAllowedReactions)
}
public enum ChannelAdminLogEventError {
@@ -264,7 +264,7 @@ func channelAdminLogEvents(postbox: Postbox, network: Network, peerId: PeerId, m
action = .sendMessage(rendered)
}
case let .channelAdminLogEventActionChangeAvailableReactions(prevValue, newValue):
action = .changeAvailableReactions(previousValue: prevValue, updatedValue: newValue)
action = .changeAvailableReactions(previousValue: PeerAllowedReactions(apiReactions: prevValue), updatedValue: PeerAllowedReactions(apiReactions: newValue))
}
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
if let action = action {

View File

@@ -181,10 +181,10 @@ func _internal_reportPeerReaction(account: Account, authorId: PeerId, messageId:
return (peer, author)
}
|> mapToSignal { inputData -> Signal<Never, NoError> in
guard let (inputPeer, inputUser) = inputData else {
guard let (inputPeer, authorPeer) = inputData else {
return .complete()
}
return account.network.request(Api.functions.messages.reportReaction(peer: inputPeer, id: messageId.id, reactionPeer: inputUser))
return account.network.request(Api.functions.messages.reportReaction(peer: inputPeer, id: messageId.id, reactionPeer: authorPeer))
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}

View File

@@ -140,6 +140,18 @@ public extension TelegramEngine {
|> ignoreValues
}
public func clearRecentlyUsedReactions() -> Signal<Never, NoError> {
let _ = self.account.postbox.transaction({ transaction -> Void in
transaction.replaceOrderedItemListItems(collectionId: Namespaces.OrderedItemList.CloudRecentReactions, items: [])
}).start()
return self.account.network.request(Api.functions.messages.clearRecentReactions())
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}
|> ignoreValues
}
public func reorderStickerPacks(namespace: ItemCollectionId.Namespace, itemIds: [ItemCollectionId]) -> Signal<Never, NoError> {
return self.account.postbox.transaction { transaction -> Void in
let infos = transaction.getItemCollectionsInfos(namespace: namespace)