{"size": 1636, "ext": "js", "max_stars_repo_path": "Undesirable-Communication/Undesirable-Communication/localScripts/angular/service/ChatService.js", "max_stars_repo_name": "undecidedapollo/Undesirable-Communication", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Undesirable-Communication/Undesirable-Communication/localScripts/angular/service/ChatService.js", "max_issues_repo_name": "undecidedapollo/Undesirable-Communication", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Undesirable-Communication/Undesirable-Communication/localScripts/angular/service/ChatService.js", "max_forks_repo_name": "undecidedapollo/Undesirable-Communication", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.72, "max_line_length": 114, "alphanum_fraction": 0.5721271394}
﻿(function () {
    var module = angular.module("UndesirableCommunication_Chat");
    module.factory("ChatService", ['$q', '$window', '$http', function ($q, $window, $http) {

        var currentUsername = null;
        var currentUserId = null;
        var currentConnection = null;

        var clearAllData = function () {
            currentUserId = null;
            currentConnection = null;
            currentUsername = null;
        };

        var registerUser = function (username) {
            return $http.post("api/Chat/Register", { Username: username });
        };

        var checkStatus = function (userId) {
            return $http.post("api/Chat/CheckStatus", { Id: userId });
        };

        var getMessages = function (chatId, userId) {
            return $http.get("api/Chat/GetRecentMessages?chatId=" + chatId + "&currentUserId=" + userId);
        };

        var sendMessage = function (chatId, userId, message) {
            return $http.post("api/Chat/SendMessage", { ChatId: chatId, CurrentUserId: userId, Content: message});
        };

        var ExitChat = function (chatId, userId) {
            return $http.post("api/Chat/ExitChat", { Id: chatId, CurrentUserId: userId });
        };



        return {
            currentUsername: currentUsername,
            currentUserId: currentUserId,
            currentConnection: currentConnection,
            registerUser: registerUser,
            checkStatus: checkStatus,
            getMessages: getMessages,
            sendMessage: sendMessage,
            ExitChat: ExitChat,
            clearAllData: clearAllData
        };

    }]);
}());