VB: Make the view model aware of every chunk new coming

this reactive approach will help to cache and reorder them by sequence
This commit is contained in:
manuroe
2022-10-19 17:28:08 +02:00
committed by yostyle
parent c606db5d02
commit 736cde698b
3 changed files with 32 additions and 13 deletions
@@ -28,15 +28,19 @@ struct VoiceBroadcastBuilder {
var voiceBroadcast = VoiceBroadcast()
voiceBroadcast.chunks = Set(events.compactMap { event in
guard let attachment = MXKAttachment(event: event, andMediaManager: mediaManager),
let chunkInfo = event.content[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkType] as? [String: UInt],
let sequence = chunkInfo[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkSequence] else {
return nil
}
return VoiceBroadcastChunk(voiceBroadcastInfoEventId: voiceBroadcastStartEventId, sequence: sequence, attachment: attachment)
buildChunk(event: event, mediaManager: mediaManager, voiceBroadcastStartEventId: voiceBroadcastStartEventId)
})
return voiceBroadcast
}
func buildChunk(event: MXEvent, mediaManager: MXMediaManager, voiceBroadcastStartEventId: String) -> VoiceBroadcastChunk? {
guard let attachment = MXKAttachment(event: event, andMediaManager: mediaManager),
let chunkInfo = event.content[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkType] as? [String: UInt],
let sequence = chunkInfo[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkSequence] else {
return nil
}
return VoiceBroadcastChunk(voiceBroadcastInfoEventId: voiceBroadcastStartEventId, sequence: sequence, attachment: attachment)
}
}