2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-17 16:21:09 +00:00
|
|
|
package im.vector.matrix.android.internal.session.room
|
|
|
|
|
2019-01-16 18:25:43 +00:00
|
|
|
import androidx.lifecycle.LiveData
|
|
|
|
import androidx.lifecycle.Transformations
|
2018-11-27 11:06:40 +00:00
|
|
|
import com.zhuinden.monarchy.Monarchy
|
2018-10-17 16:21:09 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.Room
|
2018-10-25 14:55:41 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.model.Membership
|
2018-10-29 13:57:36 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.model.RoomSummary
|
2019-01-28 16:56:23 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.read.ReadService
|
|
|
|
import im.vector.matrix.android.api.session.room.send.SendService
|
2019-01-14 15:18:39 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.TimelineService
|
2018-10-25 14:55:41 +00:00
|
|
|
import im.vector.matrix.android.api.util.Cancelable
|
2018-10-29 13:57:36 +00:00
|
|
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
2018-10-23 16:25:28 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
2018-10-30 17:22:29 +00:00
|
|
|
import im.vector.matrix.android.internal.database.model.RoomSummaryEntityFields
|
2018-10-18 16:38:11 +00:00
|
|
|
import im.vector.matrix.android.internal.database.query.where
|
2018-12-14 16:39:25 +00:00
|
|
|
import im.vector.matrix.android.internal.session.room.members.LoadRoomMembersTask
|
2018-12-20 14:44:01 +00:00
|
|
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
|
|
|
import im.vector.matrix.android.internal.task.configureWith
|
2018-10-17 16:21:09 +00:00
|
|
|
|
2019-02-26 18:32:01 +00:00
|
|
|
internal class DefaultRoom(
|
2018-10-23 16:25:28 +00:00
|
|
|
override val roomId: String,
|
2019-01-28 17:42:29 +00:00
|
|
|
private val loadRoomMembersTask: LoadRoomMembersTask,
|
|
|
|
private val monarchy: Monarchy,
|
|
|
|
private val timelineService: TimelineService,
|
|
|
|
private val sendService: SendService,
|
|
|
|
private val readService: ReadService,
|
|
|
|
private val taskExecutor: TaskExecutor
|
2018-10-18 16:38:11 +00:00
|
|
|
|
2019-01-28 17:42:29 +00:00
|
|
|
|
|
|
|
) : Room,
|
|
|
|
TimelineService by timelineService,
|
|
|
|
SendService by sendService,
|
|
|
|
ReadService by readService {
|
2018-10-22 17:36:29 +00:00
|
|
|
|
2018-10-29 13:57:36 +00:00
|
|
|
override val roomSummary: LiveData<RoomSummary> by lazy {
|
2018-11-27 11:06:40 +00:00
|
|
|
val liveData = monarchy
|
2018-10-29 13:57:36 +00:00
|
|
|
.findAllMappedWithChanges(
|
2018-10-30 17:22:29 +00:00
|
|
|
{ realm -> RoomSummaryEntity.where(realm, roomId).isNotEmpty(RoomSummaryEntityFields.DISPLAY_NAME) },
|
2018-10-29 13:57:36 +00:00
|
|
|
{ from -> from.asDomain() })
|
|
|
|
|
|
|
|
Transformations.map(liveData) {
|
|
|
|
it.first()
|
|
|
|
}
|
2018-10-18 16:38:11 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 14:55:41 +00:00
|
|
|
override fun loadRoomMembersIfNeeded(): Cancelable {
|
2018-12-30 09:53:56 +00:00
|
|
|
val params = LoadRoomMembersTask.Params(roomId, Membership.LEAVE)
|
|
|
|
return loadRoomMembersTask.configureWith(params).executeBy(taskExecutor)
|
2018-10-25 14:55:41 +00:00
|
|
|
}
|
2018-10-18 16:38:11 +00:00
|
|
|
}
|