<commit_before>/* global libquassel */
/* global angular */
/* global Favico */
/* global localStorage */
/* global Notification */
/* global $ */

angular.module('quassel', ['ngQuassel', 'ngAria', 'ngSanitize', 'ui.bootstrap', 'dragAndDrop', 'cgNotify', 'luegg.directives'])
.config(['$compileProvider', function ($compileProvider) {
    if (!localStorage.getItem('debug')) {
        $compileProvider.debugInfoEnabled(false);
    }
}])
.factory('$responsive', ['$window', function ($window) {
    return {
        getBreakpoint: function () {
            var w = $window.innerWidth;
            if (w < 768) {
                return 'xs';
            } else if (w < 992) {
                return 'sm';
            } else if (w < 1200) {
                return 'md';
            } else {
                return 'lg';
            }
        }
    };
}])
.factory('$ignore', ['$quassel', function($quassel){
    var IgnoreList = libquassel.ignore.IgnoreList;
    var IgnoreItem = libquassel.ignore.IgnoreItem;
    var ignoreList = new IgnoreList();
    var savedIgnoreList = null;
    var ignoreListRevision = 0;
    return {
        createItem: function() {
            ignoreList.list.push(new IgnoreItem(1, '', 0, 0, 1, 0, 'rule'));
        },
        deleteItem: function(indice) {
            if (ignoreList.list[indice]) {
                ignoreList.list.splice(indice, 1);
            }
        },
        getList: function() {
            return ignoreList;
        },
        restoreSavedList: function() {
            ignoreList = angular.copy(savedIgnoreList);
        },
        setList: function(obj) {
            ignoreList = obj;
            savedIgnoreList = angular.copy(ignoreList);
        },
        getRevision: function() {
            return ignoreListRevision;
        },
        incRevision: function() {
            ignoreListRevision++;
        },
        save: function() {
            savedIgnoreList = angular.copy(ignoreList);
            $quassel.core().updateIgnoreListManager(ignoreList.export());
        }
    };
}])
.factory('$highlight', ['$quassel', function($quassel){
    var HighlightRuleManager = libquassel.highlight.HighlightRuleManager;
    var HighlightRule = libquassel.highlight.HighlightRule;
    var highlightRuleManager = new HighlightRuleManager();
    var savedHighlightRuleManager = null;
    var highlightRuleManagerRevision = 0;
    return {
        createRule: function() {
            highlightRuleManager.list.push(new HighlightRule('', false, false, true, false, '', ''));
        },
        deleteRule: function(indice) {
            if (highlightRuleManager.list[indice]) {
                highlightRuleManager.list.splice(indice, 1);
            }
        },
        getManager: function() {
            return highlightRuleManager;
        },
        restoreSavedManager: function() {
            highlightRuleManager = angular.copy(savedHighlightRuleManager);
        },
        setManager: function(obj) {
            highlightRuleManager = obj;
            savedHighlightRuleManager = angular.copy(highlightRuleManager);
        },
        getRevision: function() {
            return highlightRuleManagerRevision;
        },
        incRevision: function() {
            highlightRuleManagerRevision++;
        },
        save: function() {
            savedHighlightRuleManager = angular.copy(highlightRuleManager);
            $quassel.core().updateHighlightRuleManager(highlightRuleManager.export());
        }
    };
}])
.factory('$config', ['$rootScope', '$http', '$alert', function($rootScope, $http, $alert){

    function set(key, val, raw) {
        localStorage.setItem(key, raw ? val : JSON.stringify(val));
        if (keys[key]) {
            for (var x in keys[key]) {
                keys[key][x](val);
            }
        }
        $rootScope.$emit('config.'+key, val);
    }
    
    function del(key) {
        localStorage.removeItem(key);
    }
    
    function get(key, defval, raw) {
        var myitem = localStorage.getItem(key);
        if (myitem === null) return defval;
        try {
            return raw ? myitem : JSON.parse(myitem);
        } catch (e) {
            console.log(e);
            localStorage.removeItem(key);
        }
        return null;
    }
    
    function has(key) {
        return key in localStorage;
    }

    var keys = {};
    var configurationKeys = ['initialBacklogLimit', 'backlogLimit', 'securecore', 'theme', 'themes'];
    var ind;
    var missingKeys = false;
    for (var ind in configurationKeys) {
        if (localStorage.getItem(configurationKeys[ind]) === null) {
            missingKeys = true;
            break;
        }
    }
    $http.get("settings")
    .then(function(response) {
        var data = response.data;
        if (localStorage.length > 0 && data.version !== get('version')) {
            $alert.warn("Local settings replaced by default settings (new version)");
            localStorage.clear();
            missingKeys = true;
            set('version', data.version);
        }
        if (missingKeys) {
            set('host', data.settings.host);
            set('port', data.settings.port);
            set('initialBacklogLimit', data.settings.initialBacklogLimit);
            set('backlogLimit', data.settings.backlogLimit);
            set('securecore', data.settings.securecore || true);
            set('theme', data.settings.theme);
            set('perchathistory', data.settings.perchathistory);
            set('displayfullhostmask', data.settings.displayfullhostmask);
            set('highlightmode', data.settings.highlightmode);
            if (typeof data.settings.emptybufferonswitch === 'number') {
                set('emptybufferonswitch', true);
                set('emptybufferonswitchvalue', data.settings.emptybufferonswitch);
            } else {
                set('emptybufferonswitch', false);
            }
        }
        set('themes', data.themes || ['default', 'darksolarized']);
        $rootScope.$emit('defaultsettings', true);
    }).catch(function(response) {
        $alert.warn("Could not load settings. Check nodejs logs.");
        if (missingKeys) {
            set('host', '');
            set('port', 4242);
            set('initialBacklogLimit', 20);
            set('backlogLimit', 100);<commit_msg>settings: Fix ignoring 'securecore: false' default (#290)<commit_after>/* global libquassel */
/* global angular */
/* global Favico */
/* global localStorage */
/* global Notification */
/* global $ */

angular.module('quassel', ['ngQuassel', 'ngAria', 'ngSanitize', 'ui.bootstrap', 'dragAndDrop', 'cgNotify', 'luegg.directives'])
.config(['$compileProvider', function ($compileProvider) {
    if (!localStorage.getItem('debug')) {
        $compileProvider.debugInfoEnabled(false);
    }
}])
.factory('$responsive', ['$window', function ($window) {
    return {
        getBreakpoint: function () {
            var w = $window.innerWidth;
            if (w < 768) {
                return 'xs';
            } else if (w < 992) {
                return 'sm';
            } else if (w < 1200) {
                return 'md';
            } else {
                return 'lg';
            }
        }
    };
}])
.factory('$ignore', ['$quassel', function($quassel){
    var IgnoreList = libquassel.ignore.IgnoreList;
    var IgnoreItem = libquassel.ignore.IgnoreItem;
    var ignoreList = new IgnoreList();
    var savedIgnoreList = null;
    var ignoreListRevision = 0;
    return {
        createItem: function() {
            ignoreList.list.push(new IgnoreItem(1, '', 0, 0, 1, 0, 'rule'));
        },
        deleteItem: function(indice) {
            if (ignoreList.list[indice]) {
                ignoreList.list.splice(indice, 1);
            }
        },
        getList: function() {
            return ignoreList;
        },
        restoreSavedList: function() {
            ignoreList = angular.copy(savedIgnoreList);
        },
        setList: function(obj) {
            ignoreList = obj;
            savedIgnoreList = angular.copy(ignoreList);
        },
        getRevision: function() {
            return ignoreListRevision;
        },
        incRevision: function() {
            ignoreListRevision++;
        },
        save: function() {
            savedIgnoreList = angular.copy(ignoreList);
            $quassel.core().updateIgnoreListManager(ignoreList.export());
        }
    };
}])
.factory('$highlight', ['$quassel', function($quassel){
    var HighlightRuleManager = libquassel.highlight.HighlightRuleManager;
    var HighlightRule = libquassel.highlight.HighlightRule;
    var highlightRuleManager = new HighlightRuleManager();
    var savedHighlightRuleManager = null;
    var highlightRuleManagerRevision = 0;
    return {
        createRule: function() {
            highlightRuleManager.list.push(new HighlightRule('', false, false, true, false, '', ''));
        },
        deleteRule: function(indice) {
            if (highlightRuleManager.list[indice]) {
                highlightRuleManager.list.splice(indice, 1);
            }
        },
        getManager: function() {
            return highlightRuleManager;
        },
        restoreSavedManager: function() {
            highlightRuleManager = angular.copy(savedHighlightRuleManager);
        },
        setManager: function(obj) {
            highlightRuleManager = obj;
            savedHighlightRuleManager = angular.copy(highlightRuleManager);
        },
        getRevision: function() {
            return highlightRuleManagerRevision;
        },
        incRevision: function() {
            highlightRuleManagerRevision++;
        },
        save: function() {
            savedHighlightRuleManager = angular.copy(highlightRuleManager);
            $quassel.core().updateHighlightRuleManager(highlightRuleManager.export());
        }
    };
}])
.factory('$config', ['$rootScope', '$http', '$alert', function($rootScope, $http, $alert){

    function set(key, val, raw) {
        localStorage.setItem(key, raw ? val : JSON.stringify(val));
        if (keys[key]) {
            for (var x in keys[key]) {
                keys[key][x](val);
            }
        }
        $rootScope.$emit('config.'+key, val);
    }
    
    function del(key) {
        localStorage.removeItem(key);
    }
    
    function get(key, defval, raw) {
        var myitem = localStorage.getItem(key);
        if (myitem === null) return defval;
        try {
            return raw ? myitem : JSON.parse(myitem);
        } catch (e) {
            console.log(e);
            localStorage.removeItem(key);
        }
        return null;
    }
    
    function has(key) {
        return key in localStorage;
    }

    var keys = {};
    var configurationKeys = ['initialBacklogLimit', 'backlogLimit', 'securecore', 'theme', 'themes'];
    var ind;
    var missingKeys = false;
    for (var ind in configurationKeys) {
        if (localStorage.getItem(configurationKeys[ind]) === null) {
            missingKeys = true;
            break;
        }
    }
    $http.get("settings")
    .then(function(response) {
        var data = response.data;
        if (localStorage.length > 0 && data.version !== get('version')) {
            $alert.warn("Local settings replaced by default settings (new version)");
            localStorage.clear();
            missingKeys = true;
            set('version', data.version);
        }
        if (missingKeys) {
            set('host', data.settings.host);
            set('port', data.settings.port);
            set('initialBacklogLimit', data.settings.initialBacklogLimit);
            set('backlogLimit', data.settings.backlogLimit);
            set('securecore', (typeof data.settings.securecore === 'boolean' ? data.settings.securecore : true));
            set('theme', data.settings.theme);
            set('perchathistory', data.settings.perchathistory);
            set('displayfullhostmask', data.settings.displayfullhostmask);
            set('highlightmode', data.settings.highlightmode);
            if (typeof data.settings.emptybufferonswitch === 'number') {
                set('emptybufferonswitch', true);
                set('emptybufferonswitchvalue', data.settings.emptybufferonswitch);
            } else {
                set('emptybufferonswitch', false);
            }
        }
        set('themes', data.themes || ['default', 'darksolarized']);
        $rootScope.$emit('defaultsettings', true);
    }).catch(function(response) {
        $alert.warn("Could not load settings. Check nodejs logs.");
        if (missingKeys) {
            set('host', '');
            set('port', 4242);
            set('initialBacklogLimit', 20);
            set('backlogLimit', 100);
{'fraction_non_alphanumeric': 0.13371042501374814, 'fraction_numerical': 0.004792206771938094, 'mean_word_length': 2.129301868239921, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7538325', 'n_tokens_mistral': 3550, 'n_tokens_neox': 3411, 'n_words': 682}