<commit_before>// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import $ from 'jquery';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import LocalizationStore from 'stores/localization_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import Constants from 'utils/constants.jsx';
var ActionTypes = Constants.ActionTypes;
import * as UserAgent from 'utils/user_agent.jsx';
import {Posts} from 'mattermost-redux/constants';
import {Client4} from 'mattermost-redux/client';

import {browserHistory} from 'react-router/es6';
import {FormattedMessage} from 'react-intl';

import icon50 from 'images/icon50x50.png';
import bing from 'images/bing.mp3';

import React from 'react';

export function isEmail(email) {
    // writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
    // so we just do a simple check and rely on a verification email to tell if it's a real address
    return (/^.+@.+$/).test(email);
}

export function isMac() {
    return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
}

export function createSafeId(prop) {
    if (prop === null) {
        return null;
    }

    var str = '';

    if (prop.props && prop.props.defaultMessage) {
        str = prop.props.defaultMessage;
    } else {
        str = prop.toString();
    }

    return str.replace(new RegExp(' ', 'g'), '_');
}

export function cmdOrCtrlPressed(e, allowAlt = false) {
    if (allowAlt) {
        return (isMac() && e.metaKey) || (!isMac() && e.ctrlKey);
    }
    return (isMac() && e.metaKey) || (!isMac() && e.ctrlKey && !e.altKey);
}

export function isInRole(roles, inRole) {
    var parts = roles.split(' ');
    for (var i = 0; i < parts.length; i++) {
        if (parts[i] === inRole) {
            return true;
        }
    }

    return false;
}

export function isChannelAdmin(roles) {
    if (global.mm_license.IsLicensed !== 'true') {
        return false;
    }

    if (isInRole(roles, 'channel_admin')) {
        return true;
    }

    return false;
}

export function isAdmin(roles) {
    if (isInRole(roles, 'team_admin')) {
        return true;
    }

    if (isInRole(roles, 'system_admin')) {
        return true;
    }

    return false;
}

export function isSystemAdmin(roles) {
    if (isInRole(roles, 'system_admin')) {
        return true;
    }

    return false;
}

export function getCookie(name) {
    var value = '; ' + document.cookie;
    var parts = value.split('; ' + name + '=');
    if (parts.length === 2) {
        return parts.pop().split(';').shift();
    }
    return '';
}

var requestedNotificationPermission = false;

export function notifyMe(title, body, channel, teamId, duration, silent) {
    if (!('Notification' in window)) {
        return;
    }

    let notificationDuration = Constants.DEFAULT_NOTIFICATION_DURATION;
    if (duration != null) {
        notificationDuration = duration;
    }

    if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) {
        requestedNotificationPermission = true;

        Notification.requestPermission((permission) => {
            if (permission === 'granted') {
                try {
                    var notification = new Notification(title, {body, tag: body, icon: icon50, requireInteraction: notificationDuration === 0, silent});
                    notification.onclick = () => {
                        window.focus();
                        if (channel && (channel.type === Constants.DM_CHANNEL || channel.type === Constants.GM_CHANNEL)) {
                            browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name);
                        } else if (channel) {
                            browserHistory.push(TeamStore.getTeamUrl(teamId) + '/channels/' + channel.name);
                        } else if (teamId) {
                            browserHistory.push(TeamStore.getTeamUrl(teamId) + '/channels/town-square');
                        } else {
                            browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square');
                        }
                    };

                    if (notificationDuration > 0) {
                        setTimeout(() => {
                            notification.close();
                        }, notificationDuration);
                    }
                } catch (e) {
                    console.error(e); //eslint-disable-line no-console
                }
            }
        });
    }
}

var canDing = true;

