<commit_before>﻿/// <reference path="validation-controler.js" />
/// <reference path="Class.js" />
/// <reference path="../jquery-2.0.2.js" />
/// <reference path="persister.js" />
/// <reference path="ui.js" />

$(document).ready(function () {
    var myMainPersister = persister.mainPersister('http://localhost:47655/api');//47655

    // Check is user logged in
    if (localStorage.getItem('authCode') == '' || localStorage.getItem('authCode') == null || localStorage.getItem('authCode') == undefined) {
        $('#login-container').html(ui.drawLogIn());
    }
    else {
        $('#login-container').html(ui.drawLoggedIn());
        $('#main-chat-container').html(ui.drawUserInteraction());
        $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
    }

    var int = self.setInterval(function () {
        if (localStorage.getItem('authCode') != '') {
        }
        else {
            window.clearInterval(int);
        }
    }, 5000);

    var eventControler = (function () {
        var pubnub = PUBNUB.init({
            publish_key: '<KEY>',
            subscribe_key: 'sub-c-834dd9e0-04b8-11e3-8dc9-02ee2ddab7fe',
            origin: 'pubsub.pubnub.com',
            ssl: 'off'
        })

        function addElementsEvents(persister) {
            // Logout
            $('#wrapper').on('click', '#user-loged-in #button-logout', function () {
                $('#login-container').empty();
                $('#left-side-bar').empty();
                $('#right-side-bar').empty();
                $('#main-chat-container').empty();
                $('#current-chat-state').empty();
                $('#main-chat-container').append($('<div />').attr('id', 'error-messages'));
                $('#main-chat-container').append($('<div />').attr('id', 'messages'));
                $('#login-container').html(ui.drawLogIn());

                persister.user.logout();
            });

            // Log in
            $('#wrapper').on('click', '#button-log-in', function () {
                var username = $('#login-user-nickname').val();
                var password = $('#login-user-password').val();

                ui.clearErrorMessage();
                persister.user.login(username, password, ui.showErrorMessage);
                setTimeout(function () {
                    if (localStorage.getItem('authCode') != '' && localStorage.getItem('authCode') != undefined) {
                        ui.clearErrorMessage();
                        $('#login-container').html(ui.drawLoggedIn());
                        $('#main-chat-container').html(ui.drawUserInteraction());
                        $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
                    }
                }, 500);
            });

            // Register now
            $('#wrapper').on('click', '#register-now', function () {
                $('#login-container').html(ui.drawRegister());
            });

            // Register back
            $('#wrapper').on('click', '#back-to-homepage', function () {
                $('#login-container').html(ui.drawLogIn());
            });

            // Send register request
            $('#wrapper').on('click', '#button-register', function () {
                var username = $('#register-user-nickname').val();
                var nickname = $('#register-user-nickname').val();
                var password = $('#register-user-password').val();
                var passwordRe = $('#register-user-password-re').val();

                var isUsernameValid = validationControler.isUsernameCorrect(username);
                var isPasswordValid = validationControler.isPasswordCorrect(password);
                var isPasswordsEqual = password === passwordRe;

                if (isUsernameValid && isPasswordValid && isPasswordsEqual) {
                    persister.user.register(username, nickname, password, ui.showErrorMessage);
                    setTimeout(function () {
                        $('#login-container').html(ui.drawLoggedIn());
                        ui.clearErrorMessage();
                    }, 500);
                }
                else {
                    ui.showAppErrorMessage('Invalid username or password! Check your account information and try again.');
                }
            });

            // Send message
            $('#wrapper').on('click', '#confirm-send', function () {
                var messageText = $('#message-text').val();
                var userID = $(this).attr('data-user-id');
                var chatID = $(this).attr('data-chat-id');
                var channelID = $(this).attr('data-channel-id');

                persister.chat.sendMessage(userID, messageText, function () {
                    persister.messages.all(chatID,
                    function (data) {
                        ui.drawMessages(data);
                    }),
                    function () {
                        console.log("Message is not send.");
                    }
                });

                // SEND
                function publish(channel, messageText) {
                    pubnub.publish({
                        channel: channelID,
                        message: messageText
                    })
                }

                $('#message-text').val('');
            });

            // Create new chat
            $('#wrapper').on('click', '#users-user-list li a', function () {
                var userID = $(this).parent('li').attr('data-user-id');

                persister.chat.create(userID, function () {
                    $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
                },
                ui.showErrorMessage);
            });

            // Open chat window
            $('#wrapper').on('click', '#chats-active-list li a', function () {
                var chatID = $(this).parent('li').attr('data-chat-id');
                var channelID = $(this).parent('li').attr('data-chat-channel');
                var otherUserID = $(this).parent('li').attr('data-user-id');

                $('#current-chat-container').html(ui.drawSendMessageMenu(otherUserID, chatID, channelID));

                persister.messages.all(chatID,
                    function (data) {
                        ui.drawMessages(data);
                    })
<commit_msg>Fix pubnub<commit_after>﻿/// <reference path="validation-controler.js" />
/// <reference path="Class.js" />
/// <reference path="../jquery-2.0.2.js" />
/// <reference path="persister.js" />
/// <reference path="ui.js" />

$(document).ready(function () {
    var myMainPersister = persister.mainPersister('http://localhost:47655/api');//47655

    // Check is user logged in
    if (localStorage.getItem('authCode') == '' || localStorage.getItem('authCode') == null || localStorage.getItem('authCode') == undefined) {
        $('#login-container').html(ui.drawLogIn());
    }
    else {
        $('#login-container').html(ui.drawLoggedIn());
        $('#main-chat-container').html(ui.drawUserInteraction());
        $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
    }

    var int = self.setInterval(function () {
        if (localStorage.getItem('authCode') != '') {
        }
        else {
            window.clearInterval(int);
        }
    }, 5000);

    var eventControler = (function () {
        var pubnub = PUBNUB.init({
            publish_key: '<KEY>',
            subscribe_key: 'sub-c-834dd9e0-04b8-11e3-8dc9-02ee2ddab7fe',
            origin: 'pubsub.pubnub.com',
            ssl: 'off'
        })

        function addElementsEvents(persister) {
            // Logout
            $('#wrapper').on('click', '#user-loged-in #button-logout', function () {
                $('#login-container').empty();
                $('#left-side-bar').empty();
                $('#right-side-bar').empty();
                $('#main-chat-container').empty();
                $('#current-chat-state').empty();
                $('#main-chat-container').append($('<div />').attr('id', 'error-messages'));
                $('#main-chat-container').append($('<div />').attr('id', 'messages'));
                $('#login-container').html(ui.drawLogIn());

                persister.user.logout();
            });

            // Log in
            $('#wrapper').on('click', '#button-log-in', function () {
                var username = $('#login-user-nickname').val();
                var password = $('#login-user-password').val();

                ui.clearErrorMessage();
                persister.user.login(username, password, ui.showErrorMessage);
                setTimeout(function () {
                    if (localStorage.getItem('authCode') != '' && localStorage.getItem('authCode') != undefined) {
                        ui.clearErrorMessage();
                        $('#login-container').html(ui.drawLoggedIn());
                        $('#main-chat-container').html(ui.drawUserInteraction());
                        $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
                    }
                }, 500);
            });

            // Register now
            $('#wrapper').on('click', '#register-now', function () {
                $('#login-container').html(ui.drawRegister());
            });

            // Register back
            $('#wrapper').on('click', '#back-to-homepage', function () {
                $('#login-container').html(ui.drawLogIn());
            });

            // Send register request
            $('#wrapper').on('click', '#button-register', function () {
                var username = $('#register-user-nickname').val();
                var nickname = $('#register-user-nickname').val();
                var password = $('#<PASSWORD>').val();
                var passwordRe = $('#register-<PASSWORD>-password-re').val();

                var isUsernameValid = validationControler.isUsernameCorrect(username);
                var isPasswordValid = validationControler.isPasswordCorrect(password);
                var isPasswordsEqual = <PASSWORD>;

                if (isUsernameValid && isPasswordValid && isPasswordsEqual) {
                    persister.user.register(username, nickname, password, ui.showErrorMessage);
                    setTimeout(function () {
                        $('#login-container').html(ui.drawLoggedIn());
                        ui.clearErrorMessage();
                    }, 500);
                }
                else {
                    ui.showAppErrorMessage('Invalid username or password! Check your account information and try again.');
                }
            });

            // Send message
            $('#wrapper').on('click', '#confirm-send', function () {
                var messageText = $('#message-text').val();
                var userID = $(this).attr('data-user-id');
                var chatID = $(this).attr('data-chat-id');
                var channelID = $(this).attr('data-channel-id');

                persister.chat.sendMessage(userID, messageText, function () {
                    persister.messages.all(chatID,
                    function (data) {
                        ui.drawMessages(data);
                    }),
                    function () {
                        console.log("Message is not send.");
                    }
                });

                // SEND
                pubnub.publish({
                    channel: channelID,
                    message: localStorage.getItem('userNickname') + ': ' + messageText
                });

                $('#message-text').val('');
            });

            // Create new chat
            $('#wrapper').on('click', '#users-user-list li a', function () {
                var userID = $(this).parent('li').attr('data-user-id');

                persister.chat.create(userID, function () {
                    $('#left-side-bar').html(ui.drawSidebars(myMainPersister));
                },
                ui.showErrorMessage);
            });

            // Open chat window
            $('#wrapper').on('click', '#chats-active-list li a', function () {
                var chatID = $(this).parent('li').attr('data-chat-id');
                var channelID = $(this).parent('li').attr('data-chat-channel');
                var otherUserID = $(this).parent('li').attr('data-user-id');

                $('#current-chat-container').html(ui.drawSendMessageMenu(otherUserID, chatID, channelID));

                persister.messages.all(chatID,
                    function (data) {
                        ui.drawMessages(data);
                    })

{'fraction_non_alphanumeric': 0.17134475103076435, 'fraction_numerical': 0.006343165239454488, 'mean_word_length': 1.626067041432438, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '4734349', 'n_tokens_mistral': 3306, 'n_tokens_neox': 3141, 'n_words': 478}