<commit_before>import config from '../config';
import webPush from 'web-push';
import Tarantool from '../db/tarantool';

webPush.setGCMAPIKey(config.gcm_key);

function notify(account, nparams, title, body, url) {
     var payload = JSON.stringify({
        title,
        body,
        url,
        icon: 'https://steemit.com/favicon.ico'
    });
    return new Promise((resolve, reject) => {
        webPush.sendNotification(nparams, payload).then(function() {
            resolve(account);
        }, function(err) {
            reject(err);
        });
    });
}

async function process_queue() {
    console.log('-- processing web push notifications queue -->');
    try {
        const queue = await Tarantool.instance().call('webpush_get_delivery_queue');
        for (const n of queue) {
            if (n.length === 0) return;
            const [account, nparams_array, title, body, url] = n;
            console.log('-- notification -->', account, body, url);
            for (const nparams of nparams_array) {
                try {
                    await notify(account, nparams, title, body, url);
                } catch (err) {
                    console.error('-- error in notify -->', account, err);
                }
            }
            break;
        }
        // console.log('-- run.run -->', queue);
    } catch (error) {
        console.error('-- process_queue error -->', error);
    }
}

function run() {
    process_queue().then(() => {<commit_msg>add profile pics support to notifications<commit_after>import config from '../config';
import webPush from 'web-push';
import Tarantool from '../db/tarantool';

webPush.setGCMAPIKey(config.gcm_key);

function notify(account, nparams, title, body, url, pic) {
     var payload = JSON.stringify({
        title,
        body,
        url,
        icon: pic || 'https://steemit.com/favicon.ico'
    });
    return new Promise((resolve, reject) => {
        webPush.sendNotification(nparams, payload).then(function() {
            resolve(account);
        }, function(err) {
            reject(err);
        });
    });
}

async function process_queue() {
    console.log('-- processing web push notifications queue -->');
    try {
        const queue = await Tarantool.instance().call('webpush_get_delivery_queue');
        for (const n of queue) {
            if (n.length === 0) return;
            const [account, nparams_array, title, body, url, pic] = n;
            console.log('-- notification -->', account, body, url, pic);
            for (const nparams of nparams_array) {
                try {
                    await notify(account, nparams, title, body, url, pic);
                } catch (err) {
                    console.error('-- error in notify -->', account, err);
                }
            }
            break;
        }
        // console.log('-- run.run -->', queue);
    } catch (error) {
        console.error('-- process_queue error -->', error);
    }
}

function run() {
    process_queue().then(() => {
{'fraction_non_alphanumeric': 0.14706856575024843, 'fraction_numerical': 0.000662471016893011, 'mean_word_length': 1.920696324951644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '7455050', 'n_tokens_mistral': 854, 'n_tokens_neox': 837, 'n_words': 218}