models/notifications/Notification.js

import Action from './../actions/Action.js';
import NotificationButton from './NotificationButton.js';
import NotificationCustomization from './NotificationCustomization.js';
import User from './../communities/User.js';
import MediaAttachment from './../MediaAttachment.js';

export default class Notification {
    /**
     * Creates a new Notification instance from the provider parameters.
     *
     * @constructor Notification
     * @param {Object} notificationMap notification parameters
     * @param {string} notificationMap.id - ID
     * @param {string} notificationMap.status - Status
     * @param {string} notificationMap.type - Type
     * @param {number} notificationMap.createdAt - Creation Date
     * @param {string} notificationMap.title - Title
     * @param {string} notificationMap.text - Text
     * @param {Action} notificationMap.action - Action
     * @param {NotificationButton[]} [notificationMap.actionButtons=[]] - Action Buttons
     * @param {MediaAttachment} [notificationMap.mediaAttachment] - Attachment
     * @param {User} notificationMap.sender - Sender
     * @param {NotificationCustomization} [notificationMap.customization] - Customization
     */
    constructor(notificationMap) {
        this.id = notificationMap.id || null;
        this.status = notificationMap.status || null;
        this.type = notificationMap.type || null;
        this.createdAt = notificationMap.createdAt || null;
        this.title = notificationMap.title || null;
        this.text = notificationMap.text || null;
        const actionMap = notificationMap.action;
        this.action = actionMap
            ? new Action(actionMap)
            : null;

        this.actionButtons = [];
        const notificationsButtonsArray = notificationMap.actionButtons;
        if (notificationsButtonsArray != undefined) {
            notificationsButtonsArray.forEach((notificationButtonMap) => {
                const button = new NotificationButton(notificationButtonMap);
                this.actionButtons.push(button);
            });
        }

        this.mediaAttachment = notificationMap.mediaAttachment
            ? new MediaAttachment(notificationMap.mediaAttachment)
            : null;

            const senderMap = notificationMap.sender;
        this.sender = senderMap
            ? User.create(senderMap)
            : null;

        this.customization = notificationMap.customization;
    }

    /**
     * Create Notification from PNNotification
     *
     * @memberof Notification
     * @param {Object} notification - PNNotification
     * @returns {Notification} Notification instance
     * @ignore
     */
    static create(notification) {
        return new Notification({
            ...notification,
            sender: User.create(notification.sender.publicUser),
            mediaAttachment: notification.media
                ? {
                    imageUrl: notification.media.image,
                    videoUrl: notification.media.video
                }
                : null,
            customization: notification.media
                ? {
                    titleColor: notification.media.titleColor,
                    textColor: notification.media.textColor,
                    backgroundImage: notification.media.backgroundImage,
                }
                : null
        });
    }
}