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:
parent
40461f692f
commit
ee91de4301
|
@ -303,6 +303,7 @@ internal class MatrixModules(
|
|||
}
|
||||
}
|
||||
|
||||
val overviewStore = store.overviewStore()
|
||||
installRoomService(
|
||||
storeModule.value.memberStore(),
|
||||
roomMessenger = {
|
||||
|
@ -316,6 +317,9 @@ internal class MatrixModules(
|
|||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
roomInviteRemover = {
|
||||
overviewStore.removeInvites(listOf(it))
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -323,7 +327,7 @@ internal class MatrixModules(
|
|||
|
||||
installSyncService(
|
||||
credentialsStore,
|
||||
store.overviewStore(),
|
||||
overviewStore,
|
||||
store.roomStore(),
|
||||
store.syncStore(),
|
||||
store.filterStore(),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package app.dapk.st.profile
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.dapk.st.core.Lce
|
||||
import app.dapk.st.core.extensions.ErrorTracker
|
||||
|
@ -95,7 +96,9 @@ class ProfileViewModel(
|
|||
|
||||
fun rejectRoomInvite(roomId: RoomId) {
|
||||
launchCatching { roomService.rejectJoinRoom(roomId) }.fold(
|
||||
onError = {}
|
||||
onError = {
|
||||
Log.e("!!!", it.message, it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import app.dapk.st.matrix.common.RoomId
|
|||
import app.dapk.st.matrix.common.RoomMember
|
||||
import app.dapk.st.matrix.common.UserId
|
||||
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.RoomMembersCache
|
||||
|
||||
|
@ -40,9 +41,16 @@ interface RoomService : MatrixService {
|
|||
fun MatrixServiceInstaller.installRoomService(
|
||||
memberStore: MemberStore,
|
||||
roomMessenger: ServiceDepFactory<RoomMessenger>,
|
||||
roomInviteRemover: RoomInviteRemover,
|
||||
) {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import app.dapk.st.matrix.http.emptyJsonBody
|
|||
import app.dapk.st.matrix.http.jsonBody
|
||||
import app.dapk.st.matrix.room.RoomMessenger
|
||||
import app.dapk.st.matrix.room.RoomService
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.http.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
@ -16,7 +18,9 @@ class DefaultRoomService(
|
|||
private val logger: MatrixLogger,
|
||||
private val roomMembers: RoomMembers,
|
||||
private val roomMessenger: RoomMessenger,
|
||||
private val roomInviteRemover: RoomInviteRemover,
|
||||
) : RoomService {
|
||||
|
||||
override suspend fun joinedMembers(roomId: RoomId): List<RoomService.JoinedMember> {
|
||||
val response = httpClient.execute(joinedMembersRequest(roomId))
|
||||
return response.joined.map { (userId, member) ->
|
||||
|
@ -68,7 +72,23 @@ class DefaultRoomService(
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue