Added about for regular groups

Automatically fill history hole after adding group creation message
This commit is contained in:
Peter Iakovlev 2018-12-31 00:28:12 +04:00
parent e89f808e42
commit 7ba618ae65
5 changed files with 56 additions and 29 deletions

View File

@ -2044,6 +2044,16 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, transaction: Tr
}
}
if case let .Id(id) = message.id {
for media in message.media {
if let action = media as? TelegramMediaAction, case .groupCreated = action.action {
if let hole = transaction.getHole(messageId: MessageId(peerId: chatPeerId, namespace: Namespaces.Message.Cloud, id: id.id - 1)) {
transaction.fillHole(hole, fillType: HoleFill(complete: true, direction: .UpperToLower(updatedMinIndex: nil, clippingMaxIndex: nil)), tagMask: nil, messages: [])
}
}
}
}
if !message.flags.contains(.Incoming), message.forwardInfo == nil {
inner: for media in message.media {
if let file = media as? TelegramMediaFile {

View File

@ -36,6 +36,7 @@ public final class CachedGroupData: CachedPeerData {
public let reportStatus: PeerReportStatus
public let pinnedMessageId: MessageId?
public let defaultBannedRights: TelegramChatBannedRights?
public let about: String?
public let peerIds: Set<PeerId>
public let messageIds: Set<MessageId>
@ -50,9 +51,10 @@ public final class CachedGroupData: CachedPeerData {
self.messageIds = Set()
self.peerIds = Set()
self.defaultBannedRights = nil
self.about = nil
}
public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, defaultBannedRights: TelegramChatBannedRights?) {
public init(participants: CachedGroupParticipants?, exportedInvitation: ExportedInvitation?, botInfos: [CachedPeerBotInfo], reportStatus: PeerReportStatus, pinnedMessageId: MessageId?, defaultBannedRights: TelegramChatBannedRights?, about: String?) {
self.participants = participants
self.exportedInvitation = exportedInvitation
self.botInfos = botInfos
@ -76,6 +78,7 @@ public final class CachedGroupData: CachedPeerData {
peerIds.insert(botInfo.peerId)
}
self.peerIds = peerIds
self.about = about
}
public init(decoder: PostboxDecoder) {
@ -90,6 +93,7 @@ public final class CachedGroupData: CachedPeerData {
self.pinnedMessageId = nil
}
self.defaultBannedRights = decoder.decodeObjectForKey("defbr", decoder: { TelegramChatBannedRights(decoder: $0) }) as? TelegramChatBannedRights
self.about = decoder.decodeOptionalStringForKey("ab")
var messageIds = Set<MessageId>()
if let pinnedMessageId = self.pinnedMessageId {
@ -137,6 +141,11 @@ public final class CachedGroupData: CachedPeerData {
} else {
encoder.encodeNil(forKey: "defbr")
}
if let about = self.about {
encoder.encodeString(about, forKey: "ab")
} else {
encoder.encodeNil(forKey: "ab")
}
}
public func isEqual(to: CachedPeerData) -> Bool {
@ -144,30 +153,34 @@ public final class CachedGroupData: CachedPeerData {
return false
}
return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.reportStatus == other.reportStatus && self.pinnedMessageId == other.pinnedMessageId && self.defaultBannedRights == other.defaultBannedRights
return self.participants == other.participants && self.exportedInvitation == other.exportedInvitation && self.botInfos == other.botInfos && self.reportStatus == other.reportStatus && self.pinnedMessageId == other.pinnedMessageId && self.defaultBannedRights == other.defaultBannedRights && self.about == other.about
}
func withUpdatedParticipants(_ participants: CachedGroupParticipants?) -> CachedGroupData {
return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights)
return CachedGroupData(participants: participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about)
}
func withUpdatedExportedInvitation(_ exportedInvitation: ExportedInvitation?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights)
return CachedGroupData(participants: self.participants, exportedInvitation: exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about)
}
func withUpdatedBotInfos(_ botInfos: [CachedPeerBotInfo]) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights)
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about)
}
func withUpdatedReportStatus(_ reportStatus: PeerReportStatus) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights)
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about)
}
func withUpdatedPinnedMessageId(_ pinnedMessageId: MessageId?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: pinnedMessageId, defaultBannedRights: self.defaultBannedRights)
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: self.about)
}
func withUpdatedDefaultBannedRights(_ defaultBannedRights: TelegramChatBannedRights?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: defaultBannedRights)
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: defaultBannedRights, about: self.about)
}
func withUpdatedAbout(_ about: String?) -> CachedGroupData {
return CachedGroupData(participants: self.participants, exportedInvitation: self.exportedInvitation, botInfos: self.botInfos, reportStatus: self.reportStatus, pinnedMessageId: self.pinnedMessageId, defaultBannedRights: self.defaultBannedRights, about: about)
}
}

View File

@ -20,28 +20,29 @@ public func createGroup(account: Account, title: String, peerIds: [PeerId]) -> S
}
}
return account.network.request(Api.functions.messages.createChat(users: inputUsers, title: title))
|> map(Optional.init)
|> `catch` { _ in
return Signal<Api.Updates?, NoError>.single(nil)
}
|> mapToSignal { updates -> Signal<PeerId?, NoError> in
if let updates = updates {
account.stateManager.addUpdates(updates)
if let message = updates.messages.first, let peerId = apiMessagePeerId(message) {
return account.postbox.multiplePeersView([peerId])
|> filter { view in
return view.peers[peerId] != nil
}
|> take(1)
|> map { _ in
return peerId
}
|> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil))
|> map(Optional.init)
|> `catch` { _ in
return Signal<Api.Updates?, NoError>.single(nil)
}
|> mapToSignal { updates -> Signal<PeerId?, NoError> in
if let updates = updates {
account.stateManager.addUpdates(updates)
if let message = updates.messages.first, let peerId = apiMessagePeerId(message) {
return account.postbox.multiplePeersView([peerId])
|> filter { view in
return view.peers[peerId] != nil
}
return .single(nil)
} else {
return .single(nil)
|> take(1)
|> map { _ in
return peerId
}
|> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil))
}
return .single(nil)
} else {
return .single(nil)
}
} |> switchToLatest
}
}
|> switchToLatest
}

View File

@ -220,6 +220,7 @@ func fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId: PeerId, network
.withUpdatedBotInfos(botInfos)
.withUpdatedPinnedMessageId(pinnedMessageId)
.withUpdatedDefaultBannedRights(defaultBannedRights)
.withUpdatedAbout(chatFull.about)
})
case .channelFull:
break

View File

@ -75,6 +75,8 @@ public func updatePeerDescription(account: Account, peerId: PeerId, description:
transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in
if let current = current as? CachedChannelData {
return current.withUpdatedAbout(description)
} else if let current = current as? CachedGroupData {
return current.withUpdatedAbout(description)
} else {
return current
}