forked from GitHub-Mirror/riotX-android
Read receipts : start to query them when item become visible... not sure it's the right way to do.
This commit is contained in:
parent
8d13f08574
commit
4048658c56
@ -89,6 +89,7 @@ class RoomDetailViewModel(initialState: RoomDetailViewState,
|
||||
|
||||
private fun handleEventDisplayed(action: RoomDetailActions.EventDisplayed) {
|
||||
displayedEventsObservable.accept(action)
|
||||
|
||||
}
|
||||
|
||||
private fun handleIsDisplayed() {
|
||||
@ -102,6 +103,18 @@ class RoomDetailViewModel(initialState: RoomDetailViewState,
|
||||
.buffer(1, TimeUnit.SECONDS)
|
||||
.filter { it.isNotEmpty() }
|
||||
.subscribeBy(onNext = { actions ->
|
||||
val eventIds = actions.mapNotNull { it.event.root.eventId }
|
||||
withState { state ->
|
||||
val newMapOfReadReceipts = HashMap(state.readReceiptsForEventId)
|
||||
eventIds.forEach {
|
||||
if (newMapOfReadReceipts.containsKey(it).not()) {
|
||||
val readReceipts = room.readReceipts(it)
|
||||
newMapOfReadReceipts[it] = readReceipts
|
||||
}
|
||||
}
|
||||
setState { copy(readReceiptsForEventId = newMapOfReadReceipts) }
|
||||
}
|
||||
|
||||
val mostRecentEvent = actions.lastMinBy { it.index }
|
||||
mostRecentEvent?.event?.root?.eventId?.let { eventId ->
|
||||
room.setReadReceipt(eventId, callback = object : MatrixCallback<Void> {})
|
||||
|
@ -19,12 +19,14 @@ package im.vector.riotredesign.features.home.room.detail
|
||||
import com.airbnb.mvrx.Async
|
||||
import com.airbnb.mvrx.MvRxState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import im.vector.matrix.android.api.session.room.model.ReadReceipt
|
||||
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineData
|
||||
|
||||
data class RoomDetailViewState(
|
||||
val roomId: String,
|
||||
val eventId: String?,
|
||||
val readReceiptsForEventId: Map<String, List<ReadReceipt>> = emptyMap(),
|
||||
val asyncRoomSummary: Async<RoomSummary> = Uninitialized,
|
||||
val asyncTimelineData: Async<TimelineData> = Uninitialized
|
||||
) : MvRxState {
|
||||
|
@ -60,13 +60,4 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/messageMemberNameView"
|
||||
tools:text="Alright finished work, heading there in about 20 mins…
Ping me when you’re outside" />
|
||||
|
||||
<include
|
||||
android:id="@+id/messageReadReceipts"
|
||||
layout="@layout/item_timeline_read_receipts"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/messageTextView"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -46,10 +46,10 @@ interface ReadService {
|
||||
fun readReceipts(): LiveData<List<ReadReceipt>>
|
||||
|
||||
/**
|
||||
* @param eventId to look for receipt.
|
||||
* * @return the receipt associated or null
|
||||
* @param eventId to look for receipts.
|
||||
* * @return the list of receipts associated with the eventId
|
||||
*/
|
||||
fun readReceipt(eventId: String): ReadReceipt?
|
||||
fun readReceipts(eventId: String): List<ReadReceipt>
|
||||
|
||||
/**
|
||||
* A listener defined at the room level to listen for some read events.
|
||||
|
@ -31,4 +31,4 @@ internal fun ReadReceiptEntity.Companion.where(realm: Realm, roomId: String, use
|
||||
internal fun ReadReceiptEntity.Companion.where(realm: Realm, roomId: String): RealmQuery<ReadReceiptEntity> {
|
||||
return realm.where<ReadReceiptEntity>()
|
||||
.equalTo(ReadReceiptEntityFields.ROOM_ID, roomId)
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import im.vector.matrix.android.api.session.room.model.ReadReceipt
|
||||
import im.vector.matrix.android.api.session.room.read.ReadService
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
||||
import im.vector.matrix.android.internal.database.model.ReadReceiptEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.latestEvent
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||
@ -62,10 +63,16 @@ internal class DefaultReadService(private val roomId: String,
|
||||
)
|
||||
}
|
||||
|
||||
override fun readReceipt(eventId: String): ReadReceipt? {
|
||||
val readReceipt = monarchy.fetchCopied { ReadReceiptEntity.where(it, roomId).findFirst() }
|
||||
?: return null
|
||||
val roomMember = roomMembersService.getRoomMember(readReceipt.userId)
|
||||
return ReadReceipt(roomMember, readReceipt.eventId, readReceipt.originServerTs.toLong())
|
||||
override fun readReceipts(eventId: String): List<ReadReceipt> {
|
||||
return monarchy.fetchAllMappedSync(
|
||||
{ realm ->
|
||||
ReadReceiptEntity.where(realm, roomId)
|
||||
.equalTo(ReadReceiptEntityFields.EVENT_ID, eventId)
|
||||
},
|
||||
{
|
||||
val roomMember = roomMembersService.getRoomMember(it.userId)
|
||||
ReadReceipt(roomMember, it.eventId, it.originServerTs.toLong())
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user