export function ding() {
    if (hasSoundOptions() && canDing) {
        var audio = new Audio(bing);<commit_msg>Fixing logging errors for Franz (#7273)<commit_after>// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import $ from 'jquery';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import LocalizationStore from 'stores/localization_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import Constants from 'utils/constants.jsx';
var ActionTypes = Constants.ActionTypes;
import * as UserAgent from 'utils/user_agent.jsx';
import {Posts} from 'mattermost-redux/constants';
import {Client4} from 'mattermost-redux/client';

import {browserHistory} from 'react-router/es6';
import {FormattedMessage} from 'react-intl';

import icon50 from 'images/icon50x50.png';
import bing from 'images/bing.mp3';

import React from 'react';

export function isEmail(email) {
    // writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
    // so we just do a simple check and rely on a verification email to tell if it's a real address
    return (/^.+@.+$/).test(email);
}

export function isMac() {
    return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
}

export function createSafeId(prop) {
    if (prop === null) {
        return null;
    }

    var str = '';

    if (prop.props && prop.props.defaultMessage) {
        str = prop.props.defaultMessage;
    } else {
        str = prop.toString();
    }

    return str.replace(new RegExp(' ', 'g'), '_');
}

export function cmdOrCtrlPressed(e, allowAlt = false) {
    if (allowAlt) {
        return (isMac() && e.metaKey) || (!isMac() && e.ctrlKey);
    }
    return (isMac() && e.metaKey) || (!isMac() && e.ctrlKey && !e.altKey);
}

export function isInRole(roles, inRole) {
    var parts = roles.split(' ');
    for (var i = 0; i < parts.length; i++) {
        if (parts[i] === inRole) {
            return true;
        }
    }

    return false;
}

export function isChannelAdmin(roles) {
    if (global.mm_license.IsLicensed !== 'true') {
        return false;
    }

    if (isInRole(roles, 'channel_admin')) {
        return true;
    }

    return false;
}

export function isAdmin(roles) {
    if (isInRole(roles, 'team_admin')) {
        return true;
    }

    if (isInRole(roles, 'system_admin')) {
        return true;
    }

    return false;
}

export function isSystemAdmin(roles) {
    if (isInRole(roles, 'system_admin')) {
        return true;
    }

    return false;
}

export function getCookie(name) {
    var value = '; ' + document.cookie;
    var parts = value.split('; ' + name + '=');
    if (parts.length === 2) {
        return parts.pop().split(';').shift();
    }
    return '';
}

var requestedNotificationPermission = false;

export function notifyMe(title, body, channel, teamId, duration, silent) {
    if (!('Notification' in window)) {
        return;
    }

    let notificationDuration = Constants.DEFAULT_NOTIFICATION_DURATION;
    if (duration != null) {
        notificationDuration = duration;
    }

    if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) {
        requestedNotificationPermission = true;

        if (typeof Notification.requestPermission === 'function') {
            Notification.requestPermission((permission) => {
                if (permission === 'granted') {
                    try {
                        var notification = new Notification(title, {body, tag: body, icon: icon50, requireInteraction: notificationDuration === 0, silent});
                        notification.onclick = () => {
                            window.focus();
                            if (channel && (channel.type === Constants.DM_CHANNEL || channel.type === Constants.GM_CHANNEL)) {
                                browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name);
                            } else if (channel) {
                                browserHistory.push(TeamStore.getTeamUrl(teamId) + '/channels/' + channel.name);
                            } else if (teamId) {
                                browserHistory.push(TeamStore.getTeamUrl(teamId) + '/channels/town-square');
                            } else {
                                browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square');
                            }
                        };

                        if (notificationDuration > 0) {
                            setTimeout(() => {
                                notification.close();
                            }, notificationDuration);
                        }
                    } catch (e) {
                        console.error(e); //eslint-disable-line no-console
                    }
                }
            });
        }
    }
}

var canDing = true;

export function ding() {
    if (hasSoundOptions() && canDing) {
        var audio = new Audio(bing);
{'fraction_non_alphanumeric': 0.1292469699980131, 'fraction_numerical': 0.005563282336578581, 'mean_word_length': 2.234897172236504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2526443', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2795, 'n_words': 694}