<commit_before>springChatServices.factory('RoomsFactory', ['$injector', '$route', '$routeParams', '$http', '$location', '$interval', '$cookies', '$timeout', 'toaster', 'ChatSocket', '$cookieStore', '$q', '$sce', '$rootScope', 'ChannelFactory', function($injector, $route, $routeParams, $http, $location, $interval, $cookies, $timeout, toaster, chatSocket, $cookieStore, $q, $sce, $rootScope, ChannelFactory) {

    var addRoomWithBot = function(roomName) {
        $http.post(serverPrefix + "/chat/rooms/create/with_bot/", roomName)
        success(function(data, status, headers, config) {
            console.log('room with bot created: ' + roomName)
        }).
        error(function(data, status, headers, config) {
            console.log('creating room with bot failed ')
        });

    };
    var errorMsgTitleNotFound = "Сталася помилка";
    var errorMsgContentNotFound = "Кімната не існує або Ви не є її учасником";
    var lastRoomBindings = [];
    var currentRoom = null;
    var messages = [];
    var participants = [];
    var roomType = -1;
    var ajaxRequestsForRoomLP = [];
    var message_busy = true;
    var rooms = [];

    /*var updateContactsMapFromArray = function(contactsList) {
        for (var key in Object.keys(roomsMap))
            delete roomsMap[key];
        for (var i = 0; i < contactsList.length; i++) {
            var contact = contactsList[i];
            var characterForGroup = contact.string.charAt(0);
            if (roomsMap[characterForGroup] == null) {
                roomsMap[characterForGroup] = [];
            }
            roomsMap[characterForGroup].push(contact);
        }
    }*/

    var findParticipant = function(nickname) {
        for (var c_index in participants)
            if (participants[c_index].username == nickname)
                return participants[c_index];
        return null;
    }

    var setParticipantOnline = function(chatUserId) { //$rootScope.$on("login", function(event, chatUserId)
        for (var index in participants) {
            if (participants[index].chatUserId == chatUserId) {
                participants[index].online = true;
                break;
            }
        }
    };

    var setParticipantOffline = function(chatUserId) {
        for (var index in participants) {
            if (participants[index].chatUserId == chatUserId) {
                participants[index].online = false;
                break;
            }
        }
    };
    var unsubscribeWatch = null;

    var goToRoom = function(roomId) {
        //console.log("roomName:"+roomName);
        if (!$rootScope.isInited) {
            unsubscribeWatch = $rootScope.$watch('isInited', function(newValue, oldValue) {
                if (newValue == true) {
                    goToRoom(roomId);
                }
            });
            return;
        } else {
            if (unsubscribeWatch != undefined)
                unsubscribeWatch();
        }

        if (currentRoom !== undefined && getRoomById(rooms, currentRoom) !== undefined)
            getRoomById(rooms, currentRoom.roomId).date = curentDateInJavaFromat();
        return goToRoomEvn(roomId);
    };

    var goToRoomById = function(roomId) {
        console.log("roomId:" + roomId);
        return goToRoomEvn(roomId).then(function() {
            if (currentRoom !== undefined && getRoomById(rooms, currentRoom) !== undefined)
                getRoomById(rooms, currentRoom.roomId).date = curentDateInJavaFromat();
        });

    };

    function goToRoomEvn(id) {
        console.log("goToRoomEvn(" + id + ")");
        currentRoom = { roomId: id };
        changeRoom();
        var deferred = $q.defer();
        var room = getRoomById(rooms, id);
        if (room != undefined) {
            currentRoom = room;
            room.nums = 0;
        } else {
            deferred.reject();
            return deferred.promise;
        }

        if (ChannelFactory.isSocketSupport() === true) {
            chatSocket.send("/app/chat.go.to.dialog/{0}".format(currentRoom.roomId), {}, JSON.stringify({}));
            deferred.resolve();
            return deferred.promise;
        } else {
            return $http.post(serverPrefix + "/chat.go.to.dialog/{0}".format(currentRoom.roomId));
        }
    }
        var NEXT_MESSAGE_TIME_LIMIT_SECONDS = 10;
    function calcPositionUnshift(msg) {
        if (msg == null)
            return null;
        //     msg.message = msg.message.escapeHtml();//WRAP HTML CODE
        var summarised = false;
        oldMessage = msg;

        if (messages.length > 0) {
            if (messages[0].username == msg.username) {
                if (msg.attachedFiles.length == 0) {
                    summarised = true;
                    messages[0].message = msg.message + "\n\n" + messages[0].message;
                    //  $scope.messages[0].date = msg.date;
                }
                msg.position = messages[0].position;

            } else {
                msg.position = !messages[0].position;
            }
        } else {
            msg.position = false;<commit_msg>fix calcPositionUnshift<commit_after>springChatServices.factory('RoomsFactory', ['$injector', '$route', '$routeParams', '$http', '$location', '$interval', '$cookies', '$timeout', 'toaster', 'ChatSocket', '$cookieStore', '$q', '$sce', '$rootScope', 'ChannelFactory', function($injector, $route, $routeParams, $http, $location, $interval, $cookies, $timeout, toaster, chatSocket, $cookieStore, $q, $sce, $rootScope, ChannelFactory) {

    var addRoomWithBot = function(roomName) {
        $http.post(serverPrefix + "/chat/rooms/create/with_bot/", roomName)
        success(function(data, status, headers, config) {
            console.log('room with bot created: ' + roomName)
        }).
        error(function(data, status, headers, config) {
            console.log('creating room with bot failed ')
        });

    };
    var errorMsgTitleNotFound = "Сталася помилка";
    var errorMsgContentNotFound = "Кімната не існує або Ви не є її учасником";
    var lastRoomBindings = [];
    var currentRoom = null;
    var messages = [];
    var participants = [];
    var roomType = -1;
    var ajaxRequestsForRoomLP = [];
    var message_busy = true;
    var rooms = [];

    /*var updateContactsMapFromArray = function(contactsList) {
        for (var key in Object.keys(roomsMap))
            delete roomsMap[key];
        for (var i = 0; i < contactsList.length; i++) {
            var contact = contactsList[i];
            var characterForGroup = contact.string.charAt(0);
            if (roomsMap[characterForGroup] == null) {
                roomsMap[characterForGroup] = [];
            }
            roomsMap[characterForGroup].push(contact);
        }
    }*/

    var findParticipant = function(nickname) {
        for (var c_index in participants)
            if (participants[c_index].username == nickname)
                return participants[c_index];
        return null;
    }

    var setParticipantOnline = function(chatUserId) { //$rootScope.$on("login", function(event, chatUserId)
        for (var index in participants) {
            if (participants[index].chatUserId == chatUserId) {
                participants[index].online = true;
                break;
            }
        }
    };

    var setParticipantOffline = function(chatUserId) {
        for (var index in participants) {
            if (participants[index].chatUserId == chatUserId) {
                participants[index].online = false;
                break;
            }
        }
    };
    var unsubscribeWatch = null;

    var goToRoom = function(roomId) {
        //console.log("roomName:"+roomName);
        if (!$rootScope.isInited) {
            unsubscribeWatch = $rootScope.$watch('isInited', function(newValue, oldValue) {
                if (newValue == true) {
                    goToRoom(roomId);
                }
            });
            return;
        } else {
            if (unsubscribeWatch != undefined)
                unsubscribeWatch();
        }

        if (currentRoom !== undefined && getRoomById(rooms, currentRoom) !== undefined)
            getRoomById(rooms, currentRoom.roomId).date = curentDateInJavaFromat();
        return goToRoomEvn(roomId);
    };

    var goToRoomById = function(roomId) {
        console.log("roomId:" + roomId);
        return goToRoomEvn(roomId).then(function() {
            if (currentRoom !== undefined && getRoomById(rooms, currentRoom) !== undefined)
                getRoomById(rooms, currentRoom.roomId).date = curentDateInJavaFromat();
        });

    };

    function goToRoomEvn(id) {
        console.log("goToRoomEvn(" + id + ")");
        currentRoom = { roomId: id };
        changeRoom();
        var deferred = $q.defer();
        var room = getRoomById(rooms, id);
        if (room != undefined) {
            currentRoom = room;
            room.nums = 0;
        } else {
            deferred.reject();
            return deferred.promise;
        }

        if (ChannelFactory.isSocketSupport() === true) {
            chatSocket.send("/app/chat.go.to.dialog/{0}".format(currentRoom.roomId), {}, JSON.stringify({}));
            deferred.resolve();
            return deferred.promise;
        } else {
            return $http.post(serverPrefix + "/chat.go.to.dialog/{0}".format(currentRoom.roomId));
        }
    }
        var NEXT_MESSAGE_TIME_LIMIT_SECONDS = 10;
    function calcPositionUnshift(msg) {
        if (msg == null)
            return null;
        //     msg.message = msg.message.escapeHtml();//WRAP HTML CODE
        var summarised = false;
        oldMessage = msg;

        if (messages.length > 0) {
             var isActual = differenceInSecondsBetweenDates(new Date(msg.date),new Date(messages[0].date))<NEXT_MESSAGE_TIME_LIMIT_SECONDS;
            if ( messages[0].username == msg.username) {
                if (isActual && msg.attachedFiles.length == 0) {
                    summarised = true;
                    messages[0].message = msg.message + "\n\n" + messages[0].message;
                    //  $scope.messages[0].date = msg.date;
                }
                msg.position = messages[0].position;

            } else {
                msg.position = !messages[0].position;
            }
        } else {
            msg.position = false;
{'fraction_non_alphanumeric': 0.12950613704455397, 'fraction_numerical': 0.0031893302406494637, 'mean_word_length': 2.065165876777251, 'pattern_counts': {'":': 0, '<': 6, '<?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': '665125', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2885, 'n_words': 596}