feat: highlight if mention, fix avatar padding

Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
Infi 2023-06-06 00:48:44 +02:00
parent f778a0502c
commit 8d143dffd1
1 changed files with 150 additions and 134 deletions

View File

@ -12,6 +12,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -145,161 +146,176 @@ fun Message(
Spacer(modifier = Modifier.height(10.dp)) Spacer(modifier = Modifier.height(10.dp))
} }
message.replies?.forEach { reply -> Column(
val replyMessage = RevoltAPI.messageCache[reply] modifier = Modifier.then(
if (message.mentions?.contains(RevoltAPI.selfId) == true) {
InReplyTo( Modifier.background(
messageId = reply, MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
withMention = replyMessage?.author?.let {
message.mentions?.contains(
replyMessage.author
) )
} else {
Modifier
} }
?: false, )
) {
// TODO Add jump to message
if (replyMessage == null) {
Toast.makeText(context, "lmao prankd", Toast.LENGTH_SHORT).show()
}
}
}
Row(
modifier = Modifier
.combinedClickable(
onClick = {},
onDoubleClick = {
onReply()
},
onLongClick = {
onMessageContextMenu()
}
)
.padding(horizontal = 10.dp)
.fillMaxWidth()
) { ) {
if (message.tail == false) { message.replies?.forEach { reply ->
UserAvatar( val replyMessage = RevoltAPI.messageCache[reply]
username = author.username ?: "",
userId = author.id ?: message.id ?: ULID.makeSpecial(0), InReplyTo(
avatar = author.avatar, messageId = reply,
rawUrl = message.masquerade?.avatar?.let { asJanuaryProxyUrl(it) } withMention = replyMessage?.author?.let {
) message.mentions?.contains(
} else { replyMessage.author
UserAvatarWidthPlaceholder() )
}
?: false,
) {
// TODO Add jump to message
if (replyMessage == null) {
Toast.makeText(context, "lmao prankd", Toast.LENGTH_SHORT).show()
}
}
} }
Column(modifier = Modifier.padding(start = 10.dp)) { Row(
modifier = Modifier
.combinedClickable(
onClick = {},
onDoubleClick = {
onReply()
},
onLongClick = {
onMessageContextMenu()
}
)
.padding(horizontal = 10.dp)
.fillMaxWidth()
) {
if (message.tail == false) { if (message.tail == false) {
Row(verticalAlignment = Alignment.CenterVertically) { Column {
Text( Spacer(modifier = Modifier.height(4.dp))
text = authorName(message), UserAvatar(
fontWeight = FontWeight.Bold, username = author.username ?: "",
color = authorColour(message), userId = author.id ?: message.id ?: ULID.makeSpecial(0),
maxLines = 1, avatar = author.avatar,
overflow = TextOverflow.Ellipsis rawUrl = message.masquerade?.avatar?.let { asJanuaryProxyUrl(it) }
) )
}
} else {
UserAvatarWidthPlaceholder()
}
InlineBadges( Column(modifier = Modifier.padding(start = 10.dp)) {
bot = author.bot != null && message.masquerade == null, if (message.tail == false) {
bridge = message.masquerade != null && author.bot != null, Row(verticalAlignment = Alignment.CenterVertically) {
colour = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f), Text(
modifier = Modifier.size(16.dp), text = authorName(message),
precedingIfAny = { fontWeight = FontWeight.Bold,
Spacer(modifier = Modifier.width(5.dp)) color = authorColour(message),
} maxLines = 1,
) overflow = TextOverflow.Ellipsis
Spacer(modifier = Modifier.width(5.dp))
Text(
text = formatLongAsTime(ULID.asTimestamp(message.id!!), context),
fontSize = 12.sp,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Spacer(modifier = Modifier.width(2.dp))
if (message.edited != null) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(id = R.string.edited),
tint = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f),
modifier = Modifier.size(16.dp)
) )
}
}
}
message.content?.let { InlineBadges(
if (message.content.isBlank()) return@let // if only an attachment is sent bot = author.bot != null && message.masquerade == null,
bridge = message.masquerade != null && author.bot != null,
AndroidView(factory = { ctx -> colour = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f),
androidx.appcompat.widget.AppCompatTextView(ctx).apply { modifier = Modifier.size(16.dp),
text = parse(message) precedingIfAny = {
maxLines = if (truncate) 1 else Int.MAX_VALUE Spacer(modifier = Modifier.width(5.dp))
ellipsize = TextUtils.TruncateAt.END
textSize = 16f
typeface = ResourcesCompat.getFont(ctx, R.font.inter)
setTextColor(contentColor.toArgb())
}
})
}
message.attachments?.let {
message.attachments.forEach { attachment ->
Spacer(modifier = Modifier.height(2.dp))
MessageAttachment(attachment) {
when (attachment.metadata?.type) {
"Image" -> {
attachmentView.launch(
Intent(context, ImageViewActivity::class.java).apply {
putExtra("autumnResource", attachment)
}
)
} }
)
"Video" -> { Spacer(modifier = Modifier.width(5.dp))
attachmentView.launch(
Intent(context, VideoViewActivity::class.java).apply {
putExtra("autumnResource", attachment)
}
)
}
"Audio" -> { Text(
/* no-op */ text = formatLongAsTime(ULID.asTimestamp(message.id!!), context),
} fontSize = 12.sp,
color = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
else -> { Spacer(modifier = Modifier.width(2.dp))
viewAttachmentInBrowser(context, attachment)
} if (message.edited != null) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(id = R.string.edited),
tint = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.5f),
modifier = Modifier.size(16.dp)
)
} }
} }
Spacer(modifier = Modifier.height(2.dp))
} }
}
message.embeds?.let { message.content?.let {
message.embeds.forEach { embed -> if (message.content.isBlank()) return@let // if only an attachment is sent
val embedIsEmpty =
embed.title == null && embed.description == null && embed.iconURL == null && embed.image == null
if (embedIsEmpty) { AndroidView(factory = { ctx ->
// if we do not emit anything, compose will cause an internal error. androidx.appcompat.widget.AppCompatTextView(ctx).apply {
// FIXME if you are doing fixme's anyways then check if this is still an issue text = parse(message)
Box {} maxLines = if (truncate) 1 else Int.MAX_VALUE
return@forEach ellipsize = TextUtils.TruncateAt.END
} textSize = 16f
typeface = ResourcesCompat.getFont(ctx, R.font.inter)
Spacer(modifier = Modifier.height(8.dp)) setTextColor(contentColor.toArgb())
Embed(embed = embed, onLinkClick = { }
viewUrlInBrowser(context, it)
}) })
Spacer(modifier = Modifier.height(8.dp)) }
message.attachments?.let {
message.attachments.forEach { attachment ->
Spacer(modifier = Modifier.height(2.dp))
MessageAttachment(attachment) {
when (attachment.metadata?.type) {
"Image" -> {
attachmentView.launch(
Intent(context, ImageViewActivity::class.java).apply {
putExtra("autumnResource", attachment)
}
)
}
"Video" -> {
attachmentView.launch(
Intent(context, VideoViewActivity::class.java).apply {
putExtra("autumnResource", attachment)
}
)
}
"Audio" -> {
/* no-op */
}
else -> {
viewAttachmentInBrowser(context, attachment)
}
}
}
Spacer(modifier = Modifier.height(2.dp))
}
}
message.embeds?.let {
message.embeds.forEach { embed ->
val embedIsEmpty =
embed.title == null && embed.description == null && embed.iconURL == null && embed.image == null
if (embedIsEmpty) {
// if we do not emit anything, compose will cause an internal error.
// FIXME if you are doing fixme's anyways then check if this is still an issue
Box {}
return@forEach
}
Spacer(modifier = Modifier.height(8.dp))
Embed(embed = embed, onLinkClick = {
viewUrlInBrowser(context, it)
})
Spacer(modifier = Modifier.height(8.dp))
}
} }
} }
} }