Group boosts

This commit is contained in:
Ilya Laktyushin
2024-02-01 12:29:07 +04:00
parent 2716a936bf
commit 1b2b7dc403
120 changed files with 5295 additions and 887 deletions

View File

@@ -539,6 +539,33 @@ public extension TelegramEngine.EngineData.Item {
}
}
public struct EmojiPack: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
public typealias Result = StickerPackCollectionInfo?
fileprivate var id: EnginePeer.Id
public var mapKey: EnginePeer.Id {
return self.id
}
public init(id: EnginePeer.Id) {
self.id = id
}
var key: PostboxViewKey {
return .cachedPeerData(peerId: self.id)
}
func extract(view: PostboxView) -> Result {
guard let view = view as? CachedPeerDataView else {
preconditionFailure()
}
guard let cachedData = view.cachedPeerData as? CachedChannelData else {
return nil
}
return cachedData.emojiPack
}
}
public struct AllowedReactions: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
public typealias Result = EnginePeerCachedInfoItem<PeerAllowedReactions>

View File

@@ -91,6 +91,7 @@ public enum AdminLogEventAction {
case changeProfileColor(prevColor: PeerNameColor?, prevIcon: Int64?, newColor: PeerNameColor?, newIcon: Int64?)
case changeWallpaper(prev: TelegramWallpaper?, new: TelegramWallpaper?)
case changeStatus(prev: PeerEmojiStatus?, new: PeerEmojiStatus?)
case changeEmojiPack(prev: StickerPackReference?, new: StickerPackReference?)
}
public enum ChannelAdminLogEventError {
@@ -414,6 +415,8 @@ func channelAdminLogEvents(accountPeerId: PeerId, postbox: Postbox, network: Net
action = .changeWallpaper(prev: prev, new: new)
case let .channelAdminLogEventActionChangeEmojiStatus(prevValue, newValue):
action = .changeStatus(prev: PeerEmojiStatus(apiStatus: prevValue), new: PeerEmojiStatus(apiStatus: newValue))
case let .channelAdminLogEventActionChangeEmojiStickerSet(prevStickerset, newStickerset):
action = .changeEmojiPack(prev: StickerPackReference(apiInputSet: prevStickerset), new: StickerPackReference(apiInputSet: newStickerset))
}
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(userId))
if let action = action {

View File

@@ -46,3 +46,35 @@ func _internal_peerSpecificStickerPack(postbox: Postbox, network: Network, peerI
return .single(PeerSpecificStickerPackData(packInfo: nil, canSetup: false))
}
}
func _internal_peerSpecificEmojiPack(postbox: Postbox, network: Network, peerId: PeerId) -> Signal<PeerSpecificStickerPackData, NoError> {
if peerId.namespace == Namespaces.Peer.CloudChannel {
let signal: Signal<(WrappedStickerPackCollectionInfo, Bool), NoError> = postbox.combinedView(keys: [.cachedPeerData(peerId: peerId)])
|> map { view -> (WrappedStickerPackCollectionInfo, Bool) in
let dataView = view.views[.cachedPeerData(peerId: peerId)] as? CachedPeerDataView
return (WrappedStickerPackCollectionInfo(info: (dataView?.cachedPeerData as? CachedChannelData)?.emojiPack), (dataView?.cachedPeerData as? CachedChannelData)?.flags.contains(.canSetStickerSet) ?? false)
}
|> distinctUntilChanged(isEqual: { lhs, rhs -> Bool in
return lhs.0 == rhs.0 && lhs.1 == rhs.1
})
return signal
|> mapToSignal { info, canInstall -> Signal<PeerSpecificStickerPackData, NoError> in
if let info = info.info {
return _internal_cachedStickerPack(postbox: postbox, network: network, reference: .id(id: info.id.id, accessHash: info.accessHash), forceRemote: false)
|> map { result -> PeerSpecificStickerPackData in
if case let .result(info, items, _) = result {
return PeerSpecificStickerPackData(packInfo: (info, items), canSetup: canInstall)
} else {
return PeerSpecificStickerPackData(packInfo: nil, canSetup: canInstall)
}
}
} else {
return .single(PeerSpecificStickerPackData(packInfo: nil, canSetup: canInstall))
}
}
} else {
return .single(PeerSpecificStickerPackData(packInfo: nil, canSetup: false))
}
}

View File

