Discussion group updates

This commit is contained in:
Peter 2019-05-25 00:07:04 +02:00
parent df5653b780
commit fe13574c44
6 changed files with 64 additions and 45 deletions

View File

@ -742,7 +742,6 @@ public final class AccountViewTracker {
func forceUpdateCachedPeerData(peerId: PeerId) {
self.queue.async {
let context: PeerCachedDataContext
var dataUpdated = false
if let existingContext = self.cachedDataContexts[peerId] {
context = existingContext
} else {
@ -928,7 +927,14 @@ public final class AccountViewTracker {
}
}
func wrappedPeerViewSignal(peerId: PeerId, signal: Signal<PeerView, NoError>) -> Signal<PeerView, NoError> {
func wrappedPeerViewSignal(peerId: PeerId, signal: Signal<PeerView, NoError>, updateData: Bool) -> Signal<PeerView, NoError> {
if updateData {
self.queue.async {
if let existingContext = self.cachedDataContexts[peerId] {
existingContext.timestamp = nil
}
}
}
return withState(signal, { [weak self] () -> Int32 in
if let strongSelf = self {
return OSAtomicIncrement32(&strongSelf.nextViewId)
@ -946,9 +952,9 @@ public final class AccountViewTracker {
})
}
public func peerView(_ peerId: PeerId) -> Signal<PeerView, NoError> {
public func peerView(_ peerId: PeerId, updateData: Bool = false) -> Signal<PeerView, NoError> {
if let account = self.account {
return wrappedPeerViewSignal(peerId: peerId, signal: account.postbox.peerView(id: peerId))
return wrappedPeerViewSignal(peerId: peerId, signal: account.postbox.peerView(id: peerId), updateData: updateData)
} else {
return .never()
}

View File

@ -138,7 +138,7 @@ public final class CachedChannelData: CachedPeerData {
public let minAvailableMessageId: MessageId?
public let migrationReference: ChannelMigrationReference?
public let associatedPeerId:PeerId?
public let linkedDiscussionPeerId: PeerId?
public let peerIds: Set<PeerId>
public let messageIds: Set<MessageId>
@ -160,10 +160,10 @@ public final class CachedChannelData: CachedPeerData {
self.stickerPack = nil
self.minAvailableMessageId = nil
self.migrationReference = nil
self.associatedPeerId = nil
self.linkedDiscussionPeerId = nil
}
init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, associatedPeerId: PeerId?) {
init(isNotAccessible: Bool, flags: CachedChannelFlags, about: String?, participantsSummary: CachedChannelParticipantsSummary, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, stickerPack: StickerPackCollectionInfo?, minAvailableMessageId: MessageId?, migrationReference: ChannelMigrationReference?, linkedDiscussionPeerId: PeerId?) {
self.isNotAccessible = isNotAccessible
self.flags = flags
self.about = about
@ -175,15 +175,15 @@ public final class CachedChannelData: CachedPeerData {
self.stickerPack = stickerPack
self.minAvailableMessageId = minAvailableMessageId
self.migrationReference = migrationReference
self.associatedPeerId = associatedPeerId
self.linkedDiscussionPeerId = linkedDiscussionPeerId
var peerIds = Set<PeerId>()
for botInfo in botInfos {
peerIds.insert(botInfo.peerId)
}
if let associatedPeerId = associatedPeerId {
peerIds.insert(associatedPeerId)
if let linkedDiscussionPeerId = linkedDiscussionPeerId {
peerIds.insert(linkedDiscussionPeerId)
}
self.peerIds = peerIds
@ -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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
}
func withUpdatedReportStatus(_ reportStatus: PeerReportStatus) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, 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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, associatedPeerId: self.associatedPeerId)
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: migrationReference, linkedDiscussionPeerId: self.linkedDiscussionPeerId)
}
func withUpdatedAssociatedPeerId(_ groupId: PeerId?) -> CachedChannelData {
return CachedChannelData(isNotAccessible: self.isNotAccessible, flags: self.flags, about: self.about, participantsSummary: self.participantsSummary, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, associatedPeerId: groupId)
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, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, stickerPack: self.stickerPack, minAvailableMessageId: self.minAvailableMessageId, migrationReference: self.migrationReference, linkedDiscussionPeerId: linkedDiscussionPeerId)
}
public init(decoder: PostboxDecoder) {
@ -276,14 +276,14 @@ public final class CachedChannelData: CachedPeerData {
peerIds.insert(botInfo.peerId)
}
if let associatedPeerId = decoder.decodeOptionalInt64ForKey("dgi") {
self.associatedPeerId = PeerId(associatedPeerId)
if let linkedDiscussionPeerId = decoder.decodeOptionalInt64ForKey("dgi") {
self.linkedDiscussionPeerId = PeerId(linkedDiscussionPeerId)
} else {
self.associatedPeerId = nil
self.linkedDiscussionPeerId = nil
}
if let associatedPeerId = associatedPeerId {
peerIds.insert(associatedPeerId)
if let linkedDiscussionPeerId = self.linkedDiscussionPeerId {
peerIds.insert(linkedDiscussionPeerId)
}
self.peerIds = peerIds
@ -293,8 +293,6 @@ public final class CachedChannelData: CachedPeerData {
messageIds.insert(pinnedMessageId)
}
self.messageIds = messageIds
}
public func encode(_ encoder: PostboxEncoder) {
@ -341,8 +339,8 @@ public final class CachedChannelData: CachedPeerData {
} else {
encoder.encodeNil(forKey: "mr")
}
if let associatedPeerId = self.associatedPeerId {
encoder.encodeInt64(associatedPeerId.toInt64(), forKey: "dgi")
if let linkedDiscussionPeerId = self.linkedDiscussionPeerId {
encoder.encodeInt64(linkedDiscussionPeerId.toInt64(), forKey: "dgi")
} else {
encoder.encodeNil(forKey: "dgi")
}
@ -361,7 +359,7 @@ public final class CachedChannelData: CachedPeerData {
return false
}
if other.associatedPeerId != self.associatedPeerId {
if other.linkedDiscussionPeerId != self.linkedDiscussionPeerId {
return false
}

View File

@ -55,6 +55,7 @@ public enum AdminLogEventAction {
case updateDefaultBannedRights(prev: TelegramChatBannedRights, new: TelegramChatBannedRights
)
case pollStopped(Message)
case linkedPeerUpdated(previous: Peer?, updated: Peer?)
}
public enum ChannelAdminLogEventError {
@ -208,7 +209,7 @@ public func channelAdminLogEvents(postbox: Postbox, network: Network, peerId: Pe
action = .pollStopped(rendered)
}
case let .channelAdminLogEventActionChangeLinkedChat(prevValue, newValue):
break
action = .linkedPeerUpdated(previous: prevValue == 0 ? nil : peers[PeerId(namespace: Namespaces.Peer.CloudChannel, id: prevValue)], updated: newValue == 0 ? nil : peers[PeerId(namespace: Namespaces.Peer.CloudChannel, id: newValue)])
}
let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
if let action = action {

View File

@ -223,6 +223,9 @@ final class ChatHistoryPreloadManager {
guard let strongSelf = self else {
return
}
#if DEBUG
return;
#endif
var indices: [(ChatHistoryPreloadIndex, Bool, Bool)] = []
for entry in view.0.entries {
if case let .MessageEntry(index, _, readState, notificationSettings, _, _, _, _) = entry {

View File

@ -56,8 +56,6 @@ public enum ChannelDiscussionGroupError {
case generic
}
//channels.setDiscussionGroup broadcast:InputChannel group:InputChannel = Bool;
public func updateGroupDiscussionForChannel(network: Network, postbox: Postbox, channelId: PeerId, groupId: PeerId?) -> Signal<Bool, ChannelDiscussionGroupError> {
return postbox.transaction { transaction -> (channel: Peer?, group: Peer?) in
@ -81,18 +79,31 @@ public func updateGroupDiscussionForChannel(network: Network, postbox: Postbox,
}
|> map { result in
switch result {
case .boolTrue:
return true
case .boolFalse:
return false
case .boolTrue:
return true
case .boolFalse:
return false
}
}
} |> mapToSignal { result in
if result {
return postbox.transaction { transaction in
var previousGroupId: PeerId?
transaction.updatePeerCachedData(peerIds: Set([channelId]), update: { (_, current) -> CachedPeerData? in
return (current as? CachedChannelData ?? CachedChannelData()).withUpdatedAssociatedPeerId(groupId)
let current: CachedChannelData = current as? CachedChannelData ?? CachedChannelData()
previousGroupId = current.linkedDiscussionPeerId
return current.withUpdatedLinkedDiscussionPeerId(groupId)
})
if let previousGroupId = previousGroupId {
transaction.updatePeerCachedData(peerIds: Set([previousGroupId]), update: { (_, current) -> CachedPeerData? in
return (current as? CachedChannelData ?? CachedChannelData()).withUpdatedLinkedDiscussionPeerId(nil)
})
}
if let groupId = groupId {
transaction.updatePeerCachedData(peerIds: Set([groupId]), update: { (_, current) -> CachedPeerData? in
return (current as? CachedChannelData ?? CachedChannelData()).withUpdatedLinkedDiscussionPeerId(channelId)
})
}
}
|> introduceError(ChannelDiscussionGroupError.self)
|> map { _ in

View File

@ -271,12 +271,12 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
channelFlags.insert(.canSetStickerSet)
}
let associatedPeerId: PeerId?
let linkedDiscussionPeerId: PeerId?
if let linkedChatId = linkedChatId {
associatedPeerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: linkedChatId)
linkedDiscussionPeerId = PeerId(namespace: Namespaces.Peer.CloudChannel, id: linkedChatId)
} else {
associatedPeerId = nil
linkedDiscussionPeerId = nil
}
var botInfos: [CachedPeerBotInfo] = []
@ -365,7 +365,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
.withUpdatedStickerPack(stickerPack)
.withUpdatedMinAvailableMessageId(minAvailableMessageId)
.withUpdatedMigrationReference(migrationReference)
.withUpdatedAssociatedPeerId(associatedPeerId)
.withUpdatedLinkedDiscussionPeerId(linkedDiscussionPeerId)
})
if let minAvailableMessageId = minAvailableMessageId, minAvailableMessageIdUpdated {