Fix "Leave room only leaves the current version"

This commit is contained in:
ganfra 2020-07-10 08:54:41 +02:00
parent da7c971927
commit 9c595b6c02
2 changed files with 19 additions and 3 deletions

View file

@ -14,6 +14,7 @@ Bugfix 🐛:
- Regression Composer does not grow, crops out text (#1650)
- Bug / Unwanted draft (#698)
- All users seems to be able to see the enable encryption option in room settings (#1341)
- Leave room only leaves the current version (#1656)
Translations 🗣:
-

View file

@ -16,8 +16,13 @@
package im.vector.matrix.android.internal.session.room.membership.leaving
import im.vector.matrix.android.api.query.QueryStringValue
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.create.RoomCreateContent
import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.room.RoomAPI
import im.vector.matrix.android.internal.session.room.state.StateEventDataSource
import im.vector.matrix.android.internal.task.Task
import org.greenrobot.eventbus.EventBus
import javax.inject.Inject
@ -31,12 +36,22 @@ internal interface LeaveRoomTask : Task<LeaveRoomTask.Params, Unit> {
internal class DefaultLeaveRoomTask @Inject constructor(
private val roomAPI: RoomAPI,
private val eventBus: EventBus
private val eventBus: EventBus,
private val stateEventDataSource: StateEventDataSource
) : LeaveRoomTask {
override suspend fun execute(params: LeaveRoomTask.Params) {
return executeRequest(eventBus) {
apiCall = roomAPI.leave(params.roomId, mapOf("reason" to params.reason))
leaveRoom(params.roomId, params.reason)
}
private suspend fun leaveRoom(roomId: String, reason: String?) {
val roomCreateStateEvent = stateEventDataSource.getStateEvent(roomId, eventType = EventType.STATE_ROOM_CREATE, stateKey = QueryStringValue.NoCondition)
val predecessorRoomId = roomCreateStateEvent?.getClearContent()?.toModel<RoomCreateContent>()?.predecessor?.roomId
executeRequest<Unit>(eventBus) {
apiCall = roomAPI.leave(roomId, mapOf("reason" to reason))
}
if (predecessorRoomId != null) {
leaveRoom(predecessorRoomId, reason)
}
}
}