Skip to content

Commit

Permalink
Merge pull request #491 from DimensionDev/bugfix/status_reactions
Browse files Browse the repository at this point in the history
bugfix for status reaction
  • Loading branch information
Tlaster authored Sep 26, 2024
2 parents 0c18798 + 52d98a6 commit 077e778
Show file tree
Hide file tree
Showing 14 changed files with 728 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private fun StatusActions(
text = action.displayItem.iconText,
color = statusActionItemColor(item = action.displayItem),
withTextMinWidth = index != items.lastIndex,
) {
) { closeMenu ->
action.actions.forEach { subActions ->
if (subActions is StatusAction.Item) {
val color = statusActionItemColor(subActions)
Expand All @@ -550,6 +550,7 @@ private fun StatusActions(
)
},
onClick = {
closeMenu.invoke()
if (subActions is StatusAction.Item.Clickable) {
subActions.onClicked.invoke(
ClickContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal fun StatusRetweetHeaderComponent(
contentDescription = null,
modifier =
Modifier
.size(16.dp),
.size(12.dp),
)
if (user != null) {
Spacer(modifier = Modifier.width(8.dp))
Expand Down

Large diffs are not rendered by default.

270 changes: 261 additions & 9 deletions app/src/main/res/values/strings.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct StatusItemView: View {
case .edit: "pencil"
case .info: "app"
case .reply: "arrowshape.turn.up.left"
case .quote: "quote.bubble.fill"
}
let text = switch onEnum(of: topMessage.type) {
case .bluesky(let data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,18 @@ internal fun List<FeedViewPost>.toDbPagingTimeline(
}
}
val references =
when (val data = it.reason) {
is FeedViewPostReasonUnion.ReasonRepost ->
listOfNotNull(
if (reply != null) {
ReferenceType.Reply to reply
} else {
null
},
ReferenceType.Retweet to status,
).toMap()
else ->
listOfNotNull(
if (reply != null) {
ReferenceType.Reply to reply
} else {
null
},
).toMap()
}
listOfNotNull(
if (reply != null) {
ReferenceType.Reply to reply
} else {
null
},
if (it.reason is FeedViewPostReasonUnion.ReasonRepost) {
ReferenceType.Retweet to it.post.toDbStatusWithUser(accountKey)
} else {
null
},
).toMap()
createDbPagingTimelineWithStatus(
accountKey = accountKey,
pagingKey = pagingKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ class MastodonDataSource(
accountKey = account.accountKey,
cacheDatabase = database,
update = {
it.copy(data = result)
result.reblog?.let { StatusContent.Mastodon(it) } ?: it
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import dev.dimension.flare.data.datasource.microblog.timelinePager
import dev.dimension.flare.data.network.misskey.api.model.AdminAccountsDeleteRequest
import dev.dimension.flare.data.network.misskey.api.model.IPinRequest
import dev.dimension.flare.data.network.misskey.api.model.MuteCreateRequest
import dev.dimension.flare.data.network.misskey.api.model.NotesChildrenRequest
import dev.dimension.flare.data.network.misskey.api.model.NotesCreateRequest
import dev.dimension.flare.data.network.misskey.api.model.NotesCreateRequestPoll
import dev.dimension.flare.data.network.misskey.api.model.NotesReactionsCreateRequest
Expand Down Expand Up @@ -380,11 +379,40 @@ class MisskeyDataSource(

override fun renote(statusKey: MicroBlogKey) {
coroutineScope.launch {
service.notesRenotes(
NotesChildrenRequest(
noteId = statusKey.id,
),
updateStatusUseCase<StatusContent.Misskey>(
statusKey = statusKey,
accountKey = account.accountKey,
cacheDatabase = database,
update = {
it.copy(
data =
it.data.copy(
renoteCount = it.data.renoteCount + 1,
),
)
},
)
runCatching {
service.notesCreate(
NotesCreateRequest(
renoteId = statusKey.id,
),
)
}.onFailure {
updateStatusUseCase<StatusContent.Misskey>(
statusKey = statusKey,
accountKey = account.accountKey,
cacheDatabase = database,
update = {
it.copy(
data =
it.data.copy(
renoteCount = it.data.renoteCount - 1,
),
)
},
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import dev.dimension.flare.data.datasource.microblog.StatusAction
import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.ui.humanizer.humanize
import dev.dimension.flare.ui.model.mapper.MisskeyAchievement
import dev.dimension.flare.ui.render.UiDateTime
import dev.dimension.flare.ui.render.UiRichText
import kotlinx.collections.immutable.ImmutableList

// TODO: Handling item click event internally
@Immutable
data class UiTimeline internal constructor(
val topMessage: TopMessage?,
Expand Down Expand Up @@ -169,6 +169,7 @@ data class UiTimeline internal constructor(
Edit,
Info,
Reply,
Quote,
}

sealed interface MessageType {
Expand All @@ -191,27 +192,50 @@ data class UiTimeline internal constructor(
}

sealed interface Misskey : MessageType {
data object Follow : Misskey
data class Follow(
val id: String,
) : Misskey

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

data object Reply : Misskey
data class Reply(
val id: String,
) : Misskey

data object Renote : Misskey
data class Renote(
val id: String,
) : Misskey

data object Quote : Misskey
data class Quote(
val id: String,
) : Misskey

data object Reaction : Misskey
data class Reaction(
val id: String,
) : Misskey

data object PollEnded : Misskey
data class PollEnded(
val id: String,
) : Misskey

data object ReceiveFollowRequest : Misskey
data class ReceiveFollowRequest(
val id: String,
) : Misskey

data object FollowRequestAccepted : Misskey
data class FollowRequestAccepted(
val id: String,
) : Misskey

data object AchievementEarned : Misskey
data class AchievementEarned(
val id: String,
val achievement: MisskeyAchievement?,
) : Misskey

data object App : Misskey
data class App(
val id: String,
) : Misskey
}

sealed interface Bluesky : MessageType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import app.bsky.richtext.FacetFeatureUnion
import com.fleeksoft.ksoup.nodes.Element
import com.fleeksoft.ksoup.nodes.TextNode
import dev.dimension.flare.common.AppDeepLink
import dev.dimension.flare.data.database.cache.model.StatusContent
import dev.dimension.flare.data.datasource.bluesky.bskyJson
import dev.dimension.flare.data.datasource.microblog.StatusAction
import dev.dimension.flare.data.datasource.microblog.StatusEvent
import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.model.ReferenceType
import dev.dimension.flare.ui.model.UiCard
import dev.dimension.flare.ui.model.UiList
import dev.dimension.flare.ui.model.UiMedia
Expand Down Expand Up @@ -138,10 +140,11 @@ private fun parseBluesky(

internal fun FeedViewPostReasonUnion.render(
accountKey: MicroBlogKey,
data: PostView,
event: StatusEvent.Bluesky,
): UiTimeline =
UiTimeline(
references: Map<ReferenceType, StatusContent>,
): UiTimeline {
val data = (references[ReferenceType.Retweet] as? StatusContent.Bluesky)?.data
return UiTimeline(
topMessage =
(this as? FeedViewPostReasonUnion.ReasonRepost)?.value?.by?.let {
val user = it.render(accountKey)
Expand All @@ -159,9 +162,10 @@ internal fun FeedViewPostReasonUnion.render(
},
)
},
content = data.renderStatus(accountKey, event),
content = data?.renderStatus(accountKey, event),
platformType = PlatformType.Bluesky,
)
}

internal fun ListNotificationsNotification.render(accountKey: MicroBlogKey): UiTimeline {
val user = author.render(accountKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fleeksoft.ksoup.nodes.Node
import dev.dimension.flare.common.AppDeepLink
import dev.dimension.flare.data.database.cache.model.DbEmoji
import dev.dimension.flare.data.database.cache.model.EmojiContent
import dev.dimension.flare.data.database.cache.model.StatusContent
import dev.dimension.flare.data.datasource.guest.GuestDataSource
import dev.dimension.flare.data.datasource.microblog.StatusAction
import dev.dimension.flare.data.datasource.microblog.StatusEvent
Expand All @@ -19,6 +20,7 @@ import dev.dimension.flare.data.network.mastodon.api.model.Status
import dev.dimension.flare.data.network.mastodon.api.model.Visibility
import dev.dimension.flare.model.MicroBlogKey
import dev.dimension.flare.model.PlatformType
import dev.dimension.flare.model.ReferenceType
import dev.dimension.flare.ui.model.UiCard
import dev.dimension.flare.ui.model.UiEmoji
import dev.dimension.flare.ui.model.UiMedia
Expand All @@ -38,10 +40,14 @@ import kotlinx.datetime.Instant
internal fun Notification.render(
accountKey: MicroBlogKey,
event: StatusEvent.Mastodon,
references: Map<ReferenceType, StatusContent>,
): UiTimeline {
requireNotNull(account) { "account is null" }
val user = account.render(accountKey)
val status = status?.renderStatus(accountKey, event)
val status =
(references[ReferenceType.Notification] as? StatusContent.Mastodon)
?.data
?.renderStatus(accountKey, event)
val topMessageType =
when (type) {
NotificationTypes.Follow -> UiTimeline.TopMessage.MessageType.Mastodon.Follow
Expand Down Expand Up @@ -97,6 +103,7 @@ internal fun Notification.render(
internal fun Status.render(
accountKey: MicroBlogKey,
event: StatusEvent.Mastodon,
references: Map<ReferenceType, StatusContent> = mapOf(),
): UiTimeline {
requireNotNull(account) { "account is null" }
val user = account.render(accountKey)
Expand All @@ -119,7 +126,7 @@ internal fun Status.render(
)
}
val currentStatus = this.renderStatus(accountKey, event)
val actualStatus = reblog ?: this
val actualStatus = (references[ReferenceType.Retweet] as? StatusContent.Mastodon)?.data ?: this
return UiTimeline(
topMessage = topMessage,
content =
Expand Down
Loading

0 comments on commit 077e778

Please sign in to comment.