refactor: Enhance API URL handling and profile image retrieval
This commit updates the `RevoltAPI` to include a new `autumn` URL and modifies the `ProfileSettingsScreenViewModel` to utilize the new method for retrieving profile images and backgrounds. Key changes include: - Added `autumn` URL to the `PlatformUrls` data class and updated the `PLATFORM_URLS` map. - Refactored image URL construction in `ProfileSettingsScreenViewModel` to use `RevoltAPI.getCurrentAutumnUrl()` for dynamic URL generation. These changes improve code maintainability and ensure consistent URL handling across the application.
This commit is contained in:
parent
8b693c737b
commit
586c98f443
|
|
@ -73,6 +73,7 @@ data class PlatformUrls(
|
|||
val app: String,
|
||||
val invites: String,
|
||||
val websocket: String,
|
||||
val autumn: String,
|
||||
val kjbook: String
|
||||
)
|
||||
|
||||
|
|
@ -86,16 +87,18 @@ private val PLATFORM_URLS = mapOf(
|
|||
app = "https://app.revolt.chat",
|
||||
invites = "https://rvlt.gg",
|
||||
websocket = "wss://ws.revolt.chat",
|
||||
autumn = "https://autumn.revolt.chat",
|
||||
kjbook = "https://revoltchat.github.io/android"
|
||||
),
|
||||
ApplicationPlatform.PEP to PlatformUrls(
|
||||
base = "https://api.pep.chat/0.8",
|
||||
marketing = "https://pep.chat",
|
||||
base = "https://a-pep.peptide.chat/api",
|
||||
marketing = "https://peptide.chat",
|
||||
files = "https://cdn.pepusercontent.com",
|
||||
january = "https://jan.pep.chat",
|
||||
app = "https://app.pep.chat",
|
||||
january = "https://a-pep.peptide.chat/january",
|
||||
app = "https://peptide.chat",
|
||||
invites = "https://pep.gg",
|
||||
websocket = "wss://ws.pep.chat",
|
||||
websocket = "https://a-pep.peptide.chat/ws",
|
||||
autumn = "https://autumn.revolt.chat",
|
||||
kjbook = "https://pepchat.github.io/android"
|
||||
)
|
||||
)
|
||||
|
|
@ -258,6 +261,7 @@ object RevoltAPI {
|
|||
fun getCurrentAppUrl(): String = getUrlForPlatform(selectedApplicationPlatform) { it.app }
|
||||
fun getCurrentInvitesUrl(): String = getUrlForPlatform(selectedApplicationPlatform) { it.invites }
|
||||
fun getCurrentWebSocketUrl(): String = getUrlForPlatform(selectedApplicationPlatform) { it.websocket }
|
||||
fun getCurrentAutumnUrl(): String = getUrlForPlatform(selectedApplicationPlatform) { it.autumn }
|
||||
fun getCurrentKjBookUrl(): String = getUrlForPlatform(selectedApplicationPlatform) { it.kjbook }
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class, ExperimentalCoroutinesApi::class)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ import androidx.compose.foundation.layout.size
|
|||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
|
|
@ -79,12 +77,12 @@ class ProfileSettingsScreenViewModel @Inject constructor(@ApplicationContext val
|
|||
init {
|
||||
RevoltAPI.selfId?.let { self ->
|
||||
RevoltAPI.userCache[self]?.avatar?.id?.let {
|
||||
pfpModel = "https://autumn.revolt.chat/avatars/${it}"
|
||||
pfpModel = "${RevoltAPI.getCurrentAutumnUrl()}/avatars/${it}"
|
||||
}
|
||||
viewModelScope.launch {
|
||||
currentProfile = fetchUserProfile(self)
|
||||
currentProfile!!.background?.id?.let {
|
||||
backgroundModel = "https://autumn.revolt.chat/backgrounds/${it}"
|
||||
backgroundModel = "${RevoltAPI.getCurrentAutumnUrl()}/backgrounds/${it}"
|
||||
}
|
||||
|
||||
pendingProfile = currentProfile!!.copy()
|
||||
|
|
@ -139,7 +137,7 @@ class ProfileSettingsScreenViewModel @Inject constructor(@ApplicationContext val
|
|||
}
|
||||
|
||||
pfpModel = RevoltAPI.userCache[RevoltAPI.selfId]?.avatar?.id?.let {
|
||||
"https://autumn.revolt.chat/avatars/${it}"
|
||||
"${RevoltAPI.getCurrentAutumnUrl()}/avatars/${it}"
|
||||
}
|
||||
|
||||
uploadProgress = 0f
|
||||
|
|
@ -194,8 +192,8 @@ class ProfileSettingsScreenViewModel @Inject constructor(@ApplicationContext val
|
|||
currentProfile = profile
|
||||
pendingProfile = profile
|
||||
|
||||
profile.background?.id?.let {
|
||||
"https://autumn.revolt.chat/backgrounds/${it}"
|
||||
profile.background?.id?.let { id ->
|
||||
"${RevoltAPI.getCurrentAutumnUrl()}/backgrounds/${id}"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue