removing invites from the database after rejecting them and allowing them to fail with 403 (if the user no longer has access)

This commit is contained in:
Adam Brown 2022-09-10 19:50:19 +01:00 committed by Adam Brown
parent 40461f692f
commit ee91de4301
5 changed files with 46 additions and 4 deletions

View File

@ -303,6 +303,7 @@ internal class MatrixModules(
} }
} }
val overviewStore = store.overviewStore()
installRoomService( installRoomService(
storeModule.value.memberStore(), storeModule.value.memberStore(),
roomMessenger = { roomMessenger = {
@ -316,6 +317,9 @@ internal class MatrixModules(
) )
} }
} }
},
roomInviteRemover = {
overviewStore.removeInvites(listOf(it))
} }
) )
@ -323,7 +327,7 @@ internal class MatrixModules(
installSyncService( installSyncService(
credentialsStore, credentialsStore,
store.overviewStore(), overviewStore,
store.roomStore(), store.roomStore(),
store.syncStore(), store.syncStore(),
store.filterStore(), store.filterStore(),

View File

@ -1,5 +1,6 @@
package app.dapk.st.profile package app.dapk.st.profile
import android.util.Log
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import app.dapk.st.core.Lce import app.dapk.st.core.Lce
import app.dapk.st.core.extensions.ErrorTracker import app.dapk.st.core.extensions.ErrorTracker
@ -95,7 +96,9 @@ class ProfileViewModel(
fun rejectRoomInvite(roomId: RoomId) { fun rejectRoomInvite(roomId: RoomId) {
launchCatching { roomService.rejectJoinRoom(roomId) }.fold( launchCatching { roomService.rejectJoinRoom(roomId) }.fold(
onError = {} onError = {
Log.e("!!!", it.message, it)
}
) )
} }

View File

@ -9,6 +9,7 @@ import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.common.RoomMember import app.dapk.st.matrix.common.RoomMember
import app.dapk.st.matrix.common.UserId import app.dapk.st.matrix.common.UserId
import app.dapk.st.matrix.room.internal.DefaultRoomService import app.dapk.st.matrix.room.internal.DefaultRoomService
import app.dapk.st.matrix.room.internal.RoomInviteRemover
import app.dapk.st.matrix.room.internal.RoomMembers import app.dapk.st.matrix.room.internal.RoomMembers
import app.dapk.st.matrix.room.internal.RoomMembersCache import app.dapk.st.matrix.room.internal.RoomMembersCache
@ -40,9 +41,16 @@ interface RoomService : MatrixService {
fun MatrixServiceInstaller.installRoomService( fun MatrixServiceInstaller.installRoomService(
memberStore: MemberStore, memberStore: MemberStore,
roomMessenger: ServiceDepFactory<RoomMessenger>, roomMessenger: ServiceDepFactory<RoomMessenger>,
roomInviteRemover: RoomInviteRemover,
) { ) {
this.install { (httpClient, _, services, logger) -> this.install { (httpClient, _, services, logger) ->
SERVICE_KEY to DefaultRoomService(httpClient, logger, RoomMembers(memberStore, RoomMembersCache()), roomMessenger.create(services)) SERVICE_KEY to DefaultRoomService(
httpClient,
logger,
RoomMembers(memberStore, RoomMembersCache()),
roomMessenger.create(services),
roomInviteRemover
)
} }
} }

View File

@ -8,6 +8,8 @@ import app.dapk.st.matrix.http.emptyJsonBody
import app.dapk.st.matrix.http.jsonBody import app.dapk.st.matrix.http.jsonBody
import app.dapk.st.matrix.room.RoomMessenger import app.dapk.st.matrix.room.RoomMessenger
import app.dapk.st.matrix.room.RoomService import app.dapk.st.matrix.room.RoomService
import io.ktor.client.plugins.*
import io.ktor.http.*
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@ -16,7 +18,9 @@ class DefaultRoomService(
private val logger: MatrixLogger, private val logger: MatrixLogger,
private val roomMembers: RoomMembers, private val roomMembers: RoomMembers,
private val roomMessenger: RoomMessenger, private val roomMessenger: RoomMessenger,
private val roomInviteRemover: RoomInviteRemover,
) : RoomService { ) : RoomService {
override suspend fun joinedMembers(roomId: RoomId): List<RoomService.JoinedMember> { override suspend fun joinedMembers(roomId: RoomId): List<RoomService.JoinedMember> {
val response = httpClient.execute(joinedMembersRequest(roomId)) val response = httpClient.execute(joinedMembersRequest(roomId))
return response.joined.map { (userId, member) -> return response.joined.map { (userId, member) ->
@ -68,7 +72,23 @@ class DefaultRoomService(
} }
override suspend fun rejectJoinRoom(roomId: RoomId) { override suspend fun rejectJoinRoom(roomId: RoomId) {
httpClient.execute(rejectJoinRoomRequest(roomId)) runCatching { httpClient.execute(rejectJoinRoomRequest(roomId)) }.fold(
onSuccess = {},
onFailure = {
when (it) {
is ClientRequestException -> {
if (it.response.status == HttpStatusCode.Forbidden) {
// allow error
} else {
throw it
}
}
else -> throw it
}
}
)
roomInviteRemover.remove(roomId)
} }
} }

View File

@ -0,0 +1,7 @@
package app.dapk.st.matrix.room.internal
import app.dapk.st.matrix.common.RoomId
fun interface RoomInviteRemover {
suspend fun remove(roomId: RoomId)
}