-
Notifications
You must be signed in to change notification settings - Fork 0
feat: notifications without account #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,70 +8,83 @@ const MODULE_ID = 'api::notification.notification' | |
| const GLOBAL_MODULE_ID = 'api::notifications-consumer.notifications-consumer' | ||
| const SINGLETON_ID = 1 | ||
|
|
||
| const NOTIFICATIONS_POPULATE = { | ||
| notification_template: { | ||
| fields: ['id', 'title', 'description', 'url', 'push'], | ||
| populate: { | ||
| thumbnail: { | ||
| fields: ['url'] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default factories.createCoreService(MODULE_ID, ({ strapi }) => { | ||
| return { | ||
| async getNotificationsForAll(push: boolean) { | ||
| return strapi.entityService.findMany( | ||
| MODULE_ID, | ||
| { | ||
| start: 0, | ||
| limit: 50, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the plan for the hardcoded 50
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would even keep it as it is.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, lets keep it for now them |
||
| filters: { | ||
| account: { $null: true }, | ||
| notification_template: { push } | ||
| }, | ||
| populate: NOTIFICATIONS_POPULATE | ||
| } | ||
| ) | ||
| }, | ||
| async getNotificationList(account: string) { | ||
| const push = false | ||
| const notifications = await strapi.entityService.findMany( | ||
| MODULE_ID, | ||
| { | ||
| start: 0, | ||
| limit: 50, | ||
| filters: { | ||
| account, | ||
| notification_template: { push: false } | ||
| notification_template: { push } | ||
| }, | ||
| populate: { | ||
| notification_template: { | ||
| fields: ['id', 'title', 'description', 'url', 'push'], | ||
| populate: { | ||
| thumbnail: { | ||
| fields: ['url'] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| populate: NOTIFICATIONS_POPULATE | ||
| } | ||
| ) | ||
| const notificationsForAll = await this.getNotificationsForAll(push) | ||
|
|
||
| return notifications.map(notification => ({ | ||
| return [...notifications, ...notificationsForAll].map(notification => ({ | ||
| id: notification.id, | ||
| account: notification.account, | ||
| title: notification.notification_template.title, | ||
| description: templateNotification(notification.notification_template.description, notification.data), | ||
| url: notification.notification_template.url, | ||
| createdAt: notification.createdAt, | ||
| thumbnail: notification.notification_template.thumbnail.url | ||
| thumbnail: notification.notification_template.thumbnail?.url | ||
| })) | ||
| }, | ||
| async getPushNotifications() { | ||
| const push = true | ||
| const global = await strapi.entityService.findOne(GLOBAL_MODULE_ID, SINGLETON_ID, { | ||
| populate: ['id', 'lastConsumedNotificationDate'] | ||
| }) | ||
|
|
||
| const lastConsumedNotificationDate = global?.lastConsumedNotificationDate | ||
|
|
||
| return strapi.entityService.findMany( | ||
| const notificationsForAll = await this.getNotificationsForAll(push) | ||
| const notifications = await strapi.entityService.findMany( | ||
| MODULE_ID, | ||
| { | ||
| limit: 200, | ||
| filters: { | ||
| notification_template: { push: true }, | ||
| notification_template: { push }, | ||
| ...(lastConsumedNotificationDate ? { | ||
| createdAt: {$gt: lastConsumedNotificationDate} | ||
| } : undefined) | ||
| }, | ||
| populate: { | ||
| notification_template: { | ||
| fields: ['id', 'title', 'description', 'url', 'push'], | ||
| populate: { | ||
| thumbnail: { | ||
| fields: ['url'] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| populate: NOTIFICATIONS_POPULATE | ||
| } | ||
| ) | ||
|
|
||
| return [notifications, notificationsForAll] | ||
| }, | ||
| updateLastConsumedNotificationDate() { | ||
| return strapi.entityService.update( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.