1
Fork 0
mirror of https://github.com/Steffo99/twom.git synced 2024-11-21 23:54:26 +00:00

Add support for uninviting

This commit is contained in:
Steffo 2024-01-20 13:42:02 +01:00
parent 23de2ed278
commit 4a084519ce
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -17,6 +17,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
@ -28,6 +29,7 @@ import eu.steffo.twom.composables.avatar.AvatarUser
import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.matrix.LocalSession
import eu.steffo.twom.utils.RSVPAnswer
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
import org.matrix.android.sdk.api.session.user.model.User
import kotlin.jvm.optionals.getOrNull
@ -73,6 +75,8 @@ fun MemberListItem(
Log.d("UserListItem", "Resolved user: $memberId")
}
val scope = rememberCoroutineScope()
val rsvp = observeRSVP(room = room, member = member) ?: return
var expanded by rememberSaveable { mutableStateOf(false) }
@ -132,7 +136,25 @@ fun MemberListItem(
text = {
Text(stringResource(R.string.room_uninvite_label))
},
onClick = { expanded = false },
onClick = {
expanded = false
scope.launch SendUninvite@{
val userId = member.userId
Log.d("Room", "Uninviting `$userId`...")
// FIXME: Errors for this aren't displayed as I don't have any idea of where to place the relevant text on the UI, but also are so unlikely to occour that it should be ok to disregard it
try {
room.membershipService().remove(userId)
} catch (e: Throwable) {
Log.e("Room", "Failed to uninvite `$userId`: $e")
return@SendUninvite
}
Log.d("Room", "Successfully uninvited `$userId`!")
}
},
)
}
}