stacker.news/api/typeDefs/notifications.js

142 lines
2.2 KiB
JavaScript
Raw Normal View History

import { gql } from 'graphql-tag'
2021-08-17 18:15:24 +00:00
export default gql`
extend type Query {
2022-04-21 17:48:27 +00:00
notifications(cursor: String, inc: String): Notifications
2021-08-17 18:15:24 +00:00
}
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
extend type Mutation {
savePushSubscription(endpoint: String!, p256dh: String!, auth: String!, oldEndpoint: String): PushSubscription
deletePushSubscription(endpoint: String!): PushSubscription
}
2021-08-17 18:15:24 +00:00
type Votification {
id: ID!
2021-08-17 18:15:24 +00:00
earnedSats: Int!
item: Item!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2021-08-17 18:15:24 +00:00
}
type ForwardedVotification {
id: ID!
earnedSats: Int!
item: Item!
sortTime: Date!
}
type FollowActivity {
id: ID!
item: Item!
sortTime: Date!
}
2021-08-17 18:15:24 +00:00
type Reply {
id: ID!
2021-08-17 18:15:24 +00:00
item: Item!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2021-08-17 18:15:24 +00:00
}
2021-08-18 23:00:54 +00:00
type Mention {
id: ID!
2021-08-18 23:00:54 +00:00
mention: Boolean!
item: Item!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2021-08-18 23:00:54 +00:00
}
2022-01-19 21:02:38 +00:00
type Invitification {
id: ID!
2022-01-19 21:02:38 +00:00
invite: Invite!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2022-01-19 21:02:38 +00:00
}
2022-02-28 20:09:21 +00:00
type JobChanged {
id: ID!
2022-02-28 20:09:21 +00:00
item: Item!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2022-02-28 20:09:21 +00:00
}
type EarnSources {
id: ID!
posts: Int!
comments: Int!
tipPosts: Int!
tipComments: Int!
}
2023-02-01 14:44:35 +00:00
type Streak {
id: ID!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2023-02-01 14:44:35 +00:00
days: Int
}
2022-03-17 20:13:19 +00:00
type Earn {
id: ID!
2022-03-17 20:13:19 +00:00
earnedSats: Int!
2023-08-30 00:13:21 +00:00
minSortTime: Date!
2023-07-27 00:18:42 +00:00
sortTime: Date!
sources: EarnSources
2022-03-17 20:13:19 +00:00
}
2023-11-21 23:32:22 +00:00
type Revenue {
id: ID!
earnedSats: Int!
sortTime: Date!
subName: String!
}
2022-03-23 18:54:39 +00:00
type InvoicePaid {
id: ID!
2022-03-23 18:54:39 +00:00
earnedSats: Int!
invoice: Invoice!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2022-03-23 18:54:39 +00:00
}
2024-03-25 20:20:11 +00:00
type WithdrawlPaid {
id: ID!
earnedSats: Int!
sortTime: Date!
}
2022-12-19 22:27:52 +00:00
type Referral {
id: ID!
2023-07-27 00:18:42 +00:00
sortTime: Date!
2022-12-19 22:27:52 +00:00
}
2024-01-03 02:05:49 +00:00
type SubStatus {
id: ID!
sub: Sub!
sortTime: Date!
}
type TerritoryPost {
id: ID!
item: Item!
sortTime: Date!
}
Territory transfers (#878) * Allow founders to transfer territories * Log territory transfers in new AuditLog table * Add territory transfer notifications * Use polymorphic AuditEvent table * Add setting for territory transfer notifications * Add push notification * Rename label from user to stacker * More space between cancel and confirm button * Remove AuditEvent table The audit table is not necessary for territory transfers and only adds complexity and unrelated discussion to this PR. Thinking about a future-proof schema for territory transfers and how/what to audit at the same time made my head spin. Some thoughts I had: 1. Maybe using polymorphism for an audit log / audit events is not a good idea Using polymorphism as is currently used in the code base (user wallets) means that every generic event must map to exactly one specialized event. Is this a good requirement/assumption? It already didn't work well for naive auditing of territory transfers since we want events to be indexable by user (no array column) so every event needs to point to a single user but a territory transfer involves multiple users. This made me wonder: Do we even need a table? Maybe the audit log for a user can be implemented using a view? This would also mean no data denormalization. 2. What to audit and how and why? Most actions are already tracked in some way by necessity: zaps, items, mutes, payments, ... In that case: what is the benefit of tracking these things individually in a separate table? Denormalize simply for convenience or performance? Why no view (see previous point)? Use case needs to be more clearly defined before speccing out a schema. * Fix territory transfer notification id conflict * Use include instead of two separate queries * Drop territory transfer setting * Remove trigger usage * Prevent transfers to yourself
2024-03-05 19:56:02 +00:00
type TerritoryTransfer {
id: ID!
sub: Sub!
sortTime: Date!
}
2022-03-17 20:13:19 +00:00
union Notification = Reply | Votification | Mention
2024-03-25 20:20:11 +00:00
| Invitification | Earn | JobChanged | InvoicePaid | WithdrawlPaid | Referral
Territory transfers (#878) * Allow founders to transfer territories * Log territory transfers in new AuditLog table * Add territory transfer notifications * Use polymorphic AuditEvent table * Add setting for territory transfer notifications * Add push notification * Rename label from user to stacker * More space between cancel and confirm button * Remove AuditEvent table The audit table is not necessary for territory transfers and only adds complexity and unrelated discussion to this PR. Thinking about a future-proof schema for territory transfers and how/what to audit at the same time made my head spin. Some thoughts I had: 1. Maybe using polymorphism for an audit log / audit events is not a good idea Using polymorphism as is currently used in the code base (user wallets) means that every generic event must map to exactly one specialized event. Is this a good requirement/assumption? It already didn't work well for naive auditing of territory transfers since we want events to be indexable by user (no array column) so every event needs to point to a single user but a territory transfer involves multiple users. This made me wonder: Do we even need a table? Maybe the audit log for a user can be implemented using a view? This would also mean no data denormalization. 2. What to audit and how and why? Most actions are already tracked in some way by necessity: zaps, items, mutes, payments, ... In that case: what is the benefit of tracking these things individually in a separate table? Denormalize simply for convenience or performance? Why no view (see previous point)? Use case needs to be more clearly defined before speccing out a schema. * Fix territory transfer notification id conflict * Use include instead of two separate queries * Drop territory transfer setting * Remove trigger usage * Prevent transfers to yourself
2024-03-05 19:56:02 +00:00
| Streak | FollowActivity | ForwardedVotification | Revenue | SubStatus
| TerritoryPost | TerritoryTransfer
2021-08-17 18:15:24 +00:00
type Notifications {
2023-07-27 00:18:42 +00:00
lastChecked: Date
2021-08-17 18:15:24 +00:00
cursor: String
notifications: [Notification!]!
}
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
type PushSubscription {
id: ID!
userId: ID!
endpoint: String!
p256dh: String!
auth: String!
}
2021-08-17 18:15:24 +00:00
`