Service API to listen live summaries given a list of event ids
This commit is contained in:
parent
3ab941eace
commit
96da695473
@ -60,4 +60,10 @@ interface LocationSharingService {
|
||||
* Returns a LiveData on the list of current running live location shares.
|
||||
*/
|
||||
fun getRunningLiveLocationShareSummaries(): LiveData<List<LiveLocationShareAggregatedSummary>>
|
||||
|
||||
/**
|
||||
* Returns a LiveData on the list of live location shares with the given eventIds.
|
||||
* @param eventIds the list of event ids
|
||||
*/
|
||||
fun getLiveLocationShareSummaries(eventIds: List<String>): LiveData<List<LiveLocationShareAggregatedSummary>>
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ internal fun LiveLocationShareAggregatedSummaryEntity.Companion.findActiveLiveIn
|
||||
realm: Realm,
|
||||
roomId: String,
|
||||
userId: String,
|
||||
ignoredEventId: String
|
||||
ignoredEventId: String,
|
||||
): List<LiveLocationShareAggregatedSummaryEntity> {
|
||||
return LiveLocationShareAggregatedSummaryEntity
|
||||
.whereRoomId(realm, roomId = roomId)
|
||||
@ -100,3 +100,14 @@ internal fun LiveLocationShareAggregatedSummaryEntity.Companion.findRunningLiveI
|
||||
.isNotEmpty(LiveLocationShareAggregatedSummaryEntityFields.USER_ID)
|
||||
.isNotNull(LiveLocationShareAggregatedSummaryEntityFields.LAST_LOCATION_CONTENT)
|
||||
}
|
||||
|
||||
internal fun LiveLocationShareAggregatedSummaryEntity.Companion.findLiveInRoom(
|
||||
realm: Realm,
|
||||
roomId: String,
|
||||
eventIds: List<String>,
|
||||
): RealmQuery<LiveLocationShareAggregatedSummaryEntity> {
|
||||
return LiveLocationShareAggregatedSummaryEntity
|
||||
.whereRoomId(realm, roomId = roomId)
|
||||
.isNotEmpty(LiveLocationShareAggregatedSummaryEntityFields.USER_ID)
|
||||
.`in`(LiveLocationShareAggregatedSummaryEntityFields.EVENT_ID, eventIds.toTypedArray())
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationSh
|
||||
import org.matrix.android.sdk.api.util.Cancelable
|
||||
import org.matrix.android.sdk.internal.database.mapper.LiveLocationShareAggregatedSummaryMapper
|
||||
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.findLiveInRoom
|
||||
import org.matrix.android.sdk.internal.database.query.findRunningLiveInRoom
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
|
||||
@ -88,4 +89,11 @@ internal class DefaultLocationSharingService @AssistedInject constructor(
|
||||
liveLocationShareAggregatedSummaryMapper
|
||||
)
|
||||
}
|
||||
|
||||
override fun getLiveLocationShareSummaries(eventIds: List<String>): LiveData<List<LiveLocationShareAggregatedSummary>> {
|
||||
return monarchy.findAllMappedWithChanges(
|
||||
{ LiveLocationShareAggregatedSummaryEntity.findLiveInRoom(it, roomId = roomId, eventIds = eventIds) },
|
||||
liveLocationShareAggregatedSummaryMapper
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationS
|
||||
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntityFields
|
||||
import org.matrix.android.sdk.test.fakes.FakeMonarchy
|
||||
import org.matrix.android.sdk.test.fakes.givenEqualTo
|
||||
import org.matrix.android.sdk.test.fakes.givenIn
|
||||
import org.matrix.android.sdk.test.fakes.givenIsNotEmpty
|
||||
import org.matrix.android.sdk.test.fakes.givenIsNotNull
|
||||
|
||||
@ -168,4 +169,30 @@ internal class DefaultLocationSharingServiceTest {
|
||||
|
||||
result shouldBeEqualTo listOf(summary)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given a list of event ids livedata on live summaries is correctly computed`() {
|
||||
val eventIds = listOf("event_id_1", "event_id_2", "event_id_3")
|
||||
val entity = LiveLocationShareAggregatedSummaryEntity()
|
||||
val summary = LiveLocationShareAggregatedSummary(
|
||||
userId = "",
|
||||
isActive = true,
|
||||
endOfLiveTimestampMillis = 123,
|
||||
lastLocationDataContent = null
|
||||
)
|
||||
|
||||
fakeMonarchy.givenWhere<LiveLocationShareAggregatedSummaryEntity>()
|
||||
.givenEqualTo(LiveLocationShareAggregatedSummaryEntityFields.ROOM_ID, fakeRoomId)
|
||||
.givenIsNotEmpty(LiveLocationShareAggregatedSummaryEntityFields.USER_ID)
|
||||
.givenIn(LiveLocationShareAggregatedSummaryEntityFields.EVENT_ID, eventIds)
|
||||
fakeMonarchy.givenFindAllMappedWithChangesReturns(
|
||||
realmEntities = listOf(entity),
|
||||
mappedResult = listOf(summary),
|
||||
fakeLiveLocationShareAggregatedSummaryMapper
|
||||
)
|
||||
|
||||
val result = defaultLocationSharingService.getLiveLocationShareSummaries(eventIds).value
|
||||
|
||||
result shouldBeEqualTo listOf(summary)
|
||||
}
|
||||
}
|
||||
|
@ -97,3 +97,11 @@ inline fun <reified T : RealmModel> RealmQuery<T>.givenIsNotNull(
|
||||
every { isNotNull(fieldName) } returns this
|
||||
return this
|
||||
}
|
||||
|
||||
inline fun <reified T : RealmModel> RealmQuery<T>.givenIn(
|
||||
fieldName: String,
|
||||
values: List<String>
|
||||
): RealmQuery<T> {
|
||||
every { `in`(fieldName, values.toTypedArray()) } returns this
|
||||
return this
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user