Skip to content

Commit f9e1efd

Browse files
authored
Merge pull request #151 from malkoG/support-post-updated-notifications
Support post updated notifications
2 parents 692354d + 4b7337d commit f9e1efd

7 files changed

Lines changed: 128 additions & 10 deletions

File tree

app/src/main/graphql/pub/hackers/android/operations.graphql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ query Notifications($after: String) {
244244
content
245245
}
246246
}
247+
... on QuotedPostUpdatedNotification {
248+
post {
249+
id
250+
content
251+
}
252+
}
247253
... on ReactNotification {
248254
emoji
249255
customEmoji {
@@ -262,6 +268,12 @@ query Notifications($after: String) {
262268
content
263269
}
264270
}
271+
... on SharedPostUpdatedNotification {
272+
post {
273+
id
274+
content
275+
}
276+
}
265277
}
266278
}
267279
pageInfo {

app/src/main/graphql/pub/hackers/android/schema.graphqls

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,15 @@ enum NotificationType {
11411141

11421142
QUOTE
11431143

1144+
QUOTED_POST_UPDATED
1145+
11441146
REACT
11451147

11461148
REPLY
11471149

11481150
SHARE
1151+
1152+
SHARED_POST_UPDATED
11491153
}
11501154

11511155
type PageInfo {
@@ -1683,6 +1687,20 @@ type QuoteNotification implements Node & Notification {
16831687
uuid: UUID!
16841688
}
16851689

1690+
type QuotedPostUpdatedNotification implements Node & Notification {
1691+
account: Account!
1692+
1693+
actors(after: String, before: String, first: Int, last: Int): NotificationActorsConnection!
1694+
1695+
created: DateTime!
1696+
1697+
id: ID!
1698+
1699+
post: Post
1700+
1701+
uuid: UUID!
1702+
}
1703+
16861704
type ReactNotification implements Node & Notification {
16871705
account: Account!
16881706

@@ -1952,6 +1970,20 @@ type ShareNotification implements Node & Notification {
19521970
uuid: UUID!
19531971
}
19541972

1973+
type SharedPostUpdatedNotification implements Node & Notification {
1974+
account: Account!
1975+
1976+
actors(after: String, before: String, first: Int, last: Int): NotificationActorsConnection!
1977+
1978+
created: DateTime!
1979+
1980+
id: ID!
1981+
1982+
post: Post
1983+
1984+
uuid: UUID!
1985+
}
1986+
19551987
input SharePostInput {
19561988
clientMutationId: ID
19571989

app/src/main/java/pub/hackers/android/data/repository/HackersPubRepository.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,13 +1829,31 @@ class HackersPubRepository @Inject constructor(
18291829
actors = actors,
18301830
post = onQuoteNotification.post?.let { NotificationPost(id = it.id, content = it.content.toString()) }
18311831
)
1832+
onQuotedPostUpdatedNotification != null -> Notification.QuotedPostUpdated(
1833+
id = id,
1834+
uuid = uuid.toString(),
1835+
created = created,
1836+
actors = actors,
1837+
post = onQuotedPostUpdatedNotification.post?.let {
1838+
NotificationPost(id = it.id, content = it.content.toString())
1839+
}
1840+
)
18321841
onShareNotification != null -> Notification.Share(
18331842
id = id,
18341843
uuid = uuid.toString(),
18351844
created = created,
18361845
actors = actors,
18371846
post = onShareNotification.post?.let { NotificationPost(id = it.id, content = it.content.toString()) }
18381847
)
1848+
onSharedPostUpdatedNotification != null -> Notification.SharedPostUpdated(
1849+
id = id,
1850+
uuid = uuid.toString(),
1851+
created = created,
1852+
actors = actors,
1853+
post = onSharedPostUpdatedNotification.post?.let {
1854+
NotificationPost(id = it.id, content = it.content.toString())
1855+
}
1856+
)
18391857
onReactNotification != null -> Notification.React(
18401858
id = id,
18411859
uuid = uuid.toString(),

app/src/main/java/pub/hackers/android/data/worker/NotificationWorker.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class NotificationWorker @AssistedInject constructor(
135135
is Notification.Mention -> "$actorName mentioned you"
136136
is Notification.Reply -> "$actorName replied to your post"
137137
is Notification.Quote -> "$actorName quoted your post"
138+
is Notification.QuotedPostUpdated -> "$actorName updated a post you quoted"
138139
is Notification.Share -> "$actorName shared your post"
140+
is Notification.SharedPostUpdated -> "$actorName updated a post you shared"
139141
is Notification.React -> {
140142
val othersCount = notification.actors.size - 1
141143
val othersText = if (othersCount > 0) {

app/src/main/java/pub/hackers/android/domain/model/Models.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ sealed class Notification {
165165
val post: NotificationPost?
166166
) : Notification()
167167

168+
@Immutable
169+
data class QuotedPostUpdated(
170+
override val id: String,
171+
override val uuid: String,
172+
override val created: Instant,
173+
override val actors: List<Actor>,
174+
val post: NotificationPost?
175+
) : Notification()
176+
168177
@Immutable
169178
data class Share(
170179
override val id: String,
@@ -174,6 +183,15 @@ sealed class Notification {
174183
val post: NotificationPost?
175184
) : Notification()
176185

186+
@Immutable
187+
data class SharedPostUpdated(
188+
override val id: String,
189+
override val uuid: String,
190+
override val created: Instant,
191+
override val actors: List<Actor>,
192+
val post: NotificationPost?
193+
) : Notification()
194+
177195
@Immutable
178196
data class React(
179197
override val id: String,

app/src/main/java/pub/hackers/android/ui/screens/notifications/NotificationsScreen.kt

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,38 @@ private fun NotificationItem(
168168
stringResource(R.string.notification_quote)
169169
)
170170

171+
is Notification.QuotedPostUpdated -> Pair(
172+
Icons.Default.FormatQuote,
173+
buildMultiActorActionText(
174+
notification = notification,
175+
actionText = stringResource(R.string.notification_quoted_post_updated)
176+
)
177+
)
178+
171179
is Notification.Share -> Pair(
172180
Icons.Default.Repeat,
173181
stringResource(R.string.notification_share)
174182
)
175183

184+
is Notification.SharedPostUpdated -> Pair(
185+
Icons.Default.Repeat,
186+
buildMultiActorActionText(
187+
notification = notification,
188+
actionText = stringResource(R.string.notification_shared_post_updated)
189+
)
190+
)
191+
176192
is Notification.React -> {
177-
val othersCount = notification.actors.size - 1
178-
val prefix = if (othersCount > 0) {
179-
pluralStringResource(
180-
R.plurals.notification_and_others,
181-
othersCount,
182-
othersCount
183-
) + " "
184-
} else ""
185193
val actionStr = if (notification.emoji != null) {
186-
prefix + stringResource(R.string.notification_react_with_emoji, notification.emoji)
194+
buildMultiActorActionText(
195+
notification = notification,
196+
actionText = stringResource(R.string.notification_react_with_emoji, notification.emoji)
197+
)
187198
} else {
188-
prefix + stringResource(R.string.notification_react)
199+
buildMultiActorActionText(
200+
notification = notification,
201+
actionText = stringResource(R.string.notification_react)
202+
)
189203
}
190204
Pair(Icons.Default.Favorite, actionStr)
191205
}
@@ -195,7 +209,9 @@ private fun NotificationItem(
195209
is Notification.Mention -> notification.post
196210
is Notification.Reply -> notification.post
197211
is Notification.Quote -> notification.post
212+
is Notification.QuotedPostUpdated -> notification.post
198213
is Notification.Share -> notification.post
214+
is Notification.SharedPostUpdated -> notification.post
199215
is Notification.React -> notification.post
200216
else -> null
201217
}
@@ -278,6 +294,24 @@ private fun NotificationItem(
278294
}
279295
}
280296

297+
@Composable
298+
private fun buildMultiActorActionText(
299+
notification: Notification,
300+
actionText: String
301+
): String {
302+
val othersCount = notification.actors.size - 1
303+
val prefix = if (othersCount > 0) {
304+
pluralStringResource(
305+
R.plurals.notification_and_others,
306+
othersCount,
307+
othersCount
308+
) + " "
309+
} else {
310+
""
311+
}
312+
return prefix + actionText
313+
}
314+
281315
private fun formatRelativeTime(instant: Instant): String {
282316
val now = Instant.now()
283317
val duration = Duration.between(instant, now)

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797
<string name="notification_mention">mentioned you</string>
9898
<string name="notification_reply">replied to your post</string>
9999
<string name="notification_quote">quoted your post</string>
100+
<string name="notification_quoted_post_updated">updated a post you quoted</string>
100101
<string name="notification_share">shared your post</string>
102+
<string name="notification_shared_post_updated">updated a post you shared</string>
101103
<string name="notification_react">reacted to your post</string>
102104
<string name="notification_react_with_emoji">reacted to your post with %1$s</string>
103105
<plurals name="notification_and_others">

0 commit comments

Comments
 (0)