<commit_before>const debug = require('./debug')('notification');

class Notification {
    constructor(domainName, notificationJson) {
        this.domainName = domainName;
        this.notificationJson = notificationJson;
    }

    async toNotificationListResource(persistence) {
        const getEntity = require('./get-entity');
        const entity = await getEntity(this.domainName, this.notificationJson.type);
        const documentJson = await entity.getInstance(persistence, this.notificationJson.id);
        debug(`TODO: documentJson=`, documentJson);
    }

    static async addToUser(persistence, userEntity, userJson, instance) {
        if (!userJson) {
            return;
        }

        // In case the modified document is the user's document.
        if (userJson.type === instance.type && userJson.id === instance.id) {
            userJson = instance;
        }

        if (!userJson._meta) {
            userJson._meta = {};
        }

        if (!userJson._meta.notifications) {
            userJson._meta.notifications = [];
        }

        const duplicate = userJson._meta.notifications.find((notification) => notification.type === instance.type && notification.id === instance.id);
        if (!duplicate) {
            userJson._meta.notifications.push({
                type: instance.type,
                typeID: instance.typeID,
                id: instance.id
            });

            await userEntity.updateDocument(persistence, userJson, true);<commit_msg>-#214: WIP to list notifications<commit_after>const Promise = require('bluebird');

const warpjsUtils = require('@warp-works/warpjs-utils');

const debug = require('./debug')('notification');

class Notification {
    constructor(domainName, notificationJson) {
        this.domainName = domainName;
        this.notificationJson = notificationJson;
    }

    async toNotificationListResource(persistence) {
        const getEntity = require('./get-entity');
        const entity = await getEntity(this.domainName, this.notificationJson.type);
        const documentJson = await entity.getInstance(persistence, this.notificationJson.id);
    }

    static async addToUser(persistence, userEntity, userJson, instance) {
        if (!userJson) {
            return;
        }

        // In case the modified document is the user's document.
        if (userJson.type === instance.type && userJson.id === instance.id) {
            userJson = instance;
        }

        if (!userJson._meta) {
            userJson._meta = {};
        }

        if (!userJson._meta.notifications) {
            userJson._meta.notifications = [];
        }

        const duplicate = userJson._meta.notifications.find((notification) => notification.type === instance.type && notification.id === instance.id);
        if (!duplicate) {
            userJson._meta.notifications.push({
                type: instance.type,
                typeID: instance.typeID,
                id: instance.id
            });

            await userEntity.updateDocument(persistence, userJson, true);
{'fraction_non_alphanumeric': 0.11502117953730857, 'fraction_numerical': 0.0009775171065493646, 'mean_word_length': 2.3736263736263736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4135099', 'n_tokens_mistral': 784, 'n_tokens_neox': 764, 'n_words': 166}