Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ For detailed information about the platform architecture, services, and their in
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)

If you use `nvm`, run this after entering the repo to align your shell with the repository Node version:

```bash
nvm use
```

## Verification

To verify the installation, perform the following checks in your terminal:
Expand Down
109 changes: 109 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion common/scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ else
--to @hcengineering/pod-process \
--to @hcengineering/pod-rating \
--to @hcengineering/pod-payment \
--to @hcengineering/pod-worker
--to @hcengineering/pod-worker \
--to @hcengineering/pod-notification-scheduler
fi
17 changes: 17 additions & 0 deletions dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,23 @@ services:
- QUEUE_CONFIG=${QUEUE_CONFIG}
- QUEUE_REGION=cockroach
restart: unless-stopped
notification-scheduler:
image: hardcoreeng/notification-scheduler
extra_hosts:
- 'huly.local:host-gateway'
depends_on:
redpanda:
condition: service_started
account:
condition: service_started
environment:
- SERVICE_ID=notification-scheduler
- SECRET=secret
- ACCOUNTS_URL=http://huly.local:3000
- QUEUE_CONFIG=${QUEUE_CONFIG}
- QUEUE_REGION=cockroach
- OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4318/v1/traces
restart: unless-stopped
# translate:
# image: hardcoreeng/translate
# extra_hosts:
Expand Down
35 changes: 35 additions & 0 deletions models/time/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,41 @@ export function createModel (builder: Builder): void {
enabledTypes: [time.ids.ToDoCreated]
})

builder.createDoc(
notification.class.NotificationType,
core.space.Model,
{
hidden: false,
generated: false,
allowedForAuthor: true,
label: time.string.ToDo,
group: time.ids.TimeNotificationGroup as Ref<NotificationGroup>,
// Scheduled notifications are created by a worker, but provider/type settings still expect a tx class list.
txClasses: [core.class.TxCreateDoc],
objectClass: time.class.ToDo,
onlyOwn: true,
defaultEnabled: true,
templates: {
textTemplate: '{body}',
htmlTemplate: '<p>{body}</p><p>{link}</p>',
subjectTemplate: '{title}'
}
},
time.ids.ToDoReminder
)

builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, {
provider: notification.providers.InboxNotificationProvider,
ignoredTypes: [],
enabledTypes: [time.ids.ToDoReminder]
})

builder.createDoc(notification.class.NotificationProviderDefaults, core.space.Model, {
provider: notification.providers.PushNotificationProvider,
ignoredTypes: [],
enabledTypes: [time.ids.ToDoReminder]
})

builder.createDoc<ClassCollaborators<ToDo>>(core.class.ClassCollaborators, core.space.Model, {
attachedTo: time.class.ToDo,
fields: ['user']
Expand Down
3 changes: 2 additions & 1 deletion models/time/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export default mergeIds(timeId, time, {
ids: {
ToDoCreated: '' as Ref<NotificationType>,
ModulePermissionGroup: '' as Ref<Doc>,
ModulePermissionGroupReadOnlyGuest: '' as Ref<Doc>
ModulePermissionGroupReadOnlyGuest: '' as Ref<Doc>,
ToDoReminder: '' as Ref<NotificationType>
},
function: {
ToDoTitleProvider: '' as Resource<(client: Client, ref: Ref<Doc>, doc?: Doc) => Promise<string>>
Expand Down
5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,11 @@
"projectFolder": "services/notification/pod-notification",
"shouldPublish": false
},
{
"packageName": "@hcengineering/pod-notification-scheduler",
"projectFolder": "services/notification/pod-notification-scheduler",
"shouldPublish": false
},
{
"packageName": "@hcengineering/pod-telegram",
"projectFolder": "services/telegram/pod-telegram",
Expand Down
46 changes: 37 additions & 9 deletions server-plugins/notification-resources/src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import serverCore, { TriggerControl } from '@hcengineering/server-core'
import serverNotification, { PUSH_NOTIFICATION_TITLE_SIZE } from '@hcengineering/server-notification'
import type { ReceiverInfo } from '@hcengineering/server-notification'
import {
AccountUuid,
Class,
Expand Down Expand Up @@ -49,6 +50,7 @@ import contact, {
} from '@hcengineering/contact'
import { AvailableProvidersCache, AvailableProvidersCacheKey, getTranslatedNotificationContent } from './index'
import { getPerson } from '@hcengineering/server-contact'
import { getAllowedProviders, getNotificationProviderControl, getReceiversInfo } from './utils'

async function createPushFromInbox (
control: TriggerControl,
Expand Down Expand Up @@ -235,25 +237,51 @@ export async function PushNotificationsHandler (
): Promise<Tx[]> {
const availableProviders: AvailableProvidersCache = control.contextCache.get(AvailableProvidersCacheKey) ?? new Map()

const all: InboxNotification[] = txes
.map((tx) => TxProcessor.createDoc2Doc(tx))
.filter(
(it) =>
availableProviders.get(it._id)?.find((p) => p === notification.providers.PushNotificationProvider) !== undefined
)
const all: InboxNotification[] = txes.map((tx) => TxProcessor.createDoc2Doc(tx))

// First pass: use cache if present.
const pushEnabled: InboxNotification[] = all.filter(
(it) =>
availableProviders.get(it._id)?.find((p) => p === notification.providers.PushNotificationProvider) !== undefined
)

// Fallback: if cache doesn't have the provider info (e.g. scheduled notifications created outside tx-trigger paths),
// compute allowed providers from notification type + user settings.
if (pushEnabled.length < all.length) {
const notificationControl = await getNotificationProviderControl(control.ctx, control)
const receivers: ReceiverInfo[] = await getReceiversInfo(control.ctx, [...new Set(all.map((n) => n.user))], control)
const receiverByAccount = new Map(receivers.map((r) => [r.account, r]))

for (const n of all) {
if (availableProviders.get(n._id) !== undefined) continue
if (pushEnabled.includes(n)) continue

const type = (n.types ?? [])[0]
if (type === undefined) continue

const notificationType = control.modelDb.getObject(type)
const receiver = receiverByAccount.get(n.user)
if (receiver === undefined) continue

const allowedProviders = getAllowedProviders(control, receiver.socialIds, notificationType, notificationControl)
if (allowedProviders.includes(notification.providers.PushNotificationProvider)) {
pushEnabled.push(n)
}
}
}

if (all.length === 0) {
if (pushEnabled.length === 0) {
return []
}

const receivers = new Set(all.map((it) => it.user))
const receivers = new Set(pushEnabled.map((it) => it.user))
const subscriptions = (await control.queryFind(control.ctx, notification.class.PushSubscription, {})).filter((it) =>
receivers.has(it.user)
)

const res: Tx[] = []

for (const inboxNotification of all) {
for (const inboxNotification of pushEnabled) {
const { user } = inboxNotification
const userSubscriptions = subscriptions.filter((it) => it.user === user)

Expand Down
Loading
Loading