feat: fetch uncached messages in replies
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
226b455730
commit
2e977ff1e8
|
|
@ -170,4 +170,14 @@ suspend fun createInvite(channelId: String): CreateInviteResponse {
|
|||
if (error.type != "Server") throw Error(error.type)
|
||||
|
||||
return RevoltJson.decodeFromString(CreateInviteResponse.serializer(), response)
|
||||
}
|
||||
|
||||
suspend fun fetchSingleMessage(channelId: String, messageId: String): Message {
|
||||
val response = RevoltHttp.get("/channels/$channelId/messages/$messageId")
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
Message.serializer(),
|
||||
response
|
||||
)
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import androidx.compose.material3.LocalContentColor
|
|||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
|
|
@ -25,11 +26,13 @@ import androidx.compose.ui.unit.sp
|
|||
import chat.revolt.R
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.internals.solidColor
|
||||
import chat.revolt.api.routes.channel.fetchSingleMessage
|
||||
import chat.revolt.api.schemas.User
|
||||
import chat.revolt.components.generic.UserAvatar
|
||||
|
||||
@Composable
|
||||
fun InReplyTo(
|
||||
channelId: String,
|
||||
messageId: String,
|
||||
modifier: Modifier = Modifier,
|
||||
withMention: Boolean = false,
|
||||
|
|
@ -46,6 +49,12 @@ fun InReplyTo(
|
|||
val usernameColor =
|
||||
message?.let { authorColour(it) } ?: Brush.solidColor(contentColor)
|
||||
|
||||
LaunchedEffect(messageId) {
|
||||
if (messageId !in RevoltAPI.messageCache) {
|
||||
RevoltAPI.messageCache[messageId] = fetchSingleMessage(channelId, messageId)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
|
|
@ -96,19 +105,32 @@ fun InReplyTo(
|
|||
}
|
||||
)
|
||||
|
||||
Text(
|
||||
text = message.content ?: "",
|
||||
fontSize = 12.sp,
|
||||
color = contentColor.copy(alpha = 0.7f),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
if (message.content.isNullOrBlank()) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.reply_message_empty_has_attachments),
|
||||
// TODO: inter has italics now, import and use them
|
||||
fontStyle = FontStyle.Italic, // inter doesn't have italics...
|
||||
fontSize = 12.sp,
|
||||
fontFamily = FontFamily.Default, // ...so we use the default font
|
||||
color = contentColor.copy(alpha = 0.7f),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = message.content,
|
||||
fontSize = 12.sp,
|
||||
color = contentColor.copy(alpha = 0.7f),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Text(
|
||||
text = stringResource(id = R.string.reply_message_not_cached),
|
||||
fontStyle = FontStyle.Italic, // inter doesn't have italics...
|
||||
fontStyle = FontStyle.Italic, // inter _still_ doesn't have italics...
|
||||
color = contentColor.copy(alpha = 0.7f),
|
||||
fontFamily = FontFamily.Default, // ...so we use the defaul t font
|
||||
fontFamily = FontFamily.Default, // ...so we use the default font
|
||||
fontSize = 12.sp,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
|
|
|
|||
|
|
@ -65,10 +65,10 @@ import chat.revolt.activities.media.ImageViewActivity
|
|||
import chat.revolt.activities.media.VideoViewActivity
|
||||
import chat.revolt.api.REVOLT_FILES
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.internals.BrushCompat
|
||||
import chat.revolt.api.internals.Roles
|
||||
import chat.revolt.api.internals.SpecialUsers
|
||||
import chat.revolt.api.internals.ULID
|
||||
import chat.revolt.api.internals.BrushCompat
|
||||
import chat.revolt.api.internals.solidColor
|
||||
import chat.revolt.api.routes.channel.react
|
||||
import chat.revolt.api.routes.channel.unreact
|
||||
|
|
@ -212,18 +212,21 @@ fun Message(
|
|||
message.replies?.forEach { reply ->
|
||||
val replyMessage = RevoltAPI.messageCache[reply]
|
||||
|
||||
InReplyTo(
|
||||
messageId = reply,
|
||||
withMention = replyMessage?.author?.let {
|
||||
message.mentions?.contains(
|
||||
replyMessage.author
|
||||
)
|
||||
}
|
||||
?: false
|
||||
) {
|
||||
// TODO Add jump to message
|
||||
if (replyMessage == null) {
|
||||
Toast.makeText(context, "lmao prankd", Toast.LENGTH_SHORT).show()
|
||||
message.channel?.let { chId ->
|
||||
InReplyTo(
|
||||
channelId = chId,
|
||||
messageId = reply,
|
||||
withMention = replyMessage?.author?.let {
|
||||
message.mentions?.contains(
|
||||
replyMessage.author
|
||||
)
|
||||
}
|
||||
?: false
|
||||
) {
|
||||
// TODO Add jump to message
|
||||
if (replyMessage == null) {
|
||||
Toast.makeText(context, "lmao prankd", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@
|
|||
<string name="message_field_denied_no_permission">You don\'t have permission to send messages in this channel.</string>
|
||||
<string name="message_field_denied_platform_moderation">This is a trusted channel for notices from our moderation team. You can\'t send messages here.</string>
|
||||
|
||||
<string name="reply_message_not_cached">Unknown message, tap to jump</string>
|
||||
<string name="reply_message_not_cached">Unknown message</string>
|
||||
<string name="reply_message_empty_has_attachments">Sent attachments</string>
|
||||
|
||||
<string name="system_message_ownership_changed_alt">Ownership changed</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue