First mapping of room. Still very dirty
This commit is contained in:
parent
58decf03d8
commit
f906158f2b
11 changed files with 165 additions and 30 deletions
|
|
@ -28,7 +28,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation(name: 'matrix-rust-sdk', ext: 'aar')
|
||||
api(name: 'matrix-rust-sdk', ext: 'aar')
|
||||
implementation "net.java.dev.jna:jna:5.10.0@aar"
|
||||
implementation 'androidx.datastore:datastore-core:1.0.0'
|
||||
implementation 'androidx.datastore:datastore-preferences:1.0.0'
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ class MatrixClient internal constructor(
|
|||
private val client: Client,
|
||||
private val sessionStore: SessionStore,
|
||||
) {
|
||||
private val roomWrapper = RoomWrapper(client)
|
||||
|
||||
fun startSync() {
|
||||
val clientDelegate = object : ClientDelegate {
|
||||
override fun didReceiveAuthError(isSoftLogout: Boolean) {
|
||||
|
|
@ -32,7 +34,7 @@ class MatrixClient internal constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun slidingSync(onSyncUpdate: (UpdateSummary) -> Unit): StoppableSpawn {
|
||||
fun slidingSync(listener: SlidingSyncListener): StoppableSpawn {
|
||||
val slidingSyncView = SlidingSyncViewBuilder()
|
||||
.timelineLimit(limit = 10u)
|
||||
.requiredState(requiredState = listOf(RequiredState(key = "m.room.avatar", value = "")))
|
||||
|
|
@ -49,7 +51,10 @@ class MatrixClient internal constructor(
|
|||
slidingSync.setObserver(object : SlidingSyncObserver {
|
||||
override fun didReceiveSyncUpdate(summary: UpdateSummary) {
|
||||
Log.v(LOG_TAG, "didReceiveSyncUpdate=$summary")
|
||||
onSyncUpdate.invoke(summary)
|
||||
val rooms = summary.rooms.mapNotNull {
|
||||
roomWrapper.getRoom(it)
|
||||
}
|
||||
listener.onSyncUpdate(summary, rooms)
|
||||
}
|
||||
})
|
||||
return slidingSync.sync()
|
||||
|
|
@ -59,4 +64,11 @@ class MatrixClient internal constructor(
|
|||
client.logout()
|
||||
sessionStore.reset()
|
||||
}
|
||||
|
||||
fun username(): String = client.displayName()
|
||||
fun avatarUrl(): String = client.avatarUrl()
|
||||
|
||||
interface SlidingSyncListener {
|
||||
fun onSyncUpdate(summary: UpdateSummary, rooms: List<Room>)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package io.element.android.x.sdk.matrix
|
||||
|
||||
import android.util.Log
|
||||
import org.matrix.rustcomponents.sdk.Client
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
|
||||
class RoomWrapper(
|
||||
private val client: Client
|
||||
) {
|
||||
fun getRoom(roomId: String): Room? {
|
||||
val rooms = client.rooms()
|
||||
Log.d(LOG_TAG, "We have ${rooms.size} rooms")
|
||||
return rooms.firstOrNull { it.id() == roomId }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue