ref: caching joined rooms
This commit is contained in:
@@ -24,16 +24,25 @@ import ru.risdeveau.pixeldragon.token
|
||||
//
|
||||
//}
|
||||
|
||||
suspend fun getRooms(): List<String> {
|
||||
suspend fun getJoinedRooms(): List<Room> {
|
||||
val r = client.get("$baseUrl/joined_rooms")
|
||||
{ bearerAuth(token) }
|
||||
val rooms = JSONObject(r.bodyAsText()).getJSONArray("joined_rooms")
|
||||
return List(
|
||||
rooms.length()
|
||||
) { i -> getRoom(rooms.getString(i), true) }
|
||||
}
|
||||
|
||||
suspend fun isJoined(id: String): Boolean {
|
||||
val r = client.get("$baseUrl/joined_rooms")
|
||||
{ bearerAuth(token) }
|
||||
val rooms = JSONObject(r.bodyAsText()).getJSONArray("joined_rooms")
|
||||
return List<String>(
|
||||
rooms.length()
|
||||
) { i -> rooms.getString(i) }
|
||||
) { i -> rooms.getString(i) }.contains(id)
|
||||
}
|
||||
|
||||
suspend fun getRoom(rid: String): Room {
|
||||
suspend fun getRoom(rid: String, joined: Boolean? = null): Room {
|
||||
val direct = getAccountData(getMe()!!.userId, "m.direct")
|
||||
var directWith = ""
|
||||
direct?.let {
|
||||
@@ -61,7 +70,7 @@ suspend fun getRoom(rid: String): Room {
|
||||
null,
|
||||
avatar,
|
||||
null,
|
||||
true, // TODO: insert actual value
|
||||
joined ?: isJoined(rid),
|
||||
if (directWith.isNotEmpty()) User.getById(directWith) else null
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user