feat: catch invite urls
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
d9b6ebfd95
commit
6f44c03cc0
|
|
@ -1,5 +1,9 @@
|
||||||
package chat.revolt.api.schemas
|
package chat.revolt.api.schemas
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import chat.revolt.api.REVOLT_APP
|
||||||
|
import chat.revolt.api.REVOLT_INVITES
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
@ -45,3 +49,16 @@ data class InviteJoined(
|
||||||
val channels: List<Channel>? = null,
|
val channels: List<Channel>? = null,
|
||||||
val server: Server? = null
|
val server: Server? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun Uri.isInviteUri(): Boolean {
|
||||||
|
val firstPathSegmentIsInvite = this.pathSegments.firstOrNull() == "invite"
|
||||||
|
val isAppRevoltChat = this.host == REVOLT_APP.toUri().host
|
||||||
|
val matchRvltGG = this.host == REVOLT_INVITES.toUri().host
|
||||||
|
|
||||||
|
val matchApp = isAppRevoltChat && firstPathSegmentIsInvite
|
||||||
|
|
||||||
|
val hasEnoughSegments =
|
||||||
|
if (matchApp) this.pathSegments.size == 2 else this.pathSegments.size == 1
|
||||||
|
|
||||||
|
return (matchApp || matchRvltGG) && hasEnoughSegments
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package chat.revolt.components.markdown
|
package chat.revolt.components.markdown
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
|
|
@ -35,9 +36,11 @@ import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
|
import chat.revolt.activities.InviteActivity
|
||||||
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.routes.custom.fetchEmoji
|
import chat.revolt.api.routes.custom.fetchEmoji
|
||||||
|
import chat.revolt.api.schemas.isInviteUri
|
||||||
import chat.revolt.callbacks.Action
|
import chat.revolt.callbacks.Action
|
||||||
import chat.revolt.callbacks.ActionChannel
|
import chat.revolt.callbacks.ActionChannel
|
||||||
import chat.revolt.components.generic.RemoteImage
|
import chat.revolt.components.generic.RemoteImage
|
||||||
|
|
@ -286,6 +289,22 @@ fun MarkdownText(textNode: AstNode, modifier: Modifier = Modifier) {
|
||||||
end = offset
|
end = offset
|
||||||
).firstOrNull()?.let { annotation ->
|
).firstOrNull()?.let { annotation ->
|
||||||
val url = annotation.item
|
val url = annotation.item
|
||||||
|
|
||||||
|
try {
|
||||||
|
val uri = url.toUri()
|
||||||
|
if (uri.isInviteUri()) {
|
||||||
|
scope.launch {
|
||||||
|
Intent(context, InviteActivity::class.java).apply {
|
||||||
|
data = uri
|
||||||
|
context.startActivity(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@handler true
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
val customTab = CustomTabsIntent.Builder()
|
val customTab = CustomTabsIntent.Builder()
|
||||||
.setShowTitle(true)
|
.setShowTitle(true)
|
||||||
.setDefaultColorSchemeParams(
|
.setDefaultColorSchemeParams(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue