Skip to content

Commit 0648ffb

Browse files
author
Isaac
committed
Fix default reaction privacy
1 parent e2ea61d commit 0648ffb

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

submodules/TelegramUI/Components/Chat/ChatSendStarsScreen/Sources/ChatSendStarsScreen.swift

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ private final class ChatSendStarsScreenComponent: Component {
822822
let context: AccountContext
823823
let peer: EnginePeer
824824
let myPeer: EnginePeer
825+
let defaultPrivacyPeer: ChatSendStarsScreenComponent.PrivacyPeer
825826
let channelsForPublicReaction: [EnginePeer]
826827
let messageId: EngineMessage.Id
827828
let maxAmount: Int
@@ -835,6 +836,7 @@ private final class ChatSendStarsScreenComponent: Component {
835836
context: AccountContext,
836837
peer: EnginePeer,
837838
myPeer: EnginePeer,
839+
defaultPrivacyPeer: ChatSendStarsScreenComponent.PrivacyPeer,
838840
channelsForPublicReaction: [EnginePeer],
839841
messageId: EngineMessage.Id,
840842
maxAmount: Int,
@@ -847,6 +849,7 @@ private final class ChatSendStarsScreenComponent: Component {
847849
self.context = context
848850
self.peer = peer
849851
self.myPeer = myPeer
852+
self.defaultPrivacyPeer = defaultPrivacyPeer
850853
self.channelsForPublicReaction = channelsForPublicReaction
851854
self.messageId = messageId
852855
self.maxAmount = maxAmount
@@ -985,7 +988,7 @@ private final class ChatSendStarsScreenComponent: Component {
985988
}
986989
}
987990

988-
private enum PrivacyPeer: Equatable {
991+
enum PrivacyPeer: Equatable {
989992
case account
990993
case anonymous
991994
case peer(EnginePeer)
@@ -1449,6 +1452,14 @@ private final class ChatSendStarsScreenComponent: Component {
14491452
} else {
14501453
self.privacyPeer = .account
14511454
}
1455+
} else {
1456+
self.privacyPeer = component.defaultPrivacyPeer
1457+
switch self.privacyPeer {
1458+
case .anonymous, .account:
1459+
break
1460+
case let .peer(peer):
1461+
self.currentMyPeer = peer
1462+
}
14521463
}
14531464

14541465
if let starsContext = component.context.starsContext {
@@ -2316,6 +2327,7 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
23162327
public final class InitialData {
23172328
fileprivate let peer: EnginePeer
23182329
fileprivate let myPeer: EnginePeer
2330+
fileprivate let defaultPrivacyPeer: ChatSendStarsScreenComponent.PrivacyPeer
23192331
fileprivate let channelsForPublicReaction: [EnginePeer]
23202332
fileprivate let messageId: EngineMessage.Id
23212333
fileprivate let balance: StarsAmount?
@@ -2326,6 +2338,7 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
23262338
fileprivate init(
23272339
peer: EnginePeer,
23282340
myPeer: EnginePeer,
2341+
defaultPrivacyPeer: ChatSendStarsScreenComponent.PrivacyPeer,
23292342
channelsForPublicReaction: [EnginePeer],
23302343
messageId: EngineMessage.Id,
23312344
balance: StarsAmount?,
@@ -2335,6 +2348,7 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
23352348
) {
23362349
self.peer = peer
23372350
self.myPeer = myPeer
2351+
self.defaultPrivacyPeer = defaultPrivacyPeer
23382352
self.channelsForPublicReaction = channelsForPublicReaction
23392353
self.messageId = messageId
23402354
self.balance = balance
@@ -2421,6 +2435,7 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
24212435
context: context,
24222436
peer: initialData.peer,
24232437
myPeer: initialData.myPeer,
2438+
defaultPrivacyPeer: initialData.defaultPrivacyPeer,
24242439
channelsForPublicReaction: initialData.channelsForPublicReaction,
24252440
messageId: initialData.messageId,
24262441
maxAmount: maxAmount,
@@ -2486,16 +2501,40 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
24862501

24872502
let channelsForPublicReaction = context.engine.peers.channelsForPublicReaction(useLocalCache: true)
24882503

2504+
let defaultPrivacyPeer: Signal<ChatSendStarsScreenComponent.PrivacyPeer, NoError> = context.engine.data.get(
2505+
TelegramEngine.EngineData.Item.Peer.StarsReactionDefaultPrivacy()
2506+
)
2507+
|> mapToSignal { defaultPrivacy -> Signal<ChatSendStarsScreenComponent.PrivacyPeer, NoError> in
2508+
switch defaultPrivacy {
2509+
case .anonymous:
2510+
return .single(.anonymous)
2511+
case .default:
2512+
return .single(.account)
2513+
case let .peer(peerId):
2514+
return context.engine.data.get(
2515+
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
2516+
)
2517+
|> map { peer -> ChatSendStarsScreenComponent.PrivacyPeer in
2518+
if let peer {
2519+
return .peer(peer)
2520+
} else {
2521+
return .anonymous
2522+
}
2523+
}
2524+
}
2525+
}
2526+
24892527
return combineLatest(
24902528
context.engine.data.get(
24912529
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId),
24922530
TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId),
24932531
EngineDataMap(allPeerIds.map(TelegramEngine.EngineData.Item.Peer.Peer.init(id:)))
24942532
),
24952533
balance,
2496-
channelsForPublicReaction
2534+
channelsForPublicReaction,
2535+
defaultPrivacyPeer
24972536
)
2498-
|> map { peerAndTopPeerMap, balance, channelsForPublicReaction -> InitialData? in
2537+
|> map { peerAndTopPeerMap, balance, channelsForPublicReaction, defaultPrivacyPeer -> InitialData? in
24992538
let (peer, myPeer, topPeerMap) = peerAndTopPeerMap
25002539
guard let peer, let myPeer else {
25012540
return nil
@@ -2505,6 +2544,7 @@ public class ChatSendStarsScreen: ViewControllerComponentContainer {
25052544
return InitialData(
25062545
peer: peer,
25072546
myPeer: myPeer,
2547+
defaultPrivacyPeer: defaultPrivacyPeer,
25082548
channelsForPublicReaction: channelsForPublicReaction,
25092549
messageId: messageId,
25102550
balance: balance,

0 commit comments

Comments
 (0)