Skip to content

Commit

Permalink
Merge pull request #528 from DimensionDev/bugfix/misskey_crash
Browse files Browse the repository at this point in the history
fix misskey timeline wrong quoted display
  • Loading branch information
Tlaster authored Oct 19, 2024
2 parents 0878b7e + 7195ab6 commit af3d313
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,40 +212,40 @@ private fun TopMessageComponent(

is UiTimeline.TopMessage.MessageType.Mastodon ->
when (type) {
UiTimeline.TopMessage.MessageType.Mastodon.Favourite ->
is UiTimeline.TopMessage.MessageType.Mastodon.Favourite ->
stringResource(
id = R.string.mastodon_notification_item_favourited_your_status,
)

UiTimeline.TopMessage.MessageType.Mastodon.Follow ->
is UiTimeline.TopMessage.MessageType.Mastodon.Follow ->
stringResource(
id = R.string.mastodon_notification_item_followed_you,
)

UiTimeline.TopMessage.MessageType.Mastodon.FollowRequest ->
is UiTimeline.TopMessage.MessageType.Mastodon.FollowRequest ->
stringResource(
id = R.string.mastodon_notification_item_requested_follow,
)

UiTimeline.TopMessage.MessageType.Mastodon.Mention ->
is UiTimeline.TopMessage.MessageType.Mastodon.Mention ->
stringResource(
id = R.string.mastodon_notification_item_mentioned_you,
)

UiTimeline.TopMessage.MessageType.Mastodon.Poll ->
is UiTimeline.TopMessage.MessageType.Mastodon.Poll ->
stringResource(id = R.string.mastodon_notification_item_poll_ended)

UiTimeline.TopMessage.MessageType.Mastodon.Reblogged ->
is UiTimeline.TopMessage.MessageType.Mastodon.Reblogged ->
stringResource(
id = R.string.mastodon_notification_item_reblogged_your_status,
)

UiTimeline.TopMessage.MessageType.Mastodon.Status ->
is UiTimeline.TopMessage.MessageType.Mastodon.Status ->
stringResource(
id = R.string.mastodon_notification_item_posted_status,
)

UiTimeline.TopMessage.MessageType.Mastodon.Update ->
is UiTimeline.TopMessage.MessageType.Mastodon.Update ->
stringResource(
id = R.string.mastodon_notification_item_updated_status,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ interface StatusReferenceDao {

@Query("DELETE FROM status_reference WHERE statusKey = :key")
suspend fun delete(key: MicroBlogKey)

@Query("DELETE FROM status_reference WHERE statusKey in (:keys)")
suspend fun delete(keys: List<MicroBlogKey>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ internal object Bluesky {
database.statusDao().insertAll(it)
}
timeline.flatMap { it.status.references }.map { it.reference }.let {
database.statusReferenceDao().delete(it.map { it.statusKey })
database.statusReferenceDao().insertAll(it)
}
database.pagingTimelineDao().insertAll(timeline.map { it.timeline })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal suspend fun saveToDatabase(
database.statusDao().insertAll(it)
}
items.flatMap { it.status.references }.map { it.reference }.let {
database.statusReferenceDao().delete(it.map { it.statusKey })
database.statusReferenceDao().insertAll(it)
}
database.pagingTimelineDao().insertAll(items.map { it.timeline })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal object Misskey {
database.statusDao().insertAll(it)
}
timeline.flatMap { it.status.references }.map { it.reference }.let {
database.statusReferenceDao().delete(it.map { it.statusKey })
database.statusReferenceDao().insertAll(it)
}
database.pagingTimelineDao().insertAll(timeline.map { it.timeline })
Expand Down Expand Up @@ -160,7 +161,11 @@ private fun List<Note>.toDbPagingTimeline(
references =
listOfNotNull(
if (it.renote != null) {
ReferenceType.Retweet to it.renote.toDbStatusWithUser(accountKey)
if (it.text.isNullOrEmpty()) {
ReferenceType.Retweet to it.renote.toDbStatusWithUser(accountKey)
} else {
ReferenceType.Quote to it.renote.toDbStatusWithUser(accountKey)
}
} else {
null
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,37 @@ data class UiTimeline internal constructor(

sealed interface MessageType {
sealed interface Mastodon : MessageType {
data object Reblogged : Mastodon
data class Reblogged(
val id: String,
) : Mastodon

data object Follow : Mastodon
data class Follow(
val id: String,
) : Mastodon

data object Favourite : Mastodon
data class Favourite(
val id: String,
) : Mastodon

data object Mention : Mastodon
data class Mention(
val id: String,
) : Mastodon

data object Poll : Mastodon
data class Poll(
val id: String,
) : Mastodon

data object FollowRequest : Mastodon
data class FollowRequest(
val id: String,
) : Mastodon

data object Status : Mastodon
data class Status(
val id: String,
) : Mastodon

data object Update : Mastodon
data class Update(
val id: String,
) : Mastodon
}

sealed interface Misskey : MessageType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,30 @@ internal fun Notification.render(
)
val topMessageType =
when (type) {
NotificationTypes.Follow -> UiTimeline.TopMessage.MessageType.Mastodon.Follow
NotificationTypes.Favourite -> UiTimeline.TopMessage.MessageType.Mastodon.Favourite
NotificationTypes.Reblog -> UiTimeline.TopMessage.MessageType.Mastodon.Reblogged
NotificationTypes.Mention -> UiTimeline.TopMessage.MessageType.Mastodon.Mention
NotificationTypes.Poll -> UiTimeline.TopMessage.MessageType.Mastodon.Poll
NotificationTypes.FollowRequest -> UiTimeline.TopMessage.MessageType.Mastodon.FollowRequest
NotificationTypes.Status -> UiTimeline.TopMessage.MessageType.Mastodon.Status
NotificationTypes.Update -> UiTimeline.TopMessage.MessageType.Mastodon.Update
NotificationTypes.Follow ->
UiTimeline.TopMessage.MessageType.Mastodon
.Follow(id = id.orEmpty())
NotificationTypes.Favourite ->
UiTimeline.TopMessage.MessageType.Mastodon
.Favourite(id = id.orEmpty())
NotificationTypes.Reblog ->
UiTimeline.TopMessage.MessageType.Mastodon
.Reblogged(id = id.orEmpty())
NotificationTypes.Mention ->
UiTimeline.TopMessage.MessageType.Mastodon
.Mention(id = id.orEmpty())
NotificationTypes.Poll ->
UiTimeline.TopMessage.MessageType.Mastodon
.Poll(id = id.orEmpty())
NotificationTypes.FollowRequest ->
UiTimeline.TopMessage.MessageType.Mastodon
.FollowRequest(id = id.orEmpty())
NotificationTypes.Status ->
UiTimeline.TopMessage.MessageType.Mastodon
.Status(id = id.orEmpty())
NotificationTypes.Update ->
UiTimeline.TopMessage.MessageType.Mastodon
.Update(id = id.orEmpty())
null -> null
}
val topMessage =
Expand Down Expand Up @@ -121,7 +137,9 @@ internal fun Status.render(
UiTimeline.TopMessage(
user = user,
icon = UiTimeline.TopMessage.Icon.Retweet,
type = UiTimeline.TopMessage.MessageType.Mastodon.Reblogged,
type =
UiTimeline.TopMessage.MessageType.Mastodon
.Reblogged(id = id.orEmpty()),
onClicked = {
launcher.launch(
AppDeepLink.Profile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ internal fun Note.render(
UiTimeline.TopMessage(
user = user,
icon = UiTimeline.TopMessage.Icon.Retweet,
type = UiTimeline.TopMessage.MessageType.Mastodon.Reblogged,
type =
UiTimeline.TopMessage.MessageType.Misskey
.Renote(id = id),
onClicked = {
launcher.launch(
AppDeepLink.Profile(
Expand Down

0 comments on commit af3d313

Please sign in to comment.