parent
d8953a4eb6
commit
46b75c3ed3
|
|
@ -8,6 +8,7 @@ import chat.revolt.api.schemas.Channel
|
||||||
import chat.revolt.api.schemas.Message
|
import chat.revolt.api.schemas.Message
|
||||||
import chat.revolt.api.schemas.MessagesInChannel
|
import chat.revolt.api.schemas.MessagesInChannel
|
||||||
import chat.revolt.api.schemas.User
|
import chat.revolt.api.schemas.User
|
||||||
|
import io.ktor.client.request.delete
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.request.parameter
|
import io.ktor.client.request.parameter
|
||||||
import io.ktor.client.request.patch
|
import io.ktor.client.request.patch
|
||||||
|
|
@ -133,6 +134,10 @@ suspend fun editMessage(channelId: String, messageId: String, newContent: String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun deleteMessage(channelId: String, messageId: String) {
|
||||||
|
RevoltHttp.delete("/channels/$channelId/messages/$messageId")
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun ackChannel(channelId: String, messageId: String = ULID.makeNext()) {
|
suspend fun ackChannel(channelId: String, messageId: String = ULID.makeNext()) {
|
||||||
RevoltHttp.put("/channels/$channelId/ack/$messageId")
|
RevoltHttp.put("/channels/$channelId/ack/$messageId")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,15 @@ import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
@ -39,6 +42,10 @@ import androidx.compose.ui.unit.dp
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
import chat.revolt.api.REVOLT_APP
|
import chat.revolt.api.REVOLT_APP
|
||||||
import chat.revolt.api.RevoltAPI
|
import chat.revolt.api.RevoltAPI
|
||||||
|
import chat.revolt.api.internals.PermissionBit
|
||||||
|
import chat.revolt.api.internals.Roles
|
||||||
|
import chat.revolt.api.internals.has
|
||||||
|
import chat.revolt.api.routes.channel.deleteMessage
|
||||||
import chat.revolt.api.routes.channel.react
|
import chat.revolt.api.routes.channel.react
|
||||||
import chat.revolt.callbacks.UiCallbacks
|
import chat.revolt.callbacks.UiCallbacks
|
||||||
import chat.revolt.components.chat.Message
|
import chat.revolt.components.chat.Message
|
||||||
|
|
@ -71,6 +78,7 @@ fun MessageContextSheet(
|
||||||
|
|
||||||
var showShareSheet by remember { mutableStateOf(false) }
|
var showShareSheet by remember { mutableStateOf(false) }
|
||||||
var showReactSheet by remember { mutableStateOf(false) }
|
var showReactSheet by remember { mutableStateOf(false) }
|
||||||
|
var showDeleteMessageConfirmation by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
if (showShareSheet) {
|
if (showShareSheet) {
|
||||||
val shareSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
val shareSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||||
|
|
@ -260,6 +268,52 @@ fun MessageContextSheet(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showDeleteMessageConfirmation) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = {
|
||||||
|
showDeleteMessageConfirmation = false
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.message_context_sheet_actions_delete_confirmation_title)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.message_context_sheet_actions_delete_confirmation_body)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
message.channel?.let { channelId ->
|
||||||
|
deleteMessage(channelId, messageId)
|
||||||
|
}
|
||||||
|
|
||||||
|
onHideSheet()
|
||||||
|
}
|
||||||
|
showDeleteMessageConfirmation = false
|
||||||
|
coroutineScope.launch {
|
||||||
|
onHideSheet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.message_context_sheet_actions_delete_confirmation_yes))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
showDeleteMessageConfirmation = false
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text(stringResource(R.string.message_context_sheet_actions_delete_confirmation_no))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
|
|
@ -388,30 +442,32 @@ fun MessageContextSheet(
|
||||||
showShareSheet = true
|
showShareSheet = true
|
||||||
}
|
}
|
||||||
|
|
||||||
SheetClickable(
|
if (
|
||||||
icon = { modifier ->
|
(message.channel?.let {
|
||||||
Icon(
|
val channel = RevoltAPI.channelCache[it] ?: return@let null
|
||||||
imageVector = Icons.Default.Delete,
|
Roles.permissionFor(
|
||||||
contentDescription = null,
|
channel,
|
||||||
modifier = modifier
|
RevoltAPI.userCache[RevoltAPI.selfId]
|
||||||
)
|
)
|
||||||
},
|
} ?: 0) has PermissionBit.ManageMessages || message.author == RevoltAPI.selfId
|
||||||
label = { style ->
|
|
||||||
Text(
|
|
||||||
text = stringResource(id = R.string.message_context_sheet_actions_delete),
|
|
||||||
style = style
|
|
||||||
)
|
|
||||||
},
|
|
||||||
dangerous = true
|
|
||||||
) {
|
) {
|
||||||
Toast.makeText(
|
SheetClickable(
|
||||||
context,
|
icon = { modifier ->
|
||||||
context.getString(R.string.comingsoon_toast),
|
Icon(
|
||||||
Toast.LENGTH_SHORT
|
imageVector = Icons.Default.Delete,
|
||||||
).show()
|
contentDescription = null,
|
||||||
|
modifier = modifier
|
||||||
coroutineScope.launch {
|
)
|
||||||
onHideSheet()
|
},
|
||||||
|
label = { style ->
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.message_context_sheet_actions_delete),
|
||||||
|
style = style
|
||||||
|
)
|
||||||
|
},
|
||||||
|
dangerous = true
|
||||||
|
) {
|
||||||
|
showDeleteMessageConfirmation = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,11 @@
|
||||||
<string name="message_context_sheet_actions_report">Report</string>
|
<string name="message_context_sheet_actions_report">Report</string>
|
||||||
<string name="message_context_sheet_actions_mark_unread">Mark as unread</string>
|
<string name="message_context_sheet_actions_mark_unread">Mark as unread</string>
|
||||||
|
|
||||||
|
<string name="message_context_sheet_actions_delete_confirmation_title">Delete message?</string>
|
||||||
|
<string name="message_context_sheet_actions_delete_confirmation_body">It will be gone forever (a long time!)</string>
|
||||||
|
<string name="message_context_sheet_actions_delete_confirmation_yes">Delete</string>
|
||||||
|
<string name="message_context_sheet_actions_delete_confirmation_no">Keep</string>
|
||||||
|
|
||||||
<string name="channel_context_sheet_actions_copy_id">Copy ID</string>
|
<string name="channel_context_sheet_actions_copy_id">Copy ID</string>
|
||||||
<string name="channel_context_sheet_actions_copy_id_copied">Copied channel ID to clipboard</string>
|
<string name="channel_context_sheet_actions_copy_id_copied">Copied channel ID to clipboard</string>
|
||||||
<string name="channel_context_sheet_actions_mark_read">Mark as read</string>
|
<string name="channel_context_sheet_actions_mark_read">Mark as read</string>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue