Skip to content

Commit

Permalink
Merge pull request #74 from akiomik/fix-notifications
Browse files Browse the repository at this point in the history
Fix notifications
  • Loading branch information
akiomik authored Mar 27, 2023
2 parents 3af81fb + ea51f83 commit ed575ca
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package io.github.akiomik.seiun.model.app.bsky.notification
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import io.github.akiomik.seiun.model.app.bsky.feed.PostReplyRef
import io.github.akiomik.seiun.model.com.atproto.repo.StrongRef
import java.util.*

// NOTE: app.bsky.graph.follow or app.bsky.feed.vote or app.bsky.feed.repost
// app.bsky.graph.follow (subject, createdAt) or
// app.bsky.feed.like (subject, createdAt) or
// app.bsky.feed.repost (subject, createdAt) or
// app.bsky.feed.post (text, reply, createdAt)
@JsonClass(generateAdapter = true)
data class NotificationRecord(
@Json(name = "\$type")
val type: String,
val createdAt: Date,
val text: String? = null,
val reply: PostReplyRef? = null,
// val direction: VoteDirection? = null,
val subject: NotificationSubject? = null
val subject: StrongRef? = null
)

This file was deleted.

16 changes: 8 additions & 8 deletions app/src/main/java/io/github/akiomik/seiun/ui/feed/FeedPost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ private fun RepostIndicator(viewPost: FeedViewPost) {
}

@Composable
private fun UpvoteIndicator(viewPost: FeedViewPost) {
private fun LikeIndicator(viewPost: FeedViewPost) {
val viewModel: PostViewModel = viewModel()
val upvoted = viewPost.post.viewer?.like != null
val color = if (upvoted) {
val liked = viewPost.post.viewer?.like != null
val color = if (liked) {
Red700
} else {
Color.Gray
}
val icon = if (upvoted) {
val icon = if (liked) {
Icons.Sharp.Favorite
} else {
Icons.Sharp.FavoriteBorder
Expand All @@ -232,12 +232,12 @@ private fun UpvoteIndicator(viewPost: FeedViewPost) {

TextButton(
onClick = {
if (upvoted) {
viewModel.cancelVote(feedPost = viewPost, onError = {
if (liked) {
viewModel.cancelLike(feedPost = viewPost, onError = {
Toast.makeText(context, it.toString(), Toast.LENGTH_LONG).show()
})
} else {
viewModel.upvote(feedPost = viewPost, onError = {
viewModel.like(feedPost = viewPost, onError = {
Toast.makeText(context, it.toString(), Toast.LENGTH_LONG).show()
})
}
Expand Down Expand Up @@ -369,7 +369,7 @@ private fun FeedPostContent(viewPost: FeedViewPost) {
) {
ReplyIndicator(viewPost = viewPost)
RepostIndicator(viewPost = viewPost)
UpvoteIndicator(viewPost = viewPost)
LikeIndicator(viewPost = viewPost)
MenuButton(viewPost = viewPost)
}
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private fun Avatar(notification: Notification, onClicked: (String) -> Unit) {
}

@Composable
private fun VoteItem(notification: Notification, onProfileClick: (String) -> Unit) {
private fun LikeItem(notification: Notification, onProfileClick: (String) -> Unit) {
val createdAt = DateFormat.format(
DATETIME_FORMAT,
notification.record.createdAt.toInstant().toEpochMilli()
Expand Down Expand Up @@ -118,7 +118,7 @@ private fun FollowItem(notification: Notification, onProfileClick: (String) -> U
}

@Composable
private fun InviteItem(notification: Notification, onProfileClick: (String) -> Unit) {
private fun MentionItem(notification: Notification, onProfileClick: (String) -> Unit) {
val createdAt = DateFormat.format(
DATETIME_FORMAT,
notification.record.createdAt.toInstant().toEpochMilli()
Expand All @@ -129,7 +129,7 @@ private fun InviteItem(notification: Notification, onProfileClick: (String) -> U
headlineContent = {
Text(
stringResource(
R.string.notification_invited,
R.string.notification_mentioned,
notification.author.displayName ?: notification.author.handle
)
)
Expand All @@ -145,7 +145,7 @@ private fun InviteItem(notification: Notification, onProfileClick: (String) -> U
}

@Composable
private fun MentionItem(notification: Notification, onProfileClick: (String) -> Unit) {
private fun ReplyItem(notification: Notification, onProfileClick: (String) -> Unit) {
val createdAt = DateFormat.format(
DATETIME_FORMAT,
notification.record.createdAt.toInstant().toEpochMilli()
Expand All @@ -156,7 +156,7 @@ private fun MentionItem(notification: Notification, onProfileClick: (String) ->
headlineContent = {
Text(
stringResource(
R.string.notification_mentioned,
R.string.notification_replied,
notification.author.displayName ?: notification.author.handle
)
)
Expand All @@ -172,7 +172,7 @@ private fun MentionItem(notification: Notification, onProfileClick: (String) ->
}

@Composable
private fun ReplyItem(notification: Notification, onProfileClick: (String) -> Unit) {
private fun QuoteItem(notification: Notification, onProfileClick: (String) -> Unit) {
val createdAt = DateFormat.format(
DATETIME_FORMAT,
notification.record.createdAt.toInstant().toEpochMilli()
Expand All @@ -183,7 +183,7 @@ private fun ReplyItem(notification: Notification, onProfileClick: (String) -> Un
headlineContent = {
Text(
stringResource(
R.string.notification_replied,
R.string.notification_quoted,
notification.author.displayName ?: notification.author.handle
)
)
Expand All @@ -210,13 +210,13 @@ fun NotificationListItem(notification: Notification, onProfileClick: (String) ->
.fillMaxWidth()
) {
when (notification.reason) {
"vote" -> VoteItem(notification = notification, onProfileClick = onProfileClick)
"like" -> LikeItem(notification = notification, onProfileClick = onProfileClick)
"repost" -> RepostItem(notification = notification, onProfileClick = onProfileClick)
"follow" -> FollowItem(notification = notification, onProfileClick = onProfileClick)
"invite" -> InviteItem(notification = notification, onProfileClick = onProfileClick)
"mention" ->
MentionItem(notification = notification, onProfileClick = onProfileClick)
"reply" -> ReplyItem(notification = notification, onProfileClick = onProfileClick)
"quote" -> QuoteItem(notification = notification, onProfileClick = onProfileClick)
else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostViewModel : ApplicationViewModel() {
private val userRepository = SeiunApplication.instance!!.userRepository
private val postFeedRepository = SeiunApplication.instance!!.postFeedRepository

fun upvote(
fun like(
feedPost: FeedViewPost,
onSuccess: () -> Unit = {},
onError: (Throwable) -> Unit = {}
Expand All @@ -23,7 +23,7 @@ class PostViewModel : ApplicationViewModel() {
)
}

fun cancelVote(
fun cancelLike(
feedPost: FeedViewPost,
onSuccess: () -> Unit = {},
onError: (Throwable) -> Unit = {}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<string name="notification_liked">%1$s があなたの投稿にいいねしました</string>
<string name="notification_reposted">%1$s があなたの投稿をリポストしました</string>
<string name="notification_followed">%1$s があなたをフォローしました</string>
<string name="notification_invited">%1$s があなたを招待しました</string>
<string name="notification_quoted">%1$s があなたを投稿を引用しました</string>
<string name="notification_mentioned">%1$s があなたにメンションしました</string>
<string name="notification_replied">%1$s があなたに返信しました</string>
<string name="feed_posted">投稿しました</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<string name="notification_liked">%1$s liked your post</string>
<string name="notification_reposted">%1$s reposted your post</string>
<string name="notification_followed">%1$s is followed you</string>
<string name="notification_invited">%1$s invited you</string>
<string name="notification_quoted">%1$s quoted your post</string>
<string name="notification_mentioned">%1$s mentioned you</string>
<string name="notification_replied">%1$s replied to you</string>
<string name="feed_posted">Your post has been published</string>
Expand Down

0 comments on commit ed575ca

Please sign in to comment.