refactor: move message processor to frontend internals

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-08-15 02:04:14 +02:00
parent 63c443f121
commit 08b6e99302
3 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
package chat.revolt.api.internals package chat.revolt.internals.text
import chat.revolt.api.RevoltAPI import chat.revolt.api.RevoltAPI
import chat.revolt.api.schemas.ChannelType import chat.revolt.api.schemas.ChannelType
@ -7,7 +7,7 @@ import chat.revolt.internals.EmojiImpl
object MessageProcessor { object MessageProcessor {
private val MentionRegex = Regex("@((?:\\p{L}|[\\d_.-])+)#([0-9]{4})", RegexOption.IGNORE_CASE) private val MentionRegex = Regex("@((?:\\p{L}|[\\d_.-])+)#([0-9]{4})", RegexOption.IGNORE_CASE)
private val ChannelRegex = Regex("(?:\\s|^)#(.+?)(?:\\s|\$)", RegexOption.IGNORE_CASE) private val ChannelRegex = Regex("(?:\\s|^)#(.+?)(?:\\s|\$)", RegexOption.IGNORE_CASE)
private val EmojiRegex = Regex(":([a-zA-Z0-9_+-]+):", RegexOption.IGNORE_CASE) private val EmoteRegex = Regex(":([a-zA-Z0-9_+-]+):", RegexOption.IGNORE_CASE)
val emoji = EmojiImpl() val emoji = EmojiImpl()
@ -46,13 +46,13 @@ object MessageProcessor {
fetchedChannel.name?.let { acc.replace("#${it}", "<#${fetchedChannel.id}>") } ?: acc fetchedChannel.name?.let { acc.replace("#${it}", "<#${fetchedChannel.id}>") } ?: acc
} }
val emojis = EmojiRegex.findAll(returnable).map { it.value }.toList() val emojis = EmoteRegex.findAll(returnable).map { it.value }.toList()
returnable = emojis.fold(returnable) { acc, emoji -> returnable = emojis.fold(returnable) { acc, emoji ->
val emojiName = EmojiRegex.matchEntire(emoji)?.destructured?.component1() val emojiName = EmoteRegex.matchEntire(emoji)?.destructured?.component1()
?: return@fold acc ?: return@fold acc
val byShortcode = this.emoji.unicodeByShortcode(emojiName) val byShortcode = MessageProcessor.emoji.unicodeByShortcode(emojiName)
?: return@fold acc ?: return@fold acc
acc.replace(":$emojiName:", byShortcode) acc.replace(":$emojiName:", byShortcode)

View File

@ -13,7 +13,7 @@ import chat.revolt.R
import chat.revolt.api.RevoltAPI import chat.revolt.api.RevoltAPI
import chat.revolt.api.RevoltJson import chat.revolt.api.RevoltJson
import chat.revolt.api.internals.ChannelUtils import chat.revolt.api.internals.ChannelUtils
import chat.revolt.api.internals.MessageProcessor import chat.revolt.internals.text.MessageProcessor
import chat.revolt.api.internals.PermissionBit import chat.revolt.api.internals.PermissionBit
import chat.revolt.api.internals.Roles import chat.revolt.api.internals.Roles
import chat.revolt.api.internals.SpecialUsers import chat.revolt.api.internals.SpecialUsers

View File

@ -37,7 +37,7 @@ import androidx.compose.ui.unit.sp
import chat.revolt.R import chat.revolt.R
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.MessageProcessor import chat.revolt.internals.text.MessageProcessor
import chat.revolt.api.internals.isUlid import chat.revolt.api.internals.isUlid
import chat.revolt.api.routes.custom.fetchEmoji import chat.revolt.api.routes.custom.fetchEmoji
import chat.revolt.api.routes.user.fetchUser import chat.revolt.api.routes.user.fetchUser