<commit_before>define([
    'jquery',
    '/api/config',
    '/bower_components/chainpad-crypto/crypto.js',
    '/common/toolbar3.js',
    '/bower_components/nthen/index.js',
    '/common/sframe-common.js',
    '/common/hyperscript.js',
    '/customize/messages.js',
    '/common/common-interface.js',

    'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
    'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
    'less!/notifications/app-notifications.less',
], function (
    $,
    ApiConfig,
    Crypto,
    Toolbar,
    nThen,
    SFCommon,
    h,
    Messages,
    UI
    )
{
    var APP = {};

    var common;
    var sFrameChan;

    var categories = {
        'all': [
            'cp-notifications-all',
        ],
        'friends': [
            'cp-notifications-friends',
        ],
        'pads': [
            'cp-notifications-pads',
        ],
        'archived': [
            'cp-notifications-archived',
        ],
    };

    var notifsAllowedTypes = ["FRIEND_REQUEST", "FRIEND_REQUEST_ACCEPTED", "FRIEND_REQUEST_DECLINED", "SHARE_PAD"];

    var create = {};

    var unreadData;

    // create the list of notifications
    // show only notifs with type in filterTypes array
    var makeNotificationList = function (key, filterTypes) {
        filterTypes = filterTypes || [];
        var safeKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
        var categoryName = Messages['notification_cat_' + safeKey] || safeKey;

        var notifsData = [];
        if (key === "all") {
            unreadData = notifsData;
        }
        var $div = $('<div>', {'class': 'cp-notifications-' + key + ' cp-sidebarlayout-element'});
        var notifsPanel, notifsList, dismissAll;
        notifsPanel = h("div.cp-app-notifications-panel", [
            h('div.cp-app-notifications-panel-titlebar', [
                h("span.cp-app-notifications-panel-title",
                    (Messages.notificationsPage || "Notifications") + " - " + categoryName),
                h("div.cp-app-notifications-panel-titlebar-buttons", [
                    dismissAll = h("div.cp-app-notifications-dismissall.cp-clickable", { title: Messages.dismissAll || "Dismiss All" }, h("span.fa.fa-trash")),
                ]),
            ]),
            notifsList = h("div.cp-app-notifications-panel-list", [
                h("div.cp-notification.no-notifications", Messages.notifications_empty),
            ]),
        ]);

        // add notification
        var addNotification = function (data, el) {
            // if the type of notification correspond
            if (filterTypes.indexOf(data.content.msg.type) !== -1) {
                notifsData.push(data);
                $(notifsList).prepend(el);
            }
        };
        var addArchivedNotification = function (data) {
            // if the type is allowed
            if (data.content.archived && notifsAllowedTypes.indexOf(data.content.msg.type) !== -1) {
                var isDataUnread = unreadData.findIndex(function (ud) {
                    return ud.content.hash === data.content.hash;
                }) !== -1;
                notifsData.push(data);
                var el = common.mailbox.createElement(data);
                var time = new Date(data.content.time);
                $(el).find(".cp-notification-content").append(h("span.notification-time", time.toLocaleDateString() + " - " + time.toLocaleTimeString()));
                $(el).addClass("cp-app-notification-archived");
                $(el).toggle(!isDataUnread);
                $(notifsList).append(el);
            }
        };

        $div.append(notifsPanel);

        if (key === "archived") {
            var loadmore;
            var lastKnownHash;
            $(dismissAll).remove();
            loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ...");
            $(loadmore).click(function () {
                common.mailbox.getNotificationsHistory('notifications', 10, lastKnownHash, function (err, messages, end) {
                    if (!Array.isArray(messages)) { return; }
                    // display archived notifs from most recent to oldest
                    for (var i = messages.length - 1 ; i >= 0 ; i--) {
                        var data = messages[i];
                        data.content.archived = true;
                        addArchivedNotification(data);
                    }
                    if (end) {
                        $(loadmore).hide();
                    }
                    else {
                        lastKnownHash = messages[0].content.hash;
                    }
                });
            });
            notifsList.before(loadmore);
            $(loadmore).click();
        }

        common.mailbox.subscribe(["notifications"], {
            onMessage: function (data, el) {
                addNotification(data, el);
            },
            onViewed: function (data) {
                $('.cp-app-notification-archived[data-hash="' + data.hash + '"]').show();
            }
        });

        $(dismissAll).click(function () {
            notifsData.forEach(function (data) {
                if (data.content.isDismissible) {
                    data.content.dismissHandler();
                }
            });
        });

        return $div;
    };
    create['all'] = function () {
        var key = 'all';
        return makeNotificationList(key, notifsAllowedTypes);
    };

    create['friends'] = function () {
        var key = 'friends';<commit_msg>Move button load-more under archived notifications<commit_after>define([
    'jquery',
    '/api/config',
    '/bower_components/chainpad-crypto/crypto.js',
    '/common/toolbar3.js',
    '/bower_components/nthen/index.js',
    '/common/sframe-common.js',
    '/common/hyperscript.js',
    '/customize/messages.js',
    '/common/common-interface.js',

    'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
    'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
    'less!/notifications/app-notifications.less',
], function (
    $,
    ApiConfig,
    Crypto,
    Toolbar,
    nThen,
    SFCommon,
    h,
    Messages,
    UI
    )
{
    var APP = {};

    var common;
    var sFrameChan;

    var categories = {
        'all': [
            'cp-notifications-all',
        ],
        'friends': [
            'cp-notifications-friends',
        ],
        'pads': [
            'cp-notifications-pads',
        ],
        'archived': [
            'cp-notifications-archived',
        ],
    };

    var notifsAllowedTypes = ["FRIEND_REQUEST", "FRIEND_REQUEST_ACCEPTED", "FRIEND_REQUEST_DECLINED", "SHARE_PAD"];

    var create = {};

    var unreadData;

    // create the list of notifications
    // show only notifs with type in filterTypes array
    var makeNotificationList = function (key, filterTypes) {
        filterTypes = filterTypes || [];
        var safeKey = key.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
        var categoryName = Messages['notification_cat_' + safeKey] || safeKey;

        var notifsData = [];
        if (key === "all") {
            unreadData = notifsData;
        }
        var $div = $('<div>', {'class': 'cp-notifications-' + key + ' cp-sidebarlayout-element'});
        var notifsPanel, notifsList, dismissAll;
        notifsPanel = h("div.cp-app-notifications-panel", [
            h('div.cp-app-notifications-panel-titlebar', [
                h("span.cp-app-notifications-panel-title",
                    (Messages.notificationsPage || "Notifications") + " - " + categoryName),
                h("div.cp-app-notifications-panel-titlebar-buttons", [
                    dismissAll = h("div.cp-app-notifications-dismissall.cp-clickable", { title: Messages.dismissAll || "Dismiss All" }, h("span.fa.fa-trash")),
                ]),
            ]),
            notifsList = h("div.cp-app-notifications-panel-list", [
                h("div.cp-notification.no-notifications", Messages.notifications_empty),
            ]),
        ]);

        // add notification
        var addNotification = function (data, el) {
            // if the type of notification correspond
            if (filterTypes.indexOf(data.content.msg.type) !== -1) {
                notifsData.push(data);
                $(notifsList).prepend(el);
            }
        };
        var addArchivedNotification = function (data) {
            // if the type is allowed
            if (data.content.archived && notifsAllowedTypes.indexOf(data.content.msg.type) !== -1) {
                var isDataUnread = unreadData.findIndex(function (ud) {
                    return ud.content.hash === data.content.hash;
                }) !== -1;
                notifsData.push(data);
                var el = common.mailbox.createElement(data);
                var time = new Date(data.content.time);
                $(el).find(".cp-notification-content").append(h("span.notification-time", time.toLocaleDateString() + " - " + time.toLocaleTimeString()));
                $(el).addClass("cp-app-notification-archived");
                $(el).toggle(!isDataUnread);
                $(notifsList).append(el);
            }
        };

        $div.append(notifsPanel);

        if (key === "archived") {
            var loadmore;
            var lastKnownHash;
            $(dismissAll).remove();
            loadmore = h("div.cp-app-notification-loadmore.cp-clickable", Messages.loadMore || "Load more ...");
            $(loadmore).click(function () {
                common.mailbox.getNotificationsHistory('notifications', 10, lastKnownHash, function (err, messages, end) {
                    if (!Array.isArray(messages)) { return; }
                    // display archived notifs from most recent to oldest
                    for (var i = messages.length - 1 ; i >= 0 ; i--) {
                        var data = messages[i];
                        data.content.archived = true;
                        addArchivedNotification(data);
                    }
                    if (end) {
                        $(loadmore).hide();
                    }
                    else {
                        lastKnownHash = messages[0].content.hash;
                    }
                    $('#cp-sidebarlayout-rightside').scrollTop($('#cp-sidebarlayout-rightside')[0].scrollHeight);
                });
            });
            notifsList.after(loadmore);
            $(loadmore).click();
        }

        common.mailbox.subscribe(["notifications"], {
            onMessage: function (data, el) {
                addNotification(data, el);
            },
            onViewed: function (data) {
                $('.cp-app-notification-archived[data-hash="' + data.hash + '"]').show();
            }
        });

        $(dismissAll).click(function () {
            notifsData.forEach(function (data) {
                if (data.content.isDismissible) {
                    data.content.dismissHandler();
                }
            });
        });

        return $div;
    };
    create['all'] = function () {
        var key = 'all';
        return makeNotificationList(key, notifsAllowedTypes);
    };

    create['friends'] = function () {
        var key = 'friends';
{'fraction_non_alphanumeric': 0.14318462352318814, 'fraction_numerical': 0.001851525304179157, 'mean_word_length': 1.6981446241674596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3486283', 'n_tokens_mistral': 3262, 'n_tokens_neox': 3104, 'n_words': 523}