feat: support next API version
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
28858ecde8
commit
0696f1a8de
|
|
@ -45,6 +45,7 @@ import chat.revolt.api.RevoltHttp
|
|||
import chat.revolt.api.routes.onboard.needsOnboarding
|
||||
import chat.revolt.api.settings.GlobalState
|
||||
import chat.revolt.api.settings.SyncedSettings
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.ndk.NativeLibraries
|
||||
import chat.revolt.persistence.KVStorage
|
||||
import chat.revolt.screens.DefaultDestinationScreen
|
||||
|
|
@ -111,7 +112,7 @@ class MainActivityViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun canReachRevolt(): Boolean {
|
||||
val res = RevoltHttp.get("/")
|
||||
val res = RevoltHttp.get("/".api())
|
||||
return res.status.value == 200
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import java.lang.reflect.InvocationTargetException
|
|||
import java.net.SocketException
|
||||
import chat.revolt.api.schemas.Channel as ChannelSchema
|
||||
|
||||
const val REVOLT_BASE = "https://api.revolt.chat"
|
||||
const val REVOLT_BASE = "https://revolt.chat/api"
|
||||
const val REVOLT_SUPPORT = "https://support.revolt.chat"
|
||||
const val REVOLT_MARKETING = "https://revolt.chat"
|
||||
const val REVOLT_FILES = "https://autumn.revolt.chat"
|
||||
|
|
@ -59,6 +59,10 @@ const val REVOLT_INVITES = "https://rvlt.gg"
|
|||
const val REVOLT_WEBSOCKET = "wss://ws.revolt.chat"
|
||||
const val REVOLT_KJBOOK = "https://revoltchat.github.io/android"
|
||||
|
||||
fun String.api(): String {
|
||||
return "$REVOLT_BASE$this"
|
||||
}
|
||||
|
||||
fun buildUserAgent(accessMethod: String = "Ktor"): String {
|
||||
return "$accessMethod RevoltAndroid/${BuildConfig.VERSION_NAME} ${BuildConfig.APPLICATION_ID} (Android ${android.os.Build.VERSION.SDK_INT}; ${android.os.Build.MANUFACTURER} ${android.os.Build.DEVICE}; (Kotlin ${KotlinVersion.CURRENT})"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.util.Log
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
|
|
@ -109,7 +110,7 @@ data class EmailPasswordAssessment(
|
|||
suspend fun negotiateAuthentication(email: String, password: String): EmailPasswordAssessment {
|
||||
val sessionName = friendlySessionName()
|
||||
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login") {
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(LoginNegotiation(email, password, sessionName, null))
|
||||
}
|
||||
|
|
@ -152,7 +153,7 @@ suspend fun authenticateWithMfaTotpCode(
|
|||
mfaTicket: String,
|
||||
mfaResponse: MfaResponseTotpCode
|
||||
): EmailPasswordAssessment {
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login") {
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(LoginMfaAmendmentTotpCode(mfaTicket, mfaResponse, friendlySessionName()))
|
||||
}
|
||||
|
|
@ -176,7 +177,7 @@ suspend fun authenticateWithMfaRecoveryCode(
|
|||
mfaTicket: String,
|
||||
mfaResponse: MfaResponseRecoveryCode
|
||||
): EmailPasswordAssessment {
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login") {
|
||||
val response: HttpResponse = RevoltHttp.post("/auth/session/login".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(LoginMfaAmendmentRecoveryCode(mfaTicket, mfaResponse, friendlySessionName()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import chat.revolt.api.RevoltError
|
|||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.schemas.RsResult
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
|
|
@ -21,7 +22,7 @@ data class RegistrationBody(
|
|||
)
|
||||
|
||||
suspend fun register(body: RegistrationBody): RsResult<Unit, RevoltError> {
|
||||
val response = RevoltHttp.post("/auth/account/create") {
|
||||
val response = RevoltHttp.post("/auth/account/create".api()) {
|
||||
setBody(body)
|
||||
contentType(ContentType.Application.Json)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package chat.revolt.api.routes.auth
|
|||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Session
|
||||
import io.ktor.client.request.delete
|
||||
import io.ktor.client.request.get
|
||||
|
|
@ -10,7 +11,7 @@ import io.ktor.client.statement.bodyAsText
|
|||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
suspend fun fetchAllSessions(): List<Session> {
|
||||
val response = RevoltHttp.get("/auth/session/all")
|
||||
val response = RevoltHttp.get("/auth/session/all".api())
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
|
|
@ -20,11 +21,11 @@ suspend fun fetchAllSessions(): List<Session> {
|
|||
}
|
||||
|
||||
suspend fun logoutSessionById(id: String) {
|
||||
RevoltHttp.delete("/auth/session/$id")
|
||||
RevoltHttp.delete("/auth/session/$id".api())
|
||||
}
|
||||
|
||||
suspend fun logoutAllSessions(includingSelf: Boolean = false) {
|
||||
RevoltHttp.delete("/auth/session/all") {
|
||||
RevoltHttp.delete("/auth/session/all".api()) {
|
||||
parameter("revoke_self", includingSelf)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import chat.revolt.api.RevoltAPI
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.internals.ULID
|
||||
import chat.revolt.api.schemas.Channel
|
||||
import chat.revolt.api.schemas.Message
|
||||
|
|
@ -36,7 +37,7 @@ suspend fun fetchMessagesFromChannel(
|
|||
nearby: String? = null,
|
||||
sort: String? = null
|
||||
): MessagesInChannel {
|
||||
val response = RevoltHttp.get("/channels/$channelId/messages") {
|
||||
val response = RevoltHttp.get("/channels/$channelId/messages".api()) {
|
||||
parameter("limit", limit)
|
||||
parameter("include_users", includeUsers)
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ suspend fun sendMessage(
|
|||
attachments: List<String>? = null,
|
||||
idempotencyKey: String = ULID.makeNext()
|
||||
): String {
|
||||
val response = RevoltHttp.post("/channels/$channelId/messages") {
|
||||
val response = RevoltHttp.post("/channels/$channelId/messages".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(
|
||||
SendMessageBody(
|
||||
|
|
@ -121,7 +122,7 @@ suspend fun sendMessage(
|
|||
}
|
||||
|
||||
suspend fun editMessage(channelId: String, messageId: String, newContent: String? = null) {
|
||||
val response = RevoltHttp.patch("/channels/$channelId/messages/$messageId") {
|
||||
val response = RevoltHttp.patch("/channels/$channelId/messages/$messageId".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(
|
||||
EditMessageBody(
|
||||
|
|
@ -140,15 +141,15 @@ suspend fun editMessage(channelId: String, messageId: String, newContent: String
|
|||
}
|
||||
|
||||
suspend fun deleteMessage(channelId: String, messageId: String) {
|
||||
RevoltHttp.delete("/channels/$channelId/messages/$messageId")
|
||||
RevoltHttp.delete("/channels/$channelId/messages/$messageId".api())
|
||||
}
|
||||
|
||||
suspend fun ackChannel(channelId: String, messageId: String = ULID.makeNext()) {
|
||||
RevoltHttp.put("/channels/$channelId/ack/$messageId")
|
||||
RevoltHttp.put("/channels/$channelId/ack/$messageId".api())
|
||||
}
|
||||
|
||||
suspend fun fetchSingleChannel(channelId: String): Channel {
|
||||
val response = RevoltHttp.get("/channels/$channelId")
|
||||
val response = RevoltHttp.get("/channels/$channelId".api())
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
|
|
@ -158,7 +159,7 @@ suspend fun fetchSingleChannel(channelId: String): Channel {
|
|||
}
|
||||
|
||||
suspend fun fetchGroupParticipants(channelId: String): List<User> {
|
||||
val response = RevoltHttp.get("/channels/$channelId/members")
|
||||
val response = RevoltHttp.get("/channels/$channelId/members".api())
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
|
|
@ -168,7 +169,7 @@ suspend fun fetchGroupParticipants(channelId: String): List<User> {
|
|||
}
|
||||
|
||||
suspend fun createInvite(channelId: String): CreateInviteResponse {
|
||||
val response = RevoltHttp.post("/channels/$channelId/invites")
|
||||
val response = RevoltHttp.post("/channels/$channelId/invites".api())
|
||||
.bodyAsText()
|
||||
|
||||
val error = RevoltJson.decodeFromString(RevoltError.serializer(), response)
|
||||
|
|
@ -178,7 +179,7 @@ suspend fun createInvite(channelId: String): CreateInviteResponse {
|
|||
}
|
||||
|
||||
suspend fun fetchSingleMessage(channelId: String, messageId: String): Message {
|
||||
val response = RevoltHttp.get("/channels/$channelId/messages/$messageId")
|
||||
val response = RevoltHttp.get("/channels/$channelId/messages/$messageId".api())
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
|
|
@ -188,7 +189,7 @@ suspend fun fetchSingleMessage(channelId: String, messageId: String): Message {
|
|||
}
|
||||
|
||||
suspend fun leaveDeleteOrCloseChannel(channelId: String, leaveSilently: Boolean = false) {
|
||||
RevoltHttp.delete("/channels/$channelId") {
|
||||
RevoltHttp.delete("/channels/$channelId".api()) {
|
||||
parameter("leave_silently", leaveSilently)
|
||||
}
|
||||
}
|
||||
|
|
@ -229,7 +230,7 @@ suspend fun patchChannel(
|
|||
body["nsfw"] = RevoltJson.encodeToJsonElement(Boolean.serializer(), nsfw)
|
||||
}
|
||||
|
||||
val response = RevoltHttp.patch("/channels/$channelId") {
|
||||
val response = RevoltHttp.patch("/channels/$channelId".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(
|
||||
RevoltJson.encodeToString(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package chat.revolt.api.routes.channel
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Channel
|
||||
import chat.revolt.screens.create.MAX_ADDABLE_PEOPLE_IN_GROUP
|
||||
import io.ktor.client.request.delete
|
||||
|
|
@ -27,7 +28,7 @@ suspend fun createGroupDM(name: String, members: List<String>): Channel {
|
|||
throw Exception("Too many members, maximum is $MAX_ADDABLE_PEOPLE_IN_GROUP")
|
||||
}
|
||||
|
||||
val response = RevoltHttp.post("/channels/create") {
|
||||
val response = RevoltHttp.post("/channels/create".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(CreateGroupDMBody(name, members))
|
||||
}.bodyAsText()
|
||||
|
|
@ -43,7 +44,7 @@ suspend fun createGroupDM(name: String, members: List<String>): Channel {
|
|||
}
|
||||
|
||||
suspend fun removeMember(channelId: String, userId: String) {
|
||||
val response = RevoltHttp.delete("/channels/$channelId/recipients/$userId")
|
||||
val response = RevoltHttp.delete("/channels/$channelId/recipients/$userId".api())
|
||||
|
||||
if (!response.status.isSuccess()) {
|
||||
throw Error(response.status.toString())
|
||||
|
|
@ -51,7 +52,7 @@ suspend fun removeMember(channelId: String, userId: String) {
|
|||
}
|
||||
|
||||
suspend fun addMember(channelId: String, userId: String) {
|
||||
val response = RevoltHttp.put("/channels/$channelId/recipients/$userId")
|
||||
val response = RevoltHttp.put("/channels/$channelId/recipients/$userId".api())
|
||||
|
||||
if (!response.status.isSuccess()) {
|
||||
throw Error(response.status.toString())
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package chat.revolt.api.routes.channel
|
||||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.delete
|
||||
import io.ktor.client.request.put
|
||||
|
||||
suspend fun react(channelId: String, messageId: String, emoji: String) {
|
||||
RevoltHttp.put("/channels/$channelId/messages/$messageId/reactions/$emoji")
|
||||
RevoltHttp.put("/channels/$channelId/messages/$messageId/reactions/$emoji".api())
|
||||
}
|
||||
|
||||
suspend fun unreact(channelId: String, messageId: String, emoji: String) {
|
||||
RevoltHttp.delete("/channels/$channelId/messages/$messageId/reactions/$emoji")
|
||||
RevoltHttp.delete("/channels/$channelId/messages/$messageId/reactions/$emoji".api())
|
||||
}
|
||||
|
|
@ -2,12 +2,13 @@ package chat.revolt.api.routes.custom
|
|||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Emoji
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
|
||||
suspend fun fetchEmoji(id: String): Emoji {
|
||||
val response = RevoltHttp.get("/custom/emoji/$id").bodyAsText()
|
||||
val response = RevoltHttp.get("/custom/emoji/$id".api()).bodyAsText()
|
||||
return RevoltJson.decodeFromString(
|
||||
Emoji.serializer(),
|
||||
response
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package chat.revolt.api.routes.invites
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Invite
|
||||
import chat.revolt.api.schemas.InviteJoined
|
||||
import chat.revolt.api.schemas.RsResult
|
||||
|
|
@ -12,7 +13,7 @@ import io.ktor.client.statement.bodyAsText
|
|||
import kotlinx.serialization.SerializationException
|
||||
|
||||
suspend fun fetchInviteByCode(code: String): RsResult<Invite, RevoltError> {
|
||||
val response = RevoltHttp.get("/invites/$code")
|
||||
val response = RevoltHttp.get("/invites/$code".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
@ -27,7 +28,7 @@ suspend fun fetchInviteByCode(code: String): RsResult<Invite, RevoltError> {
|
|||
}
|
||||
|
||||
suspend fun joinInviteByCode(code: String): RsResult<InviteJoined, RevoltError> {
|
||||
val response = RevoltHttp.post("/invites/$code")
|
||||
val response = RevoltHttp.post("/invites/$code".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package chat.revolt.api.routes.misc
|
||||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.request.*
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
|
@ -48,5 +49,5 @@ data class Voso(
|
|||
)
|
||||
|
||||
suspend fun getRootRoute(): Root {
|
||||
return RevoltHttp.get("/").body()
|
||||
return RevoltHttp.get("/".api()).body()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import chat.revolt.api.RevoltAPI
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.RsResult
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.header
|
||||
|
|
@ -23,7 +24,7 @@ data class OnboardingResponse(
|
|||
)
|
||||
|
||||
suspend fun needsOnboarding(sessionToken: String = RevoltAPI.sessionToken): Boolean {
|
||||
val response = RevoltHttp.get("/onboard/hello") {
|
||||
val response = RevoltHttp.get("/onboard/hello".api()) {
|
||||
header(RevoltAPI.TOKEN_HEADER_NAME, sessionToken)
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ suspend fun completeOnboarding(
|
|||
body: OnboardingCompletionBody,
|
||||
sessionToken: String = RevoltAPI.sessionToken
|
||||
): RsResult<Unit, RevoltError> {
|
||||
val response = RevoltHttp.post("/onboard/complete") {
|
||||
val response = RevoltHttp.post("/onboard/complete".api()) {
|
||||
setBody(body)
|
||||
contentType(ContentType.Application.Json)
|
||||
header(RevoltAPI.TOKEN_HEADER_NAME, sessionToken)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package chat.revolt.api.routes.push
|
|||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.routes.account.WebPushData
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.http.ContentType
|
||||
|
|
@ -18,7 +19,7 @@ suspend fun subscribePush(
|
|||
auth = auth
|
||||
)
|
||||
|
||||
RevoltHttp.post("/push/subscribe") {
|
||||
RevoltHttp.post("/push/subscribe".api()) {
|
||||
setBody(data)
|
||||
contentType(ContentType.Application.Json)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import chat.revolt.api.schemas.MessageReport
|
|||
import chat.revolt.api.schemas.ServerReport
|
||||
import chat.revolt.api.schemas.UserReport
|
||||
import chat.revolt.api.schemas.UserReportReason
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
|
|
@ -30,7 +31,7 @@ suspend fun putMessageReport(
|
|||
additional_context = additionalContext
|
||||
)
|
||||
|
||||
val response = RevoltHttp.post("/safety/report") {
|
||||
val response = RevoltHttp.post("/safety/report".api()) {
|
||||
setBody(
|
||||
RevoltJson.encodeToString(
|
||||
FullMessageReport.serializer(),
|
||||
|
|
@ -62,7 +63,7 @@ suspend fun putServerReport(
|
|||
additional_context = additionalContext
|
||||
)
|
||||
|
||||
val response = RevoltHttp.post("/safety/report") {
|
||||
val response = RevoltHttp.post("/safety/report".api()) {
|
||||
setBody(
|
||||
RevoltJson.encodeToString(
|
||||
FullServerReport.serializer(),
|
||||
|
|
@ -94,7 +95,7 @@ suspend fun putUserReport(
|
|||
additional_context = additionalContext
|
||||
)
|
||||
|
||||
val response = RevoltHttp.post("/safety/report") {
|
||||
val response = RevoltHttp.post("/safety/report".api()) {
|
||||
setBody(
|
||||
RevoltJson.encodeToString(
|
||||
FullUserReport.serializer(),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import chat.revolt.api.RevoltAPI
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Member
|
||||
import chat.revolt.api.schemas.User
|
||||
import io.ktor.client.request.delete
|
||||
|
|
@ -21,7 +22,7 @@ data class FetchMembersResponse(
|
|||
)
|
||||
|
||||
suspend fun ackServer(serverId: String) {
|
||||
RevoltHttp.put("/servers/$serverId/ack")
|
||||
RevoltHttp.put("/servers/$serverId/ack".api())
|
||||
}
|
||||
|
||||
suspend fun fetchMembers(
|
||||
|
|
@ -29,7 +30,7 @@ suspend fun fetchMembers(
|
|||
includeOffline: Boolean = false,
|
||||
pure: Boolean = false
|
||||
): FetchMembersResponse {
|
||||
val response = RevoltHttp.get("/servers/$serverId/members") {
|
||||
val response = RevoltHttp.get("/servers/$serverId/members".api()) {
|
||||
parameter("exclude_offline", !includeOffline)
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ suspend fun fetchMembers(
|
|||
}
|
||||
|
||||
suspend fun fetchMember(serverId: String, userId: String, pure: Boolean = false): Member {
|
||||
val response = RevoltHttp.get("/servers/$serverId/members/$userId")
|
||||
val response = RevoltHttp.get("/servers/$serverId/members/$userId".api())
|
||||
|
||||
try {
|
||||
val error = RevoltJson.decodeFromString(RevoltError.serializer(), response.bodyAsText())
|
||||
|
|
@ -86,7 +87,7 @@ suspend fun fetchMember(serverId: String, userId: String, pure: Boolean = false)
|
|||
}
|
||||
|
||||
suspend fun leaveOrDeleteServer(serverId: String, leaveSilently: Boolean = false) {
|
||||
RevoltHttp.delete("/servers/$serverId") {
|
||||
RevoltHttp.delete("/servers/$serverId".api()) {
|
||||
parameter("leave_silently", leaveSilently)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package chat.revolt.api.routes.sync
|
|||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.parameter
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.setBody
|
||||
|
|
@ -17,7 +18,7 @@ import kotlinx.serialization.json.JsonArray
|
|||
data class SyncedSetting(val timestamp: Long, val value: String)
|
||||
|
||||
suspend fun getKeys(vararg keys: String, revoltToken: String): Map<String, SyncedSetting> {
|
||||
val response = RevoltHttp.post("/sync/settings/fetch") {
|
||||
val response = RevoltHttp.post("/sync/settings/fetch".api()) {
|
||||
headers.append(RevoltAPI.TOKEN_HEADER_NAME, revoltToken)
|
||||
|
||||
// format: {"keys": ["key1", "key2"]}
|
||||
|
|
@ -55,7 +56,7 @@ suspend fun getKeys(vararg keys: String): Map<String, SyncedSetting> {
|
|||
}
|
||||
|
||||
suspend fun setKey(key: String, value: String) {
|
||||
RevoltHttp.post("/sync/settings/set") {
|
||||
RevoltHttp.post("/sync/settings/set".api()) {
|
||||
parameter("timestamp", System.currentTimeMillis())
|
||||
|
||||
// format: {"key": "value"}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ package chat.revolt.api.routes.sync
|
|||
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.ChannelUnreadResponse
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
|
||||
suspend fun syncUnreads(): List<ChannelUnreadResponse> {
|
||||
val response = RevoltHttp.get("/sync/unreads")
|
||||
val response = RevoltHttp.get("/sync/unreads".api())
|
||||
.bodyAsText()
|
||||
|
||||
return RevoltJson.decodeFromString(
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ package chat.revolt.api.routes.user
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Channel
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.bodyAsText
|
||||
import kotlinx.serialization.SerializationException
|
||||
|
||||
suspend fun openDM(userId: String): Channel {
|
||||
val response = RevoltHttp.get("/users/$userId/dm")
|
||||
val response = RevoltHttp.get("/users/$userId/dm".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package chat.revolt.api.routes.user
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import io.ktor.client.request.delete
|
||||
import io.ktor.client.request.post
|
||||
import io.ktor.client.request.put
|
||||
|
|
@ -13,7 +14,7 @@ import io.ktor.http.contentType
|
|||
import kotlinx.serialization.SerializationException
|
||||
|
||||
suspend fun blockUser(userId: String) {
|
||||
val response = RevoltHttp.put("/users/$userId/block")
|
||||
val response = RevoltHttp.put("/users/$userId/block".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
@ -25,7 +26,7 @@ suspend fun blockUser(userId: String) {
|
|||
}
|
||||
|
||||
suspend fun unblockUser(userId: String) {
|
||||
val response = RevoltHttp.delete("/users/$userId/block")
|
||||
val response = RevoltHttp.delete("/users/$userId/block".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
@ -37,7 +38,7 @@ suspend fun unblockUser(userId: String) {
|
|||
}
|
||||
|
||||
suspend fun friendUser(username: String) {
|
||||
val response = RevoltHttp.post("/users/friend") {
|
||||
val response = RevoltHttp.post("/users/friend".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(mapOf("username" to username))
|
||||
}
|
||||
|
|
@ -52,7 +53,7 @@ suspend fun friendUser(username: String) {
|
|||
}
|
||||
|
||||
suspend fun acceptFriendRequest(userId: String) {
|
||||
val response = RevoltHttp.put("/users/$userId/friend")
|
||||
val response = RevoltHttp.put("/users/$userId/friend".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
@ -64,7 +65,7 @@ suspend fun acceptFriendRequest(userId: String) {
|
|||
}
|
||||
|
||||
suspend fun unfriendUser(userId: String) {
|
||||
val response = RevoltHttp.delete("/users/$userId/friend")
|
||||
val response = RevoltHttp.delete("/users/$userId/friend".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import chat.revolt.api.RevoltAPI
|
|||
import chat.revolt.api.RevoltError
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.RevoltJson
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.schemas.Profile
|
||||
import chat.revolt.api.schemas.Status
|
||||
import chat.revolt.api.schemas.User
|
||||
|
|
@ -20,7 +21,7 @@ import kotlinx.serialization.builtins.serializer
|
|||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
suspend fun fetchSelf(): User {
|
||||
val response = RevoltHttp.get("/users/@me")
|
||||
val response = RevoltHttp.get("/users/@me".api())
|
||||
.bodyAsText()
|
||||
|
||||
try {
|
||||
|
|
@ -83,7 +84,7 @@ suspend fun patchSelf(
|
|||
body["remove"] = RevoltJson.encodeToJsonElement(ListSerializer(String.serializer()), remove)
|
||||
}
|
||||
|
||||
val response = RevoltHttp.patch("/users/@me") {
|
||||
val response = RevoltHttp.patch("/users/@me".api()) {
|
||||
contentType(ContentType.Application.Json)
|
||||
setBody(
|
||||
RevoltJson.encodeToString(
|
||||
|
|
@ -111,7 +112,7 @@ suspend fun patchSelf(
|
|||
}
|
||||
|
||||
suspend fun fetchUser(id: String): User {
|
||||
val res = RevoltHttp.get("/users/$id")
|
||||
val res = RevoltHttp.get("/users/$id".api())
|
||||
|
||||
if (res.status.value == 404) {
|
||||
return User.getPlaceholder(id)
|
||||
|
|
@ -146,7 +147,7 @@ suspend fun addUserIfUnknown(id: String) {
|
|||
}
|
||||
|
||||
suspend fun fetchUserProfile(id: String): Profile {
|
||||
val res = RevoltHttp.get("/users/$id/profile")
|
||||
val res = RevoltHttp.get("/users/$id/profile".api())
|
||||
|
||||
val response = res.bodyAsText()
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import androidx.navigation.NavController
|
|||
import chat.revolt.R
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.RevoltHttp
|
||||
import chat.revolt.api.api
|
||||
import chat.revolt.api.routes.onboard.needsOnboarding
|
||||
import chat.revolt.components.screens.splash.DisconnectedScreen
|
||||
import chat.revolt.persistence.KVStorage
|
||||
|
|
@ -82,7 +83,7 @@ class SplashScreenViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun canReachRevolt(): Boolean {
|
||||
val res = RevoltHttp.get("/")
|
||||
val res = RevoltHttp.get("/".api())
|
||||
return res.status.value == 200
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue