Merge commit 'a6e66d7e74c6fef84cba9da834cb24e13ba63bfb'

This commit is contained in:
Peter 2019-06-07 14:01:02 +01:00
commit 097b0f7175
12 changed files with 226 additions and 138 deletions

View File

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
0900555621E4A96E0030924C /* Wallpaper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0900555521E4A96D0030924C /* Wallpaper.swift */; };
09028386218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09028385218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift */; };
090E778322A9862100CD99F5 /* ChannelOwnershipTransfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090E778222A9862100CD99F5 /* ChannelOwnershipTransfer.swift */; };
093857A82243D87900EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857A62243D87800EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift */; };
093857A92243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857A72243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift */; };
093857AB2243D88D00EB6A54 /* EmojiKeywords.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857AA2243D88C00EB6A54 /* EmojiKeywords.swift */; };
@ -829,6 +830,7 @@
/* Begin PBXFileReference section */
0900555521E4A96D0030924C /* Wallpaper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Wallpaper.swift; sourceTree = "<group>"; };
09028385218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedVoipConfigurationUpdates.swift; sourceTree = "<group>"; };
090E778222A9862100CD99F5 /* ChannelOwnershipTransfer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelOwnershipTransfer.swift; sourceTree = "<group>"; };
093857A62243D87800EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedSynchronizeEmojiKeywordsOperations.swift; sourceTree = "<group>"; };
093857A72243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizeEmojiKeywordsOperation.swift; sourceTree = "<group>"; };
093857AA2243D88C00EB6A54 /* EmojiKeywords.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmojiKeywords.swift; sourceTree = "<group>"; };
@ -2004,6 +2006,7 @@
D0633CD12253A528003DD95F /* ChatOnlineMembers.swift */,
D015E00D225CA61100CB9E8A /* FindChannelById.swift */,
D076F8882296D8E9004F895A /* ManageChannelDiscussionGroup.swift */,
090E778222A9862100CD99F5 /* ChannelOwnershipTransfer.swift */,
);
name = Peers;
sourceTree = "<group>";
@ -2171,6 +2174,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = D09D8BF71D4FAB1D0081DBEC;
@ -2234,6 +2238,7 @@
D00D34451E6EDD420057B307 /* SynchronizeConsumeMessageContentsOperation.swift in Sources */,
D02D60AB206BA64100FEFE1E /* VerifySecureIdValue.swift in Sources */,
D00D343F1E6ED6E50057B307 /* ConsumableContentMessageAttribute.swift in Sources */,
090E778322A9862100CD99F5 /* ChannelOwnershipTransfer.swift in Sources */,
D03B0CE01D62249100955575 /* StoreMessage_Telegram.swift in Sources */,
D08774FE1E3E3A3500A97350 /* GlobalNotificationSettings.swift in Sources */,
D023E67821540624008C27D1 /* UpdateMessageMedia.swift in Sources */,

View File

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

View File

@ -132,7 +132,7 @@ public final class CachedChannelData: CachedPeerData {
public let participantsSummary: CachedChannelParticipantsSummary
public let exportedInvitation: ExportedInvitation?
public let botInfos: [CachedPeerBotInfo]
public let peerContactSettings: PeerContactSettings?
public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId?
public let stickerPack: StickerPackCollectionInfo?
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.exportedInvitation = nil
self.botInfos = []
self.peerContactSettings = nil
self.peerStatusSettings = nil
self.pinnedMessageId = nil
self.peerIds = Set()
self.messageIds = Set()
@ -163,14 +163,14 @@ public final class CachedChannelData: CachedPeerData {
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.flags = flags
self.about = about
self.participantsSummary = participantsSummary
self.exportedInvitation = exportedInvitation
self.botInfos = botInfos
self.peerContactSettings = peerContactSettings
self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId
self.stickerPack = stickerPack
self.minAvailableMessageId = minAvailableMessageId
@ -196,51 +196,51 @@ public final class CachedChannelData: CachedPeerData {
}
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 {
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 {
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 {
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 {
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 {
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 {
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)
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, peerStatusSettings: peerStatusSettings, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
}
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 {
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 {
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 {
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 {
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) {
@ -252,9 +252,9 @@ public final class CachedChannelData: CachedPeerData {
self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo]
var peerIds = Set<PeerId>()
if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value)
self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} 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") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -314,8 +314,8 @@ public final class CachedChannelData: CachedPeerData {
encoder.encodeNil(forKey: "i")
}
encoder.encodeObjectArray(self.botInfos, forKey: "b")
if let peerContactSettings = self.peerContactSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs")
if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else {
encoder.encodeNil(forKey: "pcs")
}
@ -387,7 +387,7 @@ public final class CachedChannelData: CachedPeerData {
return false
}
if other.peerContactSettings != self.peerContactSettings {
if other.peerStatusSettings != self.peerStatusSettings {
return false
}

View File

@ -47,7 +47,7 @@ public final class CachedGroupData: CachedPeerData {
public let participants: CachedGroupParticipants?
public let exportedInvitation: ExportedInvitation?
public let botInfos: [CachedPeerBotInfo]
public let peerContactSettings: PeerContactSettings?
public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId?
public let about: String?
public let flags: CachedGroupFlags
@ -60,7 +60,7 @@ public final class CachedGroupData: CachedPeerData {
self.participants = nil
self.exportedInvitation = nil
self.botInfos = []
self.peerContactSettings = nil
self.peerStatusSettings = nil
self.pinnedMessageId = nil
self.messageIds = Set()
self.peerIds = Set()
@ -68,11 +68,11 @@ public final class CachedGroupData: CachedPeerData {
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.exportedInvitation = exportedInvitation
self.botInfos = botInfos
self.peerContactSettings = peerContactSettings
self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId
self.about = about
self.flags = flags
@ -101,9 +101,9 @@ public final class CachedGroupData: CachedPeerData {
self.exportedInvitation = decoder.decodeObjectForKey("i", decoder: { ExportedInvitation(decoder: $0) }) as? ExportedInvitation
self.botInfos = decoder.decodeObjectArrayWithDecoderForKey("b") as [CachedPeerBotInfo]
if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value)
self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} 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") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -144,8 +144,8 @@ public final class CachedGroupData: CachedPeerData {
encoder.encodeNil(forKey: "i")
}
encoder.encodeObjectArray(self.botInfos, forKey: "b")
if let peerContactSettings = self.peerContactSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs")
if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else {
encoder.encodeNil(forKey: "pcs")
}
@ -171,34 +171,34 @@ public final class CachedGroupData: CachedPeerData {
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 {
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 {
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 {
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 {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, peerContactSettings: peerContactSettings, pinnedMessageId: self.pinnedMessageId, about: self.about, flags: self.flags)
func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings?) -> CachedGroupData {
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 {
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 {
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 {
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 let about: String?
public let botInfo: BotInfo?
public let peerContactSettings: PeerContactSettings?
public let peerStatusSettings: PeerStatusSettings?
public let pinnedMessageId: MessageId?
public let isBlocked: Bool
public let commonGroupCount: Int32
@ -23,7 +23,7 @@ public final class CachedUserData: CachedPeerData {
init() {
self.about = nil
self.botInfo = nil
self.peerContactSettings = nil
self.peerStatusSettings = nil
self.pinnedMessageId = nil
self.isBlocked = false
self.commonGroupCount = 0
@ -33,10 +33,10 @@ public final class CachedUserData: CachedPeerData {
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.botInfo = botInfo
self.peerContactSettings = peerContactSettings
self.peerStatusSettings = peerStatusSettings
self.pinnedMessageId = pinnedMessageId
self.isBlocked = isBlocked
self.commonGroupCount = commonGroupCount
@ -54,9 +54,9 @@ public final class CachedUserData: CachedPeerData {
self.about = decoder.decodeOptionalStringForKey("a")
self.botInfo = decoder.decodeObjectForKey("bi") as? BotInfo
if let value = decoder.decodeOptionalInt32ForKey("pcs") {
self.peerContactSettings = PeerContactSettings(rawValue: value)
self.peerStatusSettings = PeerStatusSettings(rawValue: value)
} 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") {
self.pinnedMessageId = MessageId(peerId: PeerId(pinnedMessagePeerId), namespace: pinnedMessageNamespace, id: pinnedMessageId)
@ -87,8 +87,8 @@ public final class CachedUserData: CachedPeerData {
} else {
encoder.encodeNil(forKey: "bi")
}
if let peerContactSettings = self.peerContactSettings {
encoder.encodeInt32(peerContactSettings.rawValue, forKey: "pcs")
if let peerStatusSettings = self.peerStatusSettings {
encoder.encodeInt32(peerStatusSettings.rawValue, forKey: "pcs")
} else {
encoder.encodeNil(forKey: "pcs")
}
@ -120,42 +120,42 @@ public final class CachedUserData: CachedPeerData {
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 {
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 {
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 {
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)
func withUpdatedPeerStatusSettings(_ peerStatusSettings: PeerStatusSettings) -> CachedUserData {
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 {
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 {
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 {
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 {
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 {
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 {
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

@ -0,0 +1,84 @@
import Foundation
#if os(macOS)
import SwiftSignalKitMac
import PostboxMac
#else
import SwiftSignalKit
import Postbox
#endif
public enum ChannelOwnershipTransferError {
case generic
case twoStepAuthMissing
case twoStepAuthTooFresh(Int32)
case authSessionTooFresh(Int32)
case requestPassword
case invalidPassword
}
public func updateChannelOwnership(postbox: Postbox, network: Network, accountStateManager: AccountStateManager, channelId: PeerId, memberId: PeerId, password: String?) -> Signal<Void, ChannelOwnershipTransferError> {
return postbox.transaction { transaction -> (channel: Peer?, user: Peer?) in
return (channel: transaction.getPeer(channelId), user: transaction.getPeer(memberId))
}
|> introduceError(ChannelOwnershipTransferError.self)
|> mapToSignal { channel, user -> Signal<Void, ChannelOwnershipTransferError> in
guard let channel = channel, let user = user else {
return .fail(.generic)
}
guard let apiChannel = apiInputChannel(channel) else {
return .fail(.generic)
}
guard let apiUser = apiInputUser(user) else {
return .fail(.generic)
}
let checkPassword: Signal<Api.InputCheckPasswordSRP, ChannelOwnershipTransferError>
if let password = password, !password.isEmpty {
checkPassword = twoStepAuthData(network)
|> mapError { _ in ChannelOwnershipTransferError.generic }
|> mapToSignal { authData -> Signal<Api.InputCheckPasswordSRP, ChannelOwnershipTransferError> in
if let currentPasswordDerivation = authData.currentPasswordDerivation, let srpSessionData = authData.srpSessionData {
guard let kdfResult = passwordKDF(password: password, derivation: currentPasswordDerivation, srpSessionData: srpSessionData) else {
return .fail(.generic)
}
return .single(.inputCheckPasswordSRP(srpId: kdfResult.id, A: Buffer(data: kdfResult.A), M1: Buffer(data: kdfResult.M1)))
} else {
return .fail(.twoStepAuthMissing)
}
}
} else {
checkPassword = .single(.inputCheckPasswordEmpty)
}
return checkPassword
|> mapToSignal { password -> Signal<Void, ChannelOwnershipTransferError> in
return network.request(Api.functions.channels.editCreator(channel: apiChannel, userId: apiUser, password: password))
|> mapError { error -> ChannelOwnershipTransferError in
if error.errorDescription == "PASSWORD_HASH_INVALID" {
if case .inputCheckPasswordEmpty = password {
return .requestPassword
} else {
return .invalidPassword
}
} else if error.errorDescription == "PASSWORD_MISSING" {
return .twoStepAuthMissing
} else if error.errorDescription.hasPrefix("PASSWORD_TOO_FRESH_") {
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "PASSWORD_TOO_FRESH_".count)...])
if let value = Int32(timeout) {
return .twoStepAuthTooFresh(value)
}
} else if error.errorDescription.hasPrefix("SESSION_TOO_FRESH_") {
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "SESSION_TOO_FRESH_".count)...])
if let value = Int32(timeout) {
return .authSessionTooFresh(value)
}
}
return .generic
}
|> mapToSignal { updates -> Signal<Void, ChannelOwnershipTransferError> in
accountStateManager.addUpdates(updates)
return.complete()
}
}
}
}

View File

@ -7,7 +7,6 @@ import SwiftSignalKit
import Postbox
#endif
public enum AvailableChannelDiscussionGroupError {
case generic
}

View File

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

View File

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

View File

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

View File

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

View File

@ -13,44 +13,44 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
let cachedData = transaction.getPeerCachedData(peerId: peerId)
if let cachedData = cachedData as? CachedUserData {
if cachedData.peerContactSettings != nil {
if cachedData.peerStatusSettings != nil {
return .complete()
}
} else if let cachedData = cachedData as? CachedGroupData {
if cachedData.peerContactSettings != nil {
if cachedData.peerStatusSettings != nil {
return .complete()
}
} else if let cachedData = cachedData as? CachedChannelData {
if cachedData.peerContactSettings != nil {
if cachedData.peerStatusSettings != nil {
return .complete()
}
} else if let cachedData = cachedData as? CachedSecretChatData {
if cachedData.peerContactSettings != nil {
if cachedData.peerStatusSettings != nil {
return .complete()
}
}
if peerId.namespace == Namespaces.Peer.SecretChat {
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 = peer as? TelegramSecretChat, case .creator = peer.role {
peerContactSettings = PeerContactSettings()
peerContactSettings.insert(.isHidden)
peerStatusSettings = PeerStatusSettings()
peerStatusSettings.insert(.isHidden)
} else {
peerContactSettings = PeerContactSettings()
peerContactSettings.insert(.canReport)
peerStatusSettings = PeerStatusSettings()
peerStatusSettings.insert(.canReport)
}
} else {
peerContactSettings = PeerContactSettings()
peerContactSettings.insert(.isHidden)
peerStatusSettings = PeerStatusSettings()
peerStatusSettings.insert(.isHidden)
}
transaction.updatePeerCachedData(peerIds: [peerId], update: { peerId, current in
if let current = current as? CachedSecretChatData {
return current.withUpdatedPeerContactSettings(peerContactSettings)
return current.withUpdatedPeerStatusSettings(peerStatusSettings)
} 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))
|> retryRequest
|> mapToSignal { peerSettings -> Signal<Void, NoError> in
let peerContactSettings = PeerContactSettings(apiSettings: peerSettings)
let peerStatusSettings = PeerStatusSettings(apiSettings: peerSettings)
return postbox.transaction { transaction -> Void in
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
@ -70,7 +70,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else {
previous = CachedUserData()
}
return previous.withUpdatedPeerContactSettings(peerContactSettings)
return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
case Namespaces.Peer.CloudGroup:
let previous: CachedGroupData
if let current = current as? CachedGroupData {
@ -78,7 +78,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else {
previous = CachedGroupData()
}
return previous.withUpdatedPeerContactSettings(peerContactSettings)
return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
case Namespaces.Peer.CloudChannel:
let previous: CachedChannelData
if let current = current as? CachedChannelData {
@ -86,7 +86,7 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId: PeerId, network: Network,
} else {
previous = CachedChannelData()
}
return previous.withUpdatedPeerContactSettings(peerContactSettings)
return previous.withUpdatedPeerStatusSettings(peerStatusSettings)
default:
break
}
@ -138,9 +138,9 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
let canPinMessages = (userFull.flags & (1 << 7)) != 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)
}
})
}