mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Timeline: url preview listen to Flow in ViewModel
This commit is contained in:
parent
c830d49924
commit
31ba912d6e
1 changed files with 25 additions and 10 deletions
|
@ -160,6 +160,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
observeMyRoomMember()
|
||||
observeActiveRoomWidgets()
|
||||
observePowerLevel()
|
||||
setupPreviewUrlObservers()
|
||||
room.getRoomSummaryLive()
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
tryOrNull { room.markAsRead(ReadService.MarkAsReadParams.READ_RECEIPT) }
|
||||
|
@ -263,6 +264,30 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupPreviewUrlObservers() {
|
||||
if (!vectorPreferences.showUrlPreviews()) {
|
||||
return
|
||||
}
|
||||
combine(
|
||||
timelineEvents,
|
||||
room.flow().liveRoomSummary()
|
||||
.unwrap()
|
||||
.map { it.isEncrypted }
|
||||
.distinctUntilChanged()
|
||||
) { snapshot, isRoomEncrypted ->
|
||||
if (isRoomEncrypted) {
|
||||
return@combine
|
||||
}
|
||||
withContext(Dispatchers.Default) {
|
||||
Timber.v("On new timeline events for urlpreview on ${Thread.currentThread()}")
|
||||
snapshot.forEach {
|
||||
previewUrlRetriever.getPreviewUrl(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
fun getOtherUserIds() = room.roomSummary()?.otherMemberIds
|
||||
|
||||
override fun handle(action: RoomDetailAction) {
|
||||
|
@ -1031,16 +1056,6 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
// tryEmit doesn't work with SharedFlow without cache
|
||||
timelineEvents.emit(snapshot)
|
||||
}
|
||||
// PreviewUrl
|
||||
if (vectorPreferences.showUrlPreviews()) {
|
||||
withState { state ->
|
||||
snapshot
|
||||
.takeIf { state.asyncRoomSummary.invoke()?.isEncrypted == false }
|
||||
?.forEach {
|
||||
previewUrlRetriever.getPreviewUrl(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTimelineFailure(throwable: Throwable) {
|
||||
|
|
Loading…
Reference in a new issue