In FOAM, you can send notifications to individual users, groups of users, or broadcast them to all users in a system. The notification system is built around a core Notification class that can be extended for specialized use cases.
You can create notifications programmatically using the Notification.create() method and persist them through the notificationDAO:
let t1 = foam.core.notification.Notification.create({
userId: x.subject.realUser.id,
broadcasted: true,
body: 'notification body',
toastMessage: 'toast'
});
t1 = await x.notificationDAO.put(t1);
The base Notification class includes properties like userId, groupId, broadcasted, body, toastMessage, severity, and notificationType.
You can extend the base Notification class to create specialized notification types with additional properties. For example, TicketNotification adds a ticket reference:
foam.CLASS({
package: 'foam.core.ticket',
name: 'TicketNotification',
extends: 'foam.core.notification.Notification',
properties: [
{
class: 'Reference',
of: 'foam.core.ticket.Ticket',
name: 'ticket'
}
]
});
You can then create and send these custom notifications just like standard ones:
let t2 = foam.core.ticket.TicketNotification.create({
userId: x.subject.realUser.id,
broadcasted: true,
body: 'ticket body',
ticket: ticketId
});
t2 = await x.notificationDAO.put(t2);
Users access notifications through the notifications bell icon, which displays notifications in a list format. Each notification is rendered using a NotificationCitationView.
For custom notification types, you can create specialized citation views by extending NotificationCitationView and following the naming convention <ModelName>NotificationCitationView. For example:
foam.CLASS({
package: 'foam.core.ticket',
name: 'TicketNotificationNotificationCitationView',
extends: 'foam.core.notification.NotificationCitationView',
methods: [
function render() {
// Custom rendering logic here
}
]
});
This pattern is used in other parts of the system, such as ApprovalRequestNotificationNotificationCitationView and BroadcastNotificationNotificationCitationView.
FOAM uses a sophisticated DAO system for managing notifications:
localNotificationDAO: Internal storage for notificationsnotificationDAO: Main service DAO with authorization and decoratorsmyNotificationDAO: User-specific notification DAO with polling and toast supportNotifications can be created from templates that define default recipients and content.
The broadcasted property allows sending notifications to all users or entire groups.
Notifications integrate with various FOAM systems:
SendNotification actions