mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Store default stars reaction anonymity globally
This commit is contained in:
parent
4ceb3ac58b
commit
2086a5696c
@ -182,7 +182,7 @@ public func sendStarsReactionsInteractively(account: Account, messageId: Message
|
||||
}
|
||||
var mappedCount = Int32(count)
|
||||
var attributes = currentMessage.attributes
|
||||
var resolvedIsAnonymous = false
|
||||
var resolvedIsAnonymous = _internal_getStarsReactionDefaultToPrivate(peerId: messageId.peerId, transaction: transaction)
|
||||
for attribute in attributes {
|
||||
if let attribute = attribute as? ReactionsMessageAttribute {
|
||||
if let myReaction = attribute.topPeers.first(where: { $0.isMy }) {
|
||||
@ -201,6 +201,7 @@ public func sendStarsReactionsInteractively(account: Account, messageId: Message
|
||||
|
||||
if let isAnonymous {
|
||||
resolvedIsAnonymous = isAnonymous
|
||||
_internal_setStarsReactionDefaultToPrivate(peerId: messageId.peerId, isPrivate: isAnonymous, transaction: transaction)
|
||||
}
|
||||
|
||||
attributes.append(PendingStarsReactionsMessageAttribute(accountPeerId: account.peerId, count: mappedCount, isAnonymous: resolvedIsAnonymous))
|
||||
@ -241,6 +242,8 @@ func _internal_forceSendPendingSendStarsReaction(account: Account, messageId: Me
|
||||
|
||||
func _internal_updateStarsReactionIsAnonymous(account: Account, messageId: MessageId, isAnonymous: Bool) -> Signal<Never, NoError> {
|
||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
_internal_setStarsReactionDefaultToPrivate(peerId: messageId.peerId, isPrivate: isAnonymous, transaction: transaction)
|
||||
|
||||
transaction.updateMessage(messageId, update: { currentMessage in
|
||||
var storeForwardInfo: StoreMessageForwardInfo?
|
||||
if let forwardInfo = currentMessage.forwardInfo {
|
||||
@ -1024,3 +1027,31 @@ func _internal_updateDefaultReaction(account: Account, reaction: MessageReaction
|
||||
}
|
||||
|> ignoreValues
|
||||
}
|
||||
|
||||
struct StarsReactionDefaultToPrivateData: Codable {
|
||||
var isPrivate: Bool
|
||||
|
||||
init(isPrivate: Bool) {
|
||||
self.isPrivate = isPrivate
|
||||
}
|
||||
|
||||
static func key(peerId: PeerId) -> ValueBoxKey {
|
||||
let value = ValueBoxKey(length: 8)
|
||||
value.setInt64(0, value: peerId.toInt64())
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_getStarsReactionDefaultToPrivate(peerId: PeerId, transaction: Transaction) -> Bool {
|
||||
guard let value = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.starsReactionDefaultToPrivate, key: StarsReactionDefaultToPrivateData.key(peerId: peerId)))?.get(StarsReactionDefaultToPrivateData.self) else {
|
||||
return false
|
||||
}
|
||||
return value.isPrivate
|
||||
}
|
||||
|
||||
func _internal_setStarsReactionDefaultToPrivate(peerId: PeerId, isPrivate: Bool, transaction: Transaction) {
|
||||
guard let entry = CodableEntry(StarsReactionDefaultToPrivateData(isPrivate: isPrivate)) else {
|
||||
return
|
||||
}
|
||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.starsReactionDefaultToPrivate, key: StarsReactionDefaultToPrivateData.key(peerId: peerId)), entry: entry)
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ public struct Namespaces {
|
||||
public static let cachedStarsRevenueStats: Int8 = 38
|
||||
public static let cachedRevenueStats: Int8 = 39
|
||||
public static let recommendedApps: Int8 = 40
|
||||
public static let starsReactionDefaultToPrivate: Int8 = 41
|
||||
}
|
||||
|
||||
public struct UnorderedItemList {
|
||||
|
@ -2159,5 +2159,30 @@ public extension TelegramEngine.EngineData.Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct StarsReactionDefaultToPrivate: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Bool
|
||||
|
||||
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 .cachedItem(ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.starsReactionDefaultToPrivate, key: StarsReactionDefaultToPrivateData.key(peerId: self.id)))
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
if let value = (view as? CachedItemView)?.value?.get(StarsReactionDefaultToPrivateData.self) {
|
||||
return value.isPrivate
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1622,6 +1622,12 @@ public extension TelegramEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func setStarsReactionDefaultToPrivate(peerId: EnginePeer.Id, isPrivate: Bool) {
|
||||
let _ = self.account.postbox.transaction({ transaction in
|
||||
_internal_setStarsReactionDefaultToPrivate(peerId: peerId, isPrivate: isPrivate, transaction: transaction)
|
||||
}).startStandalone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user