<commit_before>const BinarySocket         = require('./socket');
const updateBalance        = require('./user/update_balance');
const Client               = require('../base/client');
const Clock                = require('../base/clock');
const GTM                  = require('../base/gtm');
const Header               = require('../base/header');
const Login                = require('../base/login');
const getPropertyValue     = require('../base/utility').getPropertyValue;
const jpResidence          = require('../common_functions/country_base').jpResidence;
const SessionDurationLimit = require('../common_functions/session_duration_limit');
const Cookies              = require('../../lib/js-cookie');

const BinarySocketGeneral = (() => {
    'use strict';

    const onOpen = (is_ready) => {
        Header.hideNotification();
        if (is_ready) {
            if (!Login.isLoginPages()) {
                Client.validateLoginid();
                BinarySocket.send({ website_status: 1, subscribe: 1 });
            }
            Clock.startClock();
        }
    };

    const onMessage = (response) => {
        Header.hideNotification('CONNECTION_ERROR');
        let is_available;
        switch (response.msg_type) {
            case 'website_status':
                is_available = /^up$/i.test(getPropertyValue(response, ['website_status', 'site_status']));
                if (is_available && !BinarySocket.availability()) {
                    window.location.reload();
                } else if (!is_available) {
                    Header.displayNotification(response.website_status.message, true);
                }
                BinarySocket.availability(is_available);
                break;
            case 'authorize':
                if (response.error) {
                    const is_active_tab = sessionStorage.getItem('active_tab') === '1';
                    if (getPropertyValue(response, ['error', 'code']) === 'SelfExclusion' && is_active_tab) {
                        sessionStorage.removeItem('active_tab');
                        window.alert(response.error.message);
                    }
                    Client.sendLogoutRequest(is_active_tab);
                } else if (response.authorize.loginid !== Cookies.get('loginid')) {
                    Client.sendLogoutRequest(true);
                } else {
                    if (!Login.isLoginPages()) {
                        Client.responseAuthorize(response);
                        BinarySocket.send({ balance: 1, subscribe: 1 });
                        BinarySocket.send({ get_settings: 1 });
                        BinarySocket.send({ get_account_status: 1 });
                        BinarySocket.send({ payout_currencies: 1 });
                        BinarySocket.send({ mt5_login_list: 1 });
                        setResidence(response.authorize.country || Cookies.get('residence'));
                        if (!Client.get('is_virtual') && !jpResidence()) {
                            BinarySocket.send({ get_self_exclusion: 1 });
                            // TODO: remove this when back-end adds it as a status to get_account_status
                            BinarySocket.send({ get_financial_assessment: 1 });
                        }
                    }
                    BinarySocket.sendBuffered();
                }
                break;
            case 'balance':
                updateBalance(response);
                break;
            case 'logout':
                Client.doLogout(response);
                break;
            case 'landing_company':
                Header.upgradeMessageVisibility();
                if (!response.error) {
                    // Header.metatraderMenuItemVisibility(response); // to be uncommented once MetaTrader launched
                    const company = Client.currentLandingCompany();
                    if (company) {
                        Client.set('default_currency', company.legal_default_currency);
                    }
                }
                break;
            case 'get_self_exclusion':
                SessionDurationLimit.exclusionResponseHandler(response);
                break;
            case 'payout_currencies':
                Client.set('currencies', response.payout_currencies.join(','));
                break;
            case 'get_settings':
                if (response.get_settings) {
                    setResidence(response.get_settings.country_code);<commit_msg>Fix session duration limit for JP clients<commit_after>const BinarySocket         = require('./socket');
const updateBalance        = require('./user/update_balance');
const Client               = require('../base/client');
const Clock                = require('../base/clock');
const GTM                  = require('../base/gtm');
const Header               = require('../base/header');
const Login                = require('../base/login');
const getPropertyValue     = require('../base/utility').getPropertyValue;
const jpResidence          = require('../common_functions/country_base').jpResidence;
const SessionDurationLimit = require('../common_functions/session_duration_limit');
const Cookies              = require('../../lib/js-cookie');

const BinarySocketGeneral = (() => {
    'use strict';

    const onOpen = (is_ready) => {
        Header.hideNotification();
        if (is_ready) {
            if (!Login.isLoginPages()) {
                Client.validateLoginid();
                BinarySocket.send({ website_status: 1, subscribe: 1 });
            }
            Clock.startClock();
        }
    };

    const onMessage = (response) => {
        Header.hideNotification('CONNECTION_ERROR');
        let is_available;
        switch (response.msg_type) {
            case 'website_status':
                is_available = /^up$/i.test(getPropertyValue(response, ['website_status', 'site_status']));
                if (is_available && !BinarySocket.availability()) {
                    window.location.reload();
                } else if (!is_available) {
                    Header.displayNotification(response.website_status.message, true);
                }
                BinarySocket.availability(is_available);
                break;
            case 'authorize':
                if (response.error) {
                    const is_active_tab = sessionStorage.getItem('active_tab') === '1';
                    if (getPropertyValue(response, ['error', 'code']) === 'SelfExclusion' && is_active_tab) {
                        sessionStorage.removeItem('active_tab');
                        window.alert(response.error.message);
                    }
                    Client.sendLogoutRequest(is_active_tab);
                } else if (response.authorize.loginid !== Cookies.get('loginid')) {
                    Client.sendLogoutRequest(true);
                } else {
                    if (!Login.isLoginPages()) {
                        Client.responseAuthorize(response);
                        BinarySocket.send({ balance: 1, subscribe: 1 });
                        BinarySocket.send({ get_settings: 1 });
                        BinarySocket.send({ get_account_status: 1 });
                        BinarySocket.send({ payout_currencies: 1 });
                        BinarySocket.send({ mt5_login_list: 1 });
                        setResidence(response.authorize.country || Cookies.get('residence'));
                        if (!Client.get('is_virtual')) {
                            BinarySocket.send({ get_self_exclusion: 1 });
                            if (!jpResidence()) {
                                // TODO: remove this when back-end adds it as a status to get_account_status
                                BinarySocket.send({ get_financial_assessment: 1 });
                            }
                        }
                    }
                    BinarySocket.sendBuffered();
                }
                break;
            case 'balance':
                updateBalance(response);
                break;
            case 'logout':
                Client.doLogout(response);
                break;
            case 'landing_company':
                Header.upgradeMessageVisibility();
                if (!response.error) {
                    // Header.metatraderMenuItemVisibility(response); // to be uncommented once MetaTrader launched
                    const company = Client.currentLandingCompany();
                    if (company) {
                        Client.set('default_currency', company.legal_default_currency);
                    }
                }
                break;
            case 'get_self_exclusion':
                SessionDurationLimit.exclusionResponseHandler(response);
                break;
            case 'payout_currencies':
                Client.set('currencies', response.payout_currencies.join(','));
                break;
            case 'get_settings':
                if (response.get_settings) {
                    setResidence(response.get_settings.country_code);
{'fraction_non_alphanumeric': 0.11174785100286533, 'fraction_numerical': 0.0026449195503636764, 'mean_word_length': 1.5145469659185369, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1560002', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2042, 'n_words': 380}