stacker.news/api/typeDefs/notifications.js

129 lines
2.0 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
}
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!
}
2022-03-17 20:13:19 +00:00
union Notification = Reply | Votification | Mention
2022-12-19 22:27:52 +00:00
| Invitification | Earn | JobChanged | InvoicePaid | Referral
| Streak | FollowActivity | ForwardedVotification | Revenue | SubStatus | TerritoryPost
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
`