@@ -419,6 +419,10 @@ public extension TelegramEngine {
public func updateGroupSpecificStickerset(peerId: PeerId, info: StickerPackCollectionInfo?) -> Signal<Void, UpdateGroupSpecificStickersetError> {
return _internal_updateGroupSpecificStickerset(postbox: self.account.postbox, network: self.account.network, peerId: peerId, info: info)
}
public func updateGroupSpecificEmojiset(peerId: PeerId, info: StickerPackCollectionInfo?) -> Signal<Void, UpdateGroupSpecificEmojisetError> {
return _internal_updateGroupSpecificEmojiset(postbox: self.account.postbox, network: self.account.network, peerId: peerId, info: info)
}
public func joinChannel(peerId: PeerId, hash: String?) -> Signal<RenderedChannelParticipant?, JoinChannelError> {
return _internal_joinChannel(account: self.account, peerId: peerId, hash: hash)
@@ -462,6 +466,10 @@ public extension TelegramEngine {
public func peerSpecificStickerPack(peerId: PeerId) -> Signal<PeerSpecificStickerPackData, NoError> {
return _internal_peerSpecificStickerPack(postbox: self.account.postbox, network: self.account.network, peerId: peerId)
}
public func peerSpecificEmojiPack(peerId: PeerId) -> Signal<PeerSpecificStickerPackData, NoError> {
return _internal_peerSpecificEmojiPack(postbox: self.account.postbox, network: self.account.network, peerId: peerId)
}
public func addRecentlySearchedPeer(peerId: PeerId) -> Signal<Void, NoError> {
return _internal_addRecentlySearchedPeer(postbox: self.account.postbox, peerId: peerId)

View File

@@ -452,14 +452,14 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
switch result {
case let .chatFull(fullChat, chats, users):
switch fullChat {
case let .channelFull(_, _, _, _, _, _, _, _, _, _, _, _, _, notifySettings, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
case let .channelFull(_, _, _, _, _, _, _, _, _, _, _, _, _, notifySettings, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _):
transaction.updateCurrentPeerNotificationSettings([peerId: TelegramPeerNotificationSettings(apiSettings: notifySettings)])
case .chatFull:
break
}
switch fullChat {
case let .channelFull(flags, flags2, _, about, participantsCount, adminsCount, kickedCount, bannedCount, _, _, _, _, chatPhoto, _, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, _, linkedChatId, location, slowmodeSeconds, slowmodeNextSendDate, statsDc, _, inputCall, ttl, pendingSuggestions, groupcallDefaultJoinAs, themeEmoticon, requestsPending, _, defaultSendAs, allowedReactions, _, wallpaper):
case let .channelFull(flags, flags2, _, about, participantsCount, adminsCount, kickedCount, bannedCount, _, _, _, _, chatPhoto, _, apiExportedInvite, apiBotInfos, migratedFromChatId, migratedFromMaxId, pinnedMsgId, stickerSet, minAvailableMsgId, _, linkedChatId, location, slowmodeSeconds, slowmodeNextSendDate, statsDc, _, inputCall, ttl, pendingSuggestions, groupcallDefaultJoinAs, themeEmoticon, requestsPending, _, defaultSendAs, allowedReactions, _, wallpaper, _, boostsUnrestrict, emojiSet):
var channelFlags = CachedChannelFlags()
if (flags & (1 << 3)) != 0 {
channelFlags.insert(.canDisplayParticipants)
@@ -588,6 +588,22 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
}
let photo = telegramMediaImageFromApiPhoto(chatPhoto)
let emojiPack: StickerPackCollectionInfo? = emojiSet.flatMap { apiSet -> StickerPackCollectionInfo in
let namespace: ItemCollectionId.Namespace
switch apiSet {
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
if (flags & (1 << 3)) != 0 {
namespace = Namespaces.ItemCollection.CloudMaskPacks
} else if (flags & (1 << 7)) != 0 {
namespace = Namespaces.ItemCollection.CloudEmojiPacks
} else {
namespace = Namespaces.ItemCollection.CloudStickerPacks
}
}
return StickerPackCollectionInfo(apiSet: apiSet, namespace: namespace)
}
var minAvailableMessageIdUpdated = false
transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in
@@ -658,6 +674,8 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
.withUpdatedMembersHidden(.known(PeerMembersHidden(value: membersHidden)))
.withUpdatedViewForumAsMessages(.known(forumViewAsMessages))
.withUpdatedWallpaper(wallpaper)
.withUpdatedBoostsUnrestrict(boostsUnrestrict)
.withUpdatedEmojiPack(emojiPack)
})
if let minAvailableMessageId = minAvailableMessageId, minAvailableMessageIdUpdated {

View File

@@ -40,3 +40,41 @@ func _internal_updateGroupSpecificStickerset(postbox: Postbox, network: Network,
return .complete()
}
}
public enum UpdateGroupSpecificEmojisetError {
case generic
}
func _internal_updateGroupSpecificEmojiset(postbox: Postbox, network: Network, peerId: PeerId, info: StickerPackCollectionInfo?) -> Signal<Void, UpdateGroupSpecificEmojisetError> {
return postbox.loadedPeerWithId(peerId)
|> castError(UpdateGroupSpecificEmojisetError.self)
|> mapToSignal { peer -> Signal<Void, UpdateGroupSpecificEmojisetError> in
let inputStickerset: Api.InputStickerSet
if let info = info {
inputStickerset = Api.InputStickerSet.inputStickerSetShortName(shortName: info.shortName)
} else {
inputStickerset = Api.InputStickerSet.inputStickerSetEmpty
}
if let inputChannel = apiInputChannel(peer) {
return network.request(Api.functions.channels.setEmojiStickers(channel: inputChannel, stickerset: inputStickerset))
|> mapError { _ -> UpdateGroupSpecificEmojisetError in
return .generic
}
|> mapToSignal { value -> Signal<Void, UpdateGroupSpecificEmojisetError> in
switch value {
case .boolTrue:
return postbox.transaction { transaction -> Void in
return transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current -> CachedPeerData? in
return (current as? CachedChannelData)?.withUpdatedEmojiPack(info)
})
}
|> castError(UpdateGroupSpecificEmojisetError.self)
default:
return .complete()
}
}
}
return .complete()
}
}

View File

@@ -639,6 +639,39 @@ func _internal_searchStickerSets(postbox: Postbox, query: String) -> Signal<Foun
} |> switchToLatest
}
func _internal_searchEmojiSets(postbox: Postbox, query: String) -> Signal<FoundStickerSets, NoError> {
return postbox.transaction { transaction -> Signal<FoundStickerSets, NoError> in
let infos = transaction.getItemCollectionsInfos(namespace: Namespaces.ItemCollection.CloudEmojiPacks)
var collections: [(ItemCollectionId, ItemCollectionInfo)] = []
var topItems: [ItemCollectionId: ItemCollectionItem] = [:]
var entries: [ItemCollectionViewEntry] = []
for info in infos {
if let info = info.1 as? StickerPackCollectionInfo {
let split = info.title.split(separator: " ")
if !split.filter({$0.lowercased().hasPrefix(query.lowercased())}).isEmpty || info.shortName.lowercased().hasPrefix(query.lowercased()) {
collections.append((info.id, info))
}
}
}
var index: Int32 = 0
for info in collections {
let items = transaction.getItemCollectionItems(collectionId: info.0)
let values = items.map({ ItemCollectionViewEntry(index: ItemCollectionViewEntryIndex(collectionIndex: index, collectionId: info.0, itemIndex: $0.index), item: $0) })
entries.append(contentsOf: values)
if let first = items.first {
topItems[info.0] = first
}
index += 1
}
let result = FoundStickerSets(infos: collections.map { ($0.0, $0.1, topItems[$0.0], true) }, entries: entries)
return .single(result)
} |> switchToLatest
}
func _internal_searchGifs(account: Account, query: String, nextOffset: String = "") -> Signal<ChatContextResultCollection?, NoError> {
return account.postbox.transaction { transaction -> String in
let configuration = currentSearchBotsConfiguration(transaction: transaction)

View File

@@ -45,6 +45,10 @@ public extension TelegramEngine {
public func searchStickerSets(query: String) -> Signal<FoundStickerSets, NoError> {
return _internal_searchStickerSets(postbox: self.account.postbox, query: query)
}
public func searchEmojiSets(query: String) -> Signal<FoundStickerSets, NoError> {
return _internal_searchEmojiSets(postbox: self.account.postbox, query: query)
}
public func searchGifs(query: String, nextOffset: String = "") -> Signal<ChatContextResultCollection?, NoError> {
return _internal_searchGifs(account: self.account, query: query, nextOffset: nextOffset)