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

Add a mechanism for accepting invites

This commit is contained in:
Steffo 2024-01-21 16:23:58 +01:00
parent 23e70fe7ea
commit b66cb24a7f
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 49 additions and 12 deletions

View file

@ -29,7 +29,7 @@ fun MainContentLoggedIn(
val roomSummaries by session.roomService().getRoomSummariesLive( val roomSummaries by session.roomService().getRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN, Membership.INVITE)
this.includeType = listOf(TwoMGlobals.ROOM_TYPE) this.includeType = listOf(TwoMGlobals.ROOM_TYPE)
} }
).observeAsState() ).observeAsState()

View file

@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ListItem import androidx.compose.material3.ListItem
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -29,6 +30,7 @@ import eu.steffo.twom.composables.errorhandling.ErrorText
import eu.steffo.twom.composables.errorhandling.LocalizableError import eu.steffo.twom.composables.errorhandling.LocalizableError
import eu.steffo.twom.composables.matrix.LocalSession import eu.steffo.twom.composables.matrix.LocalSession
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
@ -52,9 +54,23 @@ fun RoomListItem(
var expanded by rememberSaveable { mutableStateOf(false) } var expanded by rememberSaveable { mutableStateOf(false) }
val error by remember { mutableStateOf(LocalizableError()) } val error by remember { mutableStateOf(LocalizableError()) }
// TODO: Display a running indicator
val viewRoomActivityLauncher = rememberLauncherForActivityResult(ViewRoomActivity.Contract()) {} val viewRoomActivityLauncher = rememberLauncherForActivityResult(ViewRoomActivity.Contract()) {}
fun openRoom() { suspend fun openRoom() {
if (roomSummary.membership == Membership.INVITE) {
Log.i("Main", "Opening invite `$roomId`...")
try {
session.roomService().joinRoom(roomId, "Opened the invite")
} catch (e: Throwable) {
Log.e("Main", "Failed to open invite to room `$roomId`: $error")
error.set(R.string.main_error_join_generic, e)
return
}
Log.d("Main", "Successfully opened invite to room `$roomId`!")
}
Log.i("Main", "Opening room `$roomId`...") Log.i("Main", "Opening room `$roomId`...")
viewRoomActivityLauncher.launch(roomId) viewRoomActivityLauncher.launch(roomId)
} }
@ -71,15 +87,20 @@ fun RoomListItem(
Log.d("Main", "Successfully left room `$roomId`!") Log.d("Main", "Successfully left room `$roomId`!")
} }
val alpha = if (roomSummary.membership == Membership.INVITE) 0.4f else 1.0f
Box { Box {
ListItem( ListItem(
modifier = Modifier.combinedClickable( modifier = Modifier.combinedClickable(
onClick = { openRoom() }, onClick = { scope.launch { openRoom() } },
onLongClick = { expanded = true } onLongClick = { expanded = true }
), ),
headlineContent = { headlineContent = {
Text(roomSummary.displayName) Text(
text = roomSummary.displayName,
color = LocalContentColor.current.copy(alpha)
)
}, },
leadingContent = { leadingContent = {
Box( Box(
@ -90,17 +111,24 @@ fun RoomListItem(
AvatarURL( AvatarURL(
// FIXME: URL can appearently be set before the image is available on the homeserver // FIXME: URL can appearently be set before the image is available on the homeserver
url = roomSummary.avatarUrl, url = roomSummary.avatarUrl,
alpha = alpha,
) )
} }
}, },
supportingContent = { supportingContent = {
val count = roomSummary.joinedMembersCount val count = roomSummary.joinedMembersCount
if (count != null) { if (count != null) {
if (count != 1) { Text(
Text(stringResource(R.string.main_partecipants, count)) text = stringResource(
id = if (count != 1) {
R.string.main_partecipants
} else { } else {
Text(stringResource(R.string.main_partecipant, count)) R.string.main_partecipant
} },
count,
),
color = LocalContentColor.current.copy(alpha)
)
} }
}, },
) )
@ -112,7 +140,15 @@ fun RoomListItem(
// TODO: Align me to the right // TODO: Align me to the right
DropdownMenuItem( DropdownMenuItem(
text = { text = {
Text(stringResource(id = R.string.main_room_leave_label)) Text(
stringResource(
id = if (roomSummary.membership == Membership.INVITE) {
R.string.main_room_reject_label
} else {
R.string.main_room_leave_label
}
)
)
}, },
onClick = { onClick = {
expanded = false expanded = false
@ -120,6 +156,5 @@ fun RoomListItem(
} }
) )
} }
} }
} }

View file

@ -1,6 +1,6 @@
<resources> <resources>
<string name="app_name">TwoM</string> <string name="app_name">TwoM</string>
<string name="room_name_fallback_members_0">Partying with myself</string> <string name="room_name_fallback_members_0">A brand new party</string>
<string name="room_name_fallback_members_1">Partying with %1$s</string> <string name="room_name_fallback_members_1">Partying with %1$s</string>
<string name="room_name_fallback_members_2">Partying with %1$s and %2$s</string> <string name="room_name_fallback_members_2">Partying with %1$s and %2$s</string>
<string name="room_name_fallback_members_3">Partying with %1$s, %2$s, and %3$s</string> <string name="room_name_fallback_members_3">Partying with %1$s, %2$s, and %3$s</string>
@ -87,4 +87,6 @@
<string name="edit_title">Editing %1$s</string> <string name="edit_title">Editing %1$s</string>
<string name="main_partecipants">%1$d partecipants</string> <string name="main_partecipants">%1$d partecipants</string>
<string name="main_partecipant">%1$d partecipant</string> <string name="main_partecipant">%1$d partecipant</string>
<string name="main_room_reject_label">Reject invite</string>
<string name="main_error_join_generic">Something went wrong while opening the invite: %1$s</string>
</resources> </resources>