PeerContactSettings -> PeerStatusSettings

This commit is contained in:
overtake 2019-06-07 12:13:36 +02:00
parent 242ad146b0
commit b02faa87fe
9 changed files with 137 additions and 137 deletions

View File

@ -1159,7 +1159,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
} }
}) })
case let .updatePeerSettings(peer, settings): case let .updatePeerSettings(peer, settings):
let peerContactSettings = PeerContactSettings(apiSettings: settings) let peerStatusSettings = PeerStatusSettings(apiSettings: settings)
updatedState.updateCachedPeerData(peer.peerId, { current in updatedState.updateCachedPeerData(peer.peerId, { current in
if peer.peerId.namespace == Namespaces.Peer.CloudUser { if peer.peerId.namespace == Namespaces.Peer.CloudUser {
let previous: CachedUserData let previous: CachedUserData
@ -1168,7 +1168,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
} else { } else {
previous = CachedUserData() previous = CachedUserData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if peer.peerId.namespace == Namespaces.Peer.CloudGroup { } else if peer.peerId.namespace == Namespaces.Peer.CloudGroup {
let previous: CachedGroupData let previous: CachedGroupData
if let current = current as? CachedGroupData { if let current = current as? CachedGroupData {
@ -1176,7 +1176,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
} else { } else {
previous = CachedGroupData() previous = CachedGroupData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if peer.peerId.namespace == Namespaces.Peer.CloudChannel { } else if peer.peerId.namespace == Namespaces.Peer.CloudChannel {
let previous: CachedChannelData let previous: CachedChannelData
if let current = current as? CachedChannelData { if let current = current as? CachedChannelData {
@ -1184,7 +1184,7 @@ private func finalStateWithUpdatesAndServerTime(postbox: Postbox, network: Netwo
} else { } else {
previous = CachedChannelData() previous = CachedChannelData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return current return current
} }

View File

@ -132,7 +132,7 @@ public final class CachedChannelData: CachedPeerData {
public let participantsSummary: CachedChannelParticipantsSummary public let participantsSummary: CachedChannelParticipantsSummary
public let exportedInvitation: ExportedInvitation? public let exportedInvitation: ExportedInvitation?
public let botInfos: [CachedPeerBotInfo] public let botInfos: [CachedPeerBotInfo]
public let peerContactSettings: PeerContactSettings? public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId? public let pinnedMessageId: MessageId?
public let stickerPack: StickerPackCollectionInfo? public let stickerPack: StickerPackCollectionInfo?
public let minAvailableMessageId: MessageId? public let minAvailableMessageId: MessageId?
@ -153,7 +153,7 @@ public final class CachedChannelData: CachedPeerData {
self.participantsSummary = CachedChannelParticipantsSummary(memberCount: nil, adminCount: nil, bannedCount: nil, kickedCount: nil) self.participantsSummary = CachedChannelParticipantsSummary(memberCount: nil, adminCount: nil, bannedCount: nil, kickedCount: nil)
self.exportedInvitation = nil self.exportedInvitation = nil
self.botInfos = [] self.botInfos = []
self.peerContactSettings = nil self.peerStatusSettings = nil
self.pinnedMessageId = nil self.pinnedMessageId = nil
self.peerIds = Set() self.peerIds = Set()
self.messageIds = Set() self.messageIds = Set()
@ -163,14 +163,14 @@ public final class CachedChannelData: CachedPeerData {
self.linkedDiscussionPeerId = nil self.linkedDiscussionPeerId = nil
} }
init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerContactSettings: PeerContactSettings?, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, linkedDiscussionPeerId: PeerId?) { init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, linkedDiscussionPeerId: PeerId?) {
self.isNotAccessible = isNotAccessible self.isNotAccessible = isNotAccessible
self.flags = flags self.flags = flags
self.about = about self.about = about
self.participantsSummary = participantsSummary self.participantsSummary = participantsSummary
self.exportedInvitation = exportedInvitation self.exportedInvitation = exportedInvitation
self.botInfos = botInfos self.botInfos = botInfos
self.peerContactSettings = peerContactSettings self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId self.pinnedMessageId = pinnedMessageId
self.stickerPack = stickerPack self.stickerPack = stickerPack
self.minAvailableMessageId = minAvailableMessageId self.minAvailableMessageId = minAvailableMessageId
@ -196,51 +196,51 @@ public final class CachedChannelData: CachedPeerData {
} }
func withUpdatedIsNotAccessible(_ isNotAccessible: Bool) -> CachedChannelData { func withUpdatedIsNotAccessible(_ isNotAccessible: Bool) -> CachedChannelData {
return CachedChannelData(isNotAccessible: isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedFlags(_ flags: CachedChannelFlags) -> CachedChannelData { func withUpdatedFlags(_ flags: CachedChannelFlags) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedAbout(_ about: String?) -> CachedChannelData { func withUpdatedAbout(_ about: String?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedParticipantsSummary(_ participantsSummary: CachedChannelParticipantsSummary) -> CachedChannelData { func withUpdatedParticipantsSummary(_ participantsSummary: CachedChannelParticipantsSummary) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedChannelData { func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedChannelData { func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedPeerContactSettings(_ peerContactSettings: PeerContactSettings?) -> CachedChannelData { func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedChannelData { func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedStickerPack(_ stickerPack: StickerPackCollectionInfo?) -> CachedChannelData { func withUpdatedStickerPack(_ stickerPack: StickerPackCollectionInfo?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedMinAvailableMessageId(_ minAvailableMessageId: MessageId?) -> CachedChannelData { func withUpdatedMinAvailableMessageId(_ minAvailableMessageId: MessageId?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedMigrationReference(_ migrationReference: ChannelMigrationReference?) -> CachedChannelData { func withUpdatedMigrationReference(_ migrationReference: ChannelMigrationReference?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
} }
func withUpdatedLinkedDiscussionPeerId(_ linkedDiscussionPeerId: PeerId?) -> CachedChannelData { func withUpdatedLinkedDiscussionPeerId(_ linkedDiscussionPeerId: PeerId?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: linkedDiscussionPeerId) return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: linkedDiscussionPeerId)
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
@ -252,9 +252,9 @@ public final class CachedChannelData: CachedPeerData {
self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo] self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo]
var peerIds = Set<PeerId>() var peerIds = Set<PeerId>()
if let value = decoder.decodeOptionalInt32ForKey("pcs") { if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value) self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} else { } else {
self.peerContactSettings = nil self.peerStatusSettings = nil
} }
if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") { if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId) self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -314,8 +314,8 @@ public final class CachedChannelData: CachedPeerData {
encoder.encodeNil(forKey: "i") encoder.encodeNil(forKey: "i")
} }
encoder.encodeObjectArray(self.botInfos, forKey: "b") encoder.encodeObjectArray(self.botInfos, forKey: "b")
if let peerContactSettings = self.peerContactSettings { if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs") encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else { } else {
encoder.encodeNil(forKey: "pcs") encoder.encodeNil(forKey: "pcs")
} }
@ -387,7 +387,7 @@ public final class CachedChannelData: CachedPeerData {
return false return false
} }
if other.peerContactSettings != self.peerContactSettings { if other.peerStatusSettings != self.peerStatusSettings {
return false return false
} }

View File

@ -47,7 +47,7 @@ public final class CachedGroupData: CachedPeerData {
public let participants: CachedGroupParticipants? public let participants: CachedGroupParticipants?
public let exportedInvitation: ExportedInvitation? public let exportedInvitation: ExportedInvitation?
public let botInfos: [CachedPeerBotInfo] public let botInfos: [CachedPeerBotInfo]
public let peerContactSettings: PeerContactSettings? public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId? public let pinnedMessageId: MessageId?
public let about: String? public let about: String?
public let flags: CachedGroupFlags public let flags: CachedGroupFlags
@ -60,7 +60,7 @@ public final class CachedGroupData: CachedPeerData {
self.participants = nil self.participants = nil
self.exportedInvitation = nil self.exportedInvitation = nil
self.botInfos = [] self.botInfos = []
self.peerContactSettings = nil self.peerStatusSettings = nil
self.pinnedMessageId = nil self.pinnedMessageId = nil
self.messageIds = Set() self.messageIds = Set()
self.peerIds = Set() self.peerIds = Set()
@ -68,11 +68,11 @@ public final class CachedGroupData: CachedPeerData {
self.flags = CachedGroupFlags() self.flags = CachedGroupFlags()
} }
public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerContactSettings: PeerContactSettings?, pinnedMessageId: MessageId?, about: String?, flags: CachedGroupFlags) { public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, about: String?, flags: CachedGroupFlags) {
self.participants = participants self.participants = participants
self.exportedInvitation = exportedInvitation self.exportedInvitation = exportedInvitation
self.botInfos = botInfos self.botInfos = botInfos
self.peerContactSettings = peerContactSettings self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId self.pinnedMessageId = pinnedMessageId
self.about = about self.about = about
self.flags = flags self.flags = flags
@ -101,9 +101,9 @@ public final class CachedGroupData: CachedPeerData {
self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation
self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo] self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo]
if let value = decoder.decodeOptionalInt32ForKey("pcs") { if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value) self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} else { } else {
self.peerContactSettings = nil self.peerStatusSettings = nil
} }
if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") { if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId) self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -144,8 +144,8 @@ public final class CachedGroupData: CachedPeerData {
encoder.encodeNil(forKey: "i") encoder.encodeNil(forKey: "i")
} }
encoder.encodeObjectArray(self.botInfos, forKey: "b") encoder.encodeObjectArray(self.botInfos, forKey: "b")
if let peerContactSettings = self.peerContactSettings { if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs") encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else { } else {
encoder.encodeNil(forKey: "pcs") encoder.encodeNil(forKey: "pcs")
} }
@ -171,34 +171,34 @@ public final class CachedGroupData: CachedPeerData {
return false return false
} }
return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.peerContactSettings == other.peerContactSettings && self.pinnedMessageId == other.pinnedMessageId && self.about == other.about && self.flags == other.flags return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.peerStatusSettings == other.peerStatusSettings && self.pinnedMessageId == other.pinnedMessageId && self.about == other.about && self.flags == other.flags
} }
func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData { func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData {
return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags) return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags)
} }
func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData { func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags) return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags)
} }
func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData { func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags) return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags)
} }
func withUpdatedPeerContactSettings(_ peerContactSettings: PeerContactSettings?) -> CachedGroupData { func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags) return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags)
} }
func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData { func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: pinnedMessageId, about: self.about, flags: self.flags) return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, about: self.about, flags: self.flags)
} }
func withUpdatedAbout(_ about: String?) -> CachedGroupData { func withUpdatedAbout(_ about: String?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: about, flags: self.flags) return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: about, flags: self.flags)
} }
func withUpdatedFlags(_ flags: CachedGroupFlags) -> CachedGroupData { func withUpdatedFlags(_ flags: CachedGroupFlags) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: flags) return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: flags)
} }
} }

View File

@ -8,7 +8,7 @@ import Foundation
public final class CachedUserData: CachedPeerData { public final class CachedUserData: CachedPeerData {
public let about: String? public let about: String?
public let botInfo: BotInfo? public let botInfo: BotInfo?
public let peerContactSettings: PeerContactSettings? public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId? public let pinnedMessageId: MessageId?
public let isBlocked: Bool public let isBlocked: Bool
public let commonGroupCount: Int32 public let commonGroupCount: Int32
@ -23,7 +23,7 @@ public final class CachedUserData: CachedPeerData {
init() { init() {
self.about = nil self.about = nil
self.botInfo = nil self.botInfo = nil
self.peerContactSettings = nil self.peerStatusSettings = nil
self.pinnedMessageId = nil self.pinnedMessageId = nil
self.isBlocked = false self.isBlocked = false
self.commonGroupCount = 0 self.commonGroupCount = 0
@ -33,10 +33,10 @@ public final class CachedUserData: CachedPeerData {
self.messageIds = Set() self.messageIds = Set()
} }
init(about: String?, botInfo: BotInfo?, peerContactSettings: PeerContactSettings?, pinnedMessageId: MessageId?, isBlocked: Bool, commonGroupCount: Int32, callsAvailable: Bool, callsPrivate: Bool, canPinMessages: Bool) { init(about: String?, botInfo: BotInfo?, peerStatusSettings: PeerStatusSettings?, pinnedMessageId: MessageId?, isBlocked: Bool, commonGroupCount: Int32, callsAvailable: Bool, callsPrivate: Bool, canPinMessages: Bool) {
self.about = about self.about = about
self.botInfo = botInfo self.botInfo = botInfo
self.peerContactSettings = peerContactSettings self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId self.pinnedMessageId = pinnedMessageId
self.isBlocked = isBlocked self.isBlocked = isBlocked
self.commonGroupCount = commonGroupCount self.commonGroupCount = commonGroupCount
@ -54,9 +54,9 @@ public final class CachedUserData: CachedPeerData {
self.about = decoder.decodeOptionalStringForKey("a") self.about = decoder.decodeOptionalStringForKey("a")
self.botInfo = decoder.decodeObjectForKey("bi") as? BotInfo self.botInfo = decoder.decodeObjectForKey("bi") as? BotInfo
if let value = decoder.decodeOptionalInt32ForKey("pcs") { if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value) self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} else { } else {
self.peerContactSettings = nil self.peerStatusSettings = nil
} }
if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") { if let pinnedMessagePeerId = decoder.decodeOptionalInt64ForKey("pm.p"), let pinnedMessageNamespace = decoder.decodeOptionalInt32ForKey("pm.n"), let pinnedMessageId = decoder.decodeOptionalInt32ForKey("pm.i") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId) self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -87,8 +87,8 @@ public final class CachedUserData: CachedPeerData {
} else { } else {
encoder.encodeNil(forKey: "bi") encoder.encodeNil(forKey: "bi")
} }
if let peerContactSettings = self.peerContactSettings { if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs") encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else { } else {
encoder.encodeNil(forKey: "pcs") encoder.encodeNil(forKey: "pcs")
} }
@ -120,42 +120,42 @@ public final class CachedUserData: CachedPeerData {
return false return false
} }
return other.about == self.about && other.botInfo == self.botInfo && self.peerContactSettings == other.peerContactSettings && self.isBlocked == other.isBlocked && self.commonGroupCount == other.commonGroupCount && self.callsAvailable == other.callsAvailable && self.callsPrivate == other.callsPrivate return other.about == self.about && other.botInfo == self.botInfo && self.peerStatusSettings == other.peerStatusSettings && self.isBlocked == other.isBlocked && self.commonGroupCount == other.commonGroupCount && self.callsAvailable == other.callsAvailable && self.callsPrivate == other.callsPrivate
} }
func withUpdatedAbout(_ about: String?) -> CachedUserData { func withUpdatedAbout(_ about: String?) -> CachedUserData {
return CachedUserData(about: about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedBotInfo(_ botInfo: BotInfo?) -> CachedUserData { func withUpdatedBotInfo(_ botInfo: BotInfo?) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedPeerContactSettings(_ peerContactSettings: PeerContactSettings) -> CachedUserData { func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedUserData { func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedIsBlocked(_ isBlocked: Bool) -> CachedUserData { func withUpdatedIsBlocked(_ isBlocked: Bool) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedCommonGroupCount(_ commonGroupCount: Int32) -> CachedUserData { func withUpdatedCommonGroupCount(_ commonGroupCount: Int32) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedCallsAvailable(_ callsAvailable: Bool) -> CachedUserData { func withUpdatedCallsAvailable(_ callsAvailable: Bool) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedCallsPrivate(_ callsPrivate: Bool) -> CachedUserData { func withUpdatedCallsPrivate(_ callsPrivate: Bool) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: callsPrivate, canPinMessages: self.canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: callsPrivate, canPinMessages: self.canPinMessages)
} }
func withUpdatedCanPinMessages(_ canPinMessages: Bool) -> CachedUserData { func withUpdatedCanPinMessages(_ canPinMessages: Bool) -> CachedUserData {
return CachedUserData(about: self.about, botInfo: self.botInfo, peerContactSettings: self.peerContactSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: canPinMessages) return CachedUserData(about: self.about, botInfo: self.botInfo, peerStatusSettings: self.peerStatusSettings, pinnedMessageId: self.pinnedMessageId, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate, canPinMessages: canPinMessages)
} }
} }

View File

@ -1380,9 +1380,9 @@ private func requestTerminateSecretChat(postbox: Postbox, network: Network, peer
if result != nil { if result != nil {
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedSecretChatData { if let current = current as? CachedSecretChatData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return current return current
} }

View File

@ -5,23 +5,23 @@ import Foundation
import Postbox import Postbox
#endif #endif
public struct PeerContactSettings: OptionSet { public struct PeerStatusSettings: OptionSet {
public var rawValue: Int32 public var rawValue: Int32
public init(rawValue: Int32) { public init(rawValue: Int32) {
self.rawValue = rawValue self.rawValue = rawValue
} }
public static let isHidden = PeerContactSettings(rawValue: 1 << 0) public static let isHidden = PeerStatusSettings(rawValue: 1 << 0)
public static let canReport = PeerContactSettings(rawValue: 1 << 1) public static let canReport = PeerStatusSettings(rawValue: 1 << 1)
public static let canShareContact = PeerContactSettings(rawValue: 1 << 2) public static let canShareContact = PeerStatusSettings(rawValue: 1 << 2)
} }
extension PeerContactSettings { extension PeerStatusSettings {
init(apiSettings: Api.PeerSettings) { init(apiSettings: Api.PeerSettings) {
switch apiSettings { switch apiSettings {
case let .peerSettings(flags): case let .peerSettings(flags):
var result = PeerContactSettings() var result = PeerStatusSettings()
if (flags & (1 << 1)) != 0 { if (flags & (1 << 1)) != 0 {
result.insert(.isHidden) result.insert(.isHidden)
} }

View File

@ -27,20 +27,20 @@ public func reportPeer(account: Account, peerId: PeerId) -> Signal<Void, NoError
if result != nil { if result != nil {
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedUserData { if let current = current as? CachedUserData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedGroupData { } else if let current = current as? CachedGroupData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedChannelData { } else if let current = current as? CachedChannelData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return current return current
} }
@ -59,20 +59,20 @@ public func reportPeer(account: Account, peerId: PeerId) -> Signal<Void, NoError
if result != nil { if result != nil {
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedUserData { if let current = current as? CachedUserData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedGroupData { } else if let current = current as? CachedGroupData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedChannelData { } else if let current = current as? CachedChannelData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.remove(.canReport) peerStatusSettings.remove(.canReport)
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return current return current
} }
@ -172,25 +172,25 @@ public func reportSupergroupPeer(account: Account, peerId: PeerId, memberId: Pee
} |> switchToLatest } |> switchToLatest
} }
public func dismissPeerContactOptions(account: Account, peerId: PeerId) -> Signal<Void, NoError> { public func dismissPeerStatusOptions(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
return account.postbox.transaction { transaction -> Signal<Void, NoError> in return account.postbox.transaction { transaction -> Signal<Void, NoError> in
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedUserData { if let current = current as? CachedUserData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedGroupData { } else if let current = current as? CachedGroupData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedChannelData { } else if let current = current as? CachedChannelData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else if let current = current as? CachedSecretChatData { } else if let current = current as? CachedSecretChatData {
var peerContactSettings = current.peerContactSettings ?? PeerContactSettings() var peerStatusSettings = current.peerStatusSettings ?? PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return current return current
} }

View File

@ -81,23 +81,23 @@ public final class CachedSecretChatData: CachedPeerData {
public let messageIds: Set<MessageId> = Set() public let messageIds: Set<MessageId> = Set()
public let associatedHistoryMessageId: MessageId? = nil public let associatedHistoryMessageId: MessageId? = nil
public let peerContactSettings: PeerContactSettings? public let peerStatusSettings: PeerStatusSettings?
public init(peerContactSettings: PeerContactSettings?) { public init(peerStatusSettings: PeerStatusSettings?) {
self.peerContactSettings = peerContactSettings self.peerStatusSettings = peerStatusSettings
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
if let value = decoder.decodeOptionalInt32ForKey("pcs") { if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value) self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} else { } else {
self.peerContactSettings = nil self.peerStatusSettings = nil
} }
} }
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
if let peerContactSettings = self.peerContactSettings { if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs") encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else { } else {
encoder.encodeNil(forKey: "pcs") encoder.encodeNil(forKey: "pcs")
} }
@ -105,13 +105,13 @@ public final class CachedSecretChatData: CachedPeerData {
public func isEqual(to: CachedPeerData) -> Bool { public func isEqual(to: CachedPeerData) -> Bool {
if let to = to as? CachedSecretChatData { if let to = to as? CachedSecretChatData {
return self.peerContactSettings == to.peerContactSettings return self.peerStatusSettings == to.peerStatusSettings
} else { } else {
return false return false
} }
} }
func withUpdatedPeerContactSettings(_ peerContactSettings: PeerContactSettings) -> CachedSecretChatData { func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedSecretChatData {
return CachedSecretChatData(peerContactSettings: peerContactSettings) return CachedSecretChatData(peerStatusSettings: peerStatusSettings)
} }
} }

View File

@ -13,44 +13,44 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
let cachedData = transaction.getPeerCachedData(peerId: peerId) let cachedData = transaction.getPeerCachedData(peerId: peerId)
if let cachedData = cachedData as? CachedUserData { if let cachedData = cachedData as? CachedUserData {
if cachedData.peerContactSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .complete()
} }
} else if let cachedData = cachedData as? CachedGroupData { } else if let cachedData = cachedData as? CachedGroupData {
if cachedData.peerContactSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .complete()
} }
} else if let cachedData = cachedData as? CachedChannelData { } else if let cachedData = cachedData as? CachedChannelData {
if cachedData.peerContactSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .complete()
} }
} else if let cachedData = cachedData as? CachedSecretChatData { } else if let cachedData = cachedData as? CachedSecretChatData {
if cachedData.peerContactSettings != nil { if cachedData.peerStatusSettings != nil {
return .complete() return .complete()
} }
} }
if peerId.namespace == Namespaces.Peer.SecretChat { if peerId.namespace == Namespaces.Peer.SecretChat {
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Void in
var peerContactSettings: PeerContactSettings var peerStatusSettings: PeerStatusSettings
if let peer = transaction.getPeer(peerId), let associatedPeerId = peer.associatedPeerId, !transaction.isPeerContact(peerId: associatedPeerId) { if let peer = transaction.getPeer(peerId), let associatedPeerId = peer.associatedPeerId, !transaction.isPeerContact(peerId: associatedPeerId) {
if let peer = peer as? TelegramSecretChat, case .creator = peer.role { if let peer = peer as? TelegramSecretChat, case .creator = peer.role {
peerContactSettings = PeerContactSettings() peerStatusSettings = PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
} else { } else {
peerContactSettings = PeerContactSettings() peerStatusSettings = PeerStatusSettings()
peerContactSettings.insert(.canReport) peerStatusSettings.insert(.canReport)
} }
} else { } else {
peerContactSettings = PeerContactSettings() peerStatusSettings = PeerStatusSettings()
peerContactSettings.insert(.isHidden) peerStatusSettings.insert(.isHidden)
} }
transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in
if let current = current as? CachedSecretChatData { if let current = current as? CachedSecretChatData {
return current.withUpdatedPeerContactSettings(peerContactSettings) return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} else { } else {
return CachedSecretChatData(peerContactSettings: peerContactSettings) return CachedSecretChatData(peerStatusSettings: peerStatusSettings)
} }
}) })
} }
@ -58,7 +58,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer)) return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer))
|> retryRequest |> retryRequest
|> mapToSignal { peerSettings -> Signal<Void, NoError> in |> mapToSignal { peerSettings -> Signal<Void, NoError> in
let peerContactSettings = PeerContactSettings(apiSettings: peerSettings) let peerStatusSettings = PeerStatusSettings(apiSettings: peerSettings)
return postbox.transaction { transaction -> Void in return postbox.transaction { transaction -> Void in
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
@ -70,7 +70,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else { } else {
previous = CachedUserData() previous = CachedUserData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
case Namespaces.Peer.CloudGroup: case Namespaces.Peer.CloudGroup:
let previous: CachedGroupData let previous: CachedGroupData
if let current = current as? CachedGroupData { if let current = current as? CachedGroupData {
@ -78,7 +78,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else { } else {
previous = CachedGroupData() previous = CachedGroupData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
case Namespaces.Peer.CloudChannel: case Namespaces.Peer.CloudChannel:
let previous: CachedChannelData let previous: CachedChannelData
if let current = current as? CachedChannelData { if let current = current as? CachedChannelData {
@ -86,7 +86,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else { } else {
previous = CachedChannelData() previous = CachedChannelData()
} }
return previous.withUpdatedPeerContactSettings(peerContactSettings) return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
default: default:
break break
} }
@ -138,9 +138,9 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
let canPinMessages = (userFull.flags & (1 << 7)) != 0 let canPinMessages = (userFull.flags & (1 << 7)) != 0
let pinnedMessageId = userFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) }) let pinnedMessageId = userFull.pinnedMsgId.flatMap({ MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: $0) })
let peerContactSettings = PeerContactSettings(apiSettings: userFull.settings) let peerStatusSettings = PeerStatusSettings(apiSettings: userFull.settings)
return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerContactSettings(peerContactSettings).withUpdatedPinnedMessageId(pinnedMessageId) return previous.withUpdatedAbout(userFull.about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(userFull.commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate).withUpdatedCanPinMessages(canPinMessages).withUpdatedPeerStatusSettings(peerStatusSettings).withUpdatedPinnedMessageId(pinnedMessageId)
} }
}) })
} }