Skip to content

Commit

Permalink
try to fix xqt timeline crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Jan 31, 2024
1 parent 2572998 commit 44cd3f8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import app.cash.sqldelight.ColumnAdapter
import dev.dimension.flare.common.decodeJson
import dev.dimension.flare.common.encodeJson
import kotlinx.serialization.KSerializer
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

@OptIn(ExperimentalEncodingApi::class)
internal class JsonColumnAdapter<T : Any>(
private val serializer: KSerializer<T>,
) : ColumnAdapter<T, String> {
override fun decode(databaseValue: String): T = databaseValue.decodeJson(serializer)
override fun decode(databaseValue: String): T = Base64.decode(databaseValue).decodeToString().decodeJson(serializer)

override fun encode(value: T) = value.encodeJson(serializer)
override fun encode(value: T) = Base64.encode(value.encodeJson(serializer).encodeToByteArray())
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import kotlinx.serialization.Serializable
@Serializable
internal data class Url(
@SerialName(value = "display_url")
val displayUrl: kotlin.String,
val displayUrl: kotlin.String? = null,
@Contextual @SerialName(value = "expanded_url")
val expandedUrl: String,
val expandedUrl: String? = null,
@SerialName(value = "indices")
val indices: kotlin.collections.List<kotlin.Int>,
val indices: kotlin.collections.List<kotlin.Int>? = null,
@Contextual @SerialName(value = "url")
val url: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.dimension.flare.ui.model.mapper

import de.cketti.codepoints.deluxe.codePointSequence
import dev.dimension.flare.common.encodeJson
import dev.dimension.flare.data.network.xqt.model.GetProfileSpotlightsQuery200Response
import dev.dimension.flare.data.network.xqt.model.Media
import dev.dimension.flare.data.network.xqt.model.Tweet
Expand Down Expand Up @@ -51,7 +50,7 @@ internal fun Tweet.toUi(accountKey: MicroBlogKey): UiStatus.XQT {
is UserUnavailable -> null
}
}?.toUi()
requireNotNull(user)
requireNotNull(user) { "user is null" }
val uiCard =
card?.legacy?.let {
val title = it.get("title")?.stringValue
Expand Down Expand Up @@ -156,33 +155,33 @@ internal fun Tweet.toUi(accountKey: MicroBlogKey): UiStatus.XQT {
accountKey = accountKey,
statusKey =
MicroBlogKey(
id = legacy?.idStr ?: throw Exception("no id for tweet: ${this.encodeJson()}"),
id = legacy?.idStr ?: restId,
host = accountKey.host,
),
user = user,
createdAt = parseCustomDateTime(legacy.createdAt) ?: Clock.System.now(),
createdAt = legacy?.createdAt?.let { parseCustomDateTime(it) } ?: Clock.System.now(),
content = text,
medias = medias,
card = uiCard,
matrices =
UiStatus.XQT.Matrices(
replyCount = legacy.replyCount.toLong(),
likeCount = legacy.favoriteCount.toLong(),
retweetCount = legacy.retweetCount.toLong(),
replyCount = legacy?.replyCount?.toLong() ?: 0,
likeCount = legacy?.favoriteCount?.toLong() ?: 0,
retweetCount = legacy?.retweetCount?.toLong() ?: 0,
),
reaction =
UiStatus.XQT.Reaction(
liked = legacy.favorited,
retweeted = legacy.retweeted,
bookmarked = legacy.bookmarked ?: false,
liked = legacy?.favorited ?: false,
retweeted = legacy?.retweeted ?: false,
bookmarked = legacy?.bookmarked ?: false,
),
retweet = retweet,
quote = quote,
inReplyToScreenName = legacy.in_reply_to_screen_name,
inReplyToStatusId = legacy.in_reply_to_status_id_str,
inReplyToUserId = legacy.in_reply_to_user_id_str,
inReplyToScreenName = legacy?.in_reply_to_screen_name,
inReplyToStatusId = legacy?.in_reply_to_status_id_str,
inReplyToUserId = legacy?.in_reply_to_user_id_str,
poll = poll,
sensitive = legacy.possiblySensitive == true,
sensitive = legacy?.possiblySensitive == true,
raw = this,
)
}
Expand Down
15 changes: 15 additions & 0 deletions shared/src/commonMain/sqldelight/cache/migrations/1.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dev.dimension.flare.data.database.cache.model.StatusContent;
import dev.dimension.flare.model.MicroBlogKey;
import dev.dimension.flare.model.PlatformType;

DROP TABLE IF EXISTS DbStatus;

CREATE TABLE IF NOT EXISTS DbStatus (
id INTEGER PRIMARY KEY AUTOINCREMENT,
status_key TEXT AS MicroBlogKey NOT NULL,
account_key TEXT AS MicroBlogKey NOT NULL,
user_key TEXT AS MicroBlogKey,
platform_type TEXT AS PlatformType NOT NULL,
content TEXT AS StatusContent NOT NULL,
UNIQUE (status_key, account_key)
);

0 comments on commit 44cd3f8

Please sign in to comment.