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)
|
if (error.type != "Server") throw Error(error.type)
|
||||||
|
|
||||||
return RevoltJson.decodeFromString(CreateInviteResponse.serializer(), response)
|
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.LocalTextStyle
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
|
|
@ -25,11 +26,13 @@ import androidx.compose.ui.unit.sp
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
import chat.revolt.api.RevoltAPI
|
import chat.revolt.api.RevoltAPI
|
||||||
import chat.revolt.api.internals.solidColor
|
import chat.revolt.api.internals.solidColor
|
||||||
|
import chat.revolt.api.routes.channel.fetchSingleMessage
|
||||||
import chat.revolt.api.schemas.User
|
import chat.revolt.api.schemas.User
|
||||||
import chat.revolt.components.generic.UserAvatar
|
import chat.revolt.components.generic.UserAvatar
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun InReplyTo(
|
fun InReplyTo(
|
||||||
|
channelId: String,
|
||||||
messageId: String,
|
messageId: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
withMention: Boolean = false,
|
withMention: Boolean = false,
|
||||||
|
|
@ -46,6 +49,12 @@ fun InReplyTo(
|
||||||
val usernameColor =
|
val usernameColor =
|
||||||
message?.let { authorColour(it) } ?: Brush.solidColor(contentColor)
|
message?.let { authorColour(it) } ?: Brush.solidColor(contentColor)
|
||||||
|
|
||||||
|
LaunchedEffect(messageId) {
|
||||||
|
if (messageId !in RevoltAPI.messageCache) {
|
||||||
|
RevoltAPI.messageCache[messageId] = fetchSingleMessage(channelId, messageId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
|
@ -96,19 +105,32 @@ fun InReplyTo(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
if (message.content.isNullOrBlank()) {
|
||||||
text = message.content ?: "",
|
Text(
|
||||||
fontSize = 12.sp,
|
text = stringResource(id = R.string.reply_message_empty_has_attachments),
|
||||||
color = contentColor.copy(alpha = 0.7f),
|
// TODO: inter has italics now, import and use them
|
||||||
maxLines = 1,
|
fontStyle = FontStyle.Italic, // inter doesn't have italics...
|
||||||
overflow = TextOverflow.Ellipsis
|
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 {
|
} else {
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(id = R.string.reply_message_not_cached),
|
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),
|
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,
|
fontSize = 12.sp,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ import chat.revolt.activities.media.ImageViewActivity
|
||||||
import chat.revolt.activities.media.VideoViewActivity
|
import chat.revolt.activities.media.VideoViewActivity
|
||||||
import chat.revolt.api.REVOLT_FILES
|
import chat.revolt.api.REVOLT_FILES
|
||||||
import chat.revolt.api.RevoltAPI
|
import chat.revolt.api.RevoltAPI
|
||||||
|
import chat.revolt.api.internals.BrushCompat
|
||||||
import chat.revolt.api.internals.Roles
|
import chat.revolt.api.internals.Roles
|
||||||
import chat.revolt.api.internals.SpecialUsers
|
import chat.revolt.api.internals.SpecialUsers
|
||||||
import chat.revolt.api.internals.ULID
|
import chat.revolt.api.internals.ULID
|
||||||
import chat.revolt.api.internals.BrushCompat
|
|
||||||
import chat.revolt.api.internals.solidColor
|
import chat.revolt.api.internals.solidColor
|
||||||
import chat.revolt.api.routes.channel.react
|
import chat.revolt.api.routes.channel.react
|
||||||
import chat.revolt.api.routes.channel.unreact
|
import chat.revolt.api.routes.channel.unreact
|
||||||
|
|
@ -212,18 +212,21 @@ fun Message(
|
||||||
message.replies?.forEach { reply ->
|
message.replies?.forEach { reply ->
|
||||||
val replyMessage = RevoltAPI.messageCache[reply]
|
val replyMessage = RevoltAPI.messageCache[reply]
|
||||||
|
|
||||||
InReplyTo(
|
message.channel?.let { chId ->
|
||||||
messageId = reply,
|
InReplyTo(
|
||||||
withMention = replyMessage?.author?.let {
|
channelId = chId,
|
||||||
message.mentions?.contains(
|
messageId = reply,
|
||||||
replyMessage.author
|
withMention = replyMessage?.author?.let {
|
||||||
)
|
message.mentions?.contains(
|
||||||
}
|
replyMessage.author
|
||||||
?: false
|
)
|
||||||
) {
|
}
|
||||||
// TODO Add jump to message
|
?: false
|
||||||
if (replyMessage == null) {
|
) {
|
||||||
Toast.makeText(context, "lmao prankd", Toast.LENGTH_SHORT).show()
|
// 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_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="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="reply_message_empty_has_attachments">Sent attachments</string>
|
||||||
|
|
||||||
<string name="system_message_ownership_changed_alt">Ownership changed</string>
|
<string name="system_message_ownership_changed_alt">Ownership changed</string>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue