Skip to content

Commit e7ca3b1

Browse files
committed
Make cache account specific and fix oauth parsing
1 parent eea4a64 commit e7ca3b1

6 files changed

Lines changed: 25 additions & 16 deletions

File tree

shared/src/commonMain/kotlin/site/remlit/snowdrop/App.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import com.russhwolf.settings.ExperimentalSettingsApi
4242
import io.kamel.image.KamelImage
4343
import io.kamel.image.asyncPainterResource
4444
import io.kamel.image.config.LocalKamelConfig
45+
import io.ktor.http.Url
4546
import kotlinx.serialization.Serializable
4647
import org.jetbrains.compose.resources.painterResource
4748
import site.remlit.snowdrop.component.AppTheme
@@ -57,6 +58,7 @@ import site.remlit.snowdrop.util.scrollingUpward
5758
import site.remlit.snowdrop.util.settings
5859
import site.remlit.snowdrop.util.setupAppSettings
5960
import site.remlit.snowdrop.util.cache.setupCache
61+
import site.remlit.snowdrop.util.safeReturnable
6062
import site.remlit.snowdrop.view.*
6163
import site.remlit.snowdrop.view.settings.*
6264
import snowdrop.shared.generated.resources.Res
@@ -122,13 +124,11 @@ fun App() = safe {
122124

123125
DisposableEffect(Unit) {
124126
ExternalUriHandler.listener = { uri ->
125-
Logger.d { "URI received: $uri" }
127+
val parsed = safeReturnable { Url(uri) }
128+
Logger.d { "URI received & parsed: $parsed" }
126129

127-
if (uri.startsWith("snowdrop://oauth-callback?code="))
128-
blockingSettings.putString(
129-
"oauth_callback",
130-
uri.replace("snowdrop://oauth-callback?code=", "")
131-
)
130+
if (parsed?.host == "oauth-callback" && parsed.parameters.contains("code"))
131+
blockingSettings.putString("oauth_callback", parsed.parameters["code"]!!)
132132

133133
// if any other URIs need to be configured, they can be added here
134134
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package site.remlit.snowdrop.api
2+
3+
fun getInstance(auth: Boolean = false) {
4+
5+
}

shared/src/commonMain/kotlin/site/remlit/snowdrop/model/InstanceV1.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,15 @@ data class InstanceV1(
8484
data class MediaAttachments(
8585
@SerialName("supported_mine_types")
8686
val supportedMimeTypes: List<String> = emptyList(),
87+
@SerialName("image_size_limit")
8788
val imageSizeLimit: Int = 0,
89+
@SerialName("image_matrix_limit")
8890
val imageMatrixLimit: Int = 0,
91+
@SerialName("video_size_limit")
8992
val videoSizeLimit: Int = 0,
93+
@SerialName("video_frame_limit")
9094
val videoFrameLimit: Int = 0,
95+
@SerialName("video_matrix_limit")
9196
val videoMatrixLimit: Int = 0,
9297
)
9398

shared/src/commonMain/kotlin/site/remlit/snowdrop/util/Settings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fun setupAppSettings() {
5555
* */
5656
@OptIn(ExperimentalSettingsApi::class)
5757
fun getCurrentAccountObjectFlow(): Flow<Account> = flow {
58-
if (getCurrentAccountId() == "")
58+
if (!settings.getBoolean("logged_in", false))
5959
return@flow
6060

6161
if (getCacheEntry("account_${getCurrentAccountId()}") == null)

shared/src/commonMain/kotlin/site/remlit/snowdrop/util/cache/Cache.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import site.remlit.snowdrop.model.cache.CacheEntry
1010
import site.remlit.snowdrop.model.cache.CacheManifest
1111
import site.remlit.snowdrop.util.config.cbor
1212
import site.remlit.snowdrop.util.config.json
13+
import site.remlit.snowdrop.util.getCurrentAccountId
1314

1415
/* I don't think this will be used, but i'm keeping it just in case */
1516
@OptIn(ExperimentalSettingsApi::class)
@@ -21,23 +22,23 @@ val blockingCache = cache.toBlockingSettings()
2122

2223
@OptIn(ExperimentalSerializationApi::class)
2324
fun setupCache() {
24-
if (blockingCache.hasKey("manifest")) return
25+
if (blockingCache.hasKey("${getCurrentAccountId()}_manifest")) return
2526
blockingCache.putString(
26-
"manifest",
27+
"${getCurrentAccountId()}_manifest",
2728
cbor.encodeToHexString(CacheManifest())
2829
)
2930
}
3031

3132
@OptIn(ExperimentalSerializationApi::class)
3233
fun getCacheManifest(): CacheManifest {
33-
val raw = blockingCache.getStringOrNull("manifest")
34+
val raw = blockingCache.getStringOrNull("${getCurrentAccountId()}_manifest")
3435
?: return CacheManifest()
3536
return cbor.decodeFromHexString(raw)
3637
}
3738

3839
@OptIn(ExperimentalSerializationApi::class)
3940
fun getCacheEntry(id: String): CacheEntry? {
40-
val raw = blockingCache.getStringOrNull("entry_$id")
41+
val raw = blockingCache.getStringOrNull("${getCurrentAccountId()}_entry_$id")
4142
?: return null
4243
return cbor.decodeFromHexString(raw)
4344
}
@@ -54,14 +55,14 @@ inline fun <reified T> putCacheEntry(
5455

5556
val manifest = getCacheManifest()
5657
blockingCache.putString(
57-
"manifest",
58+
"${getCurrentAccountId()}_manifest",
5859
cbor.encodeToHexString(
5960
manifest.copy(ids = manifest.ids.plus(id).distinct())
6061
)
6162
)
6263

6364
blockingCache.putString(
64-
"entry_$id",
65+
"${getCurrentAccountId()}_entry_$id",
6566
cbor.encodeToHexString(entry)
6667
)
6768
}

shared/src/commonMain/kotlin/site/remlit/snowdrop/view/LoginView.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ fun LoginView(
128128
navigateToTimeline()
129129
}
130130

131-
if (!oauthCallbackCode.isNullOrBlank()) {
132-
Logger.e("MEOW! CONTENT IS $oauthCallbackCode")
131+
if (!oauthCallbackCode.isNullOrBlank())
133132
finishButtonPressed()
134-
}
135133

136134
if (!continued) {
137135
Column(

0 commit comments

Comments
 (0)