diff --git a/IMChatApp.v12.suo b/IMChatApp.v12.suo index f046cbb..151cacb 100644 Binary files a/IMChatApp.v12.suo and b/IMChatApp.v12.suo differ diff --git a/IMChatApp/App_Start/BundleConfig.cs b/IMChatApp/App_Start/BundleConfig.cs index 7b14045..2076617 100644 --- a/IMChatApp/App_Start/BundleConfig.cs +++ b/IMChatApp/App_Start/BundleConfig.cs @@ -10,6 +10,11 @@ public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js")); + + + + bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( + "~/Scripts/jquery.validate*")); // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( diff --git a/IMChatApp/App_Start/Startup.Auth.cs b/IMChatApp/App_Start/Startup.Auth.cs new file mode 100644 index 0000000..37b9d97 --- /dev/null +++ b/IMChatApp/App_Start/Startup.Auth.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNet.Identity; +using Microsoft.Owin; +using Microsoft.Owin.Security.Cookies; +using Owin; + +namespace IMChatApp +{ + public partial class Startup + { + // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 + public void ConfigureAuth(IAppBuilder app) + { + // Enable the application to use a cookie to store information for the signed in user + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, + LoginPath = new PathString("/Account/Login") + }); + // Use a cookie to temporarily store information about a user logging in with a third party login provider + app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); + + // Uncomment the following lines to enable logging in with third party login providers + //app.UseMicrosoftAccountAuthentication( + // clientId: "", + // clientSecret: ""); + + //app.UseTwitterAuthentication( + // consumerKey: "", + // consumerSecret: ""); + + //app.UseFacebookAuthentication( + // appId: "", + // appSecret: ""); + + //app.UseGoogleAuthentication(); + } + } +} \ No newline at end of file diff --git a/IMChatApp/ChatScripts/Controlers.js b/IMChatApp/ChatScripts/Controlers.js index 253eeeb..c554cb5 100644 --- a/IMChatApp/ChatScripts/Controlers.js +++ b/IMChatApp/ChatScripts/Controlers.js @@ -1,9 +1,10 @@ (function () { 'use strict' - app.controller("chatController", function ($scope, $rootScope, signalR,Flash) { + app.controller("chatController", function ($scope, $rootScope, signalR,Flash,$compile) { $scope.$parent.UserName = ""; $scope.rooms = [];// RoomFactory.Rooms; - $scope.$parent.UserName = $("h4#userNick").text();; // prompt("Enter unique name :"); + $scope.$parent.UserName = $("div#userId").text();; // prompt("Enter unique name :"); + signalR.startHub(); $scope.activeRoom = ''; $scope.chatHistory = []; @@ -32,6 +33,7 @@ // Flash.add('success', message, 'custom-class') signalR.Login($scope.$parent.UserName); + ///////////////// server @@ -42,34 +44,50 @@ $scope.ClosePrivateWindow = function () { $scope.ShowPrivateWindow = false; + $scope.UserInPrivateChat = null; + + // close_popup(); } - + // $("#PrivateChatArea").css("display", "block"); $scope.UserInPrivateChat = null; $scope.ShowPrivateWindow = false; $scope.PrivateMessages = []; $scope.currentprivatemessages = {}; $scope.pvtmessage = ''; - $scope.OpenPrivatewindow = function (index) { - + $scope.OpenPrivatewindow = function (index) { var user = $scope.users[index]; // var conId = '#' + user.ConnectionId; $scope.ShowPrivateWindow = true; $scope.UserInPrivateChat = user; - $scope.$apply(); + console.log("CID :" + $scope.UserInPrivateChat.Connectionid); + //$scope.$apply(); + $scope.$evalAsync(); // $scope.createPrivateChatWindow($scope.$parent.UserName, conId, user.name) } - $scope.SendPrivateMessage = function () - { - // debugger; - signalR.SendPrivateMessage($scope.UserInPrivateChat.ConnectionId, $scope.pvtmessage); - $scope.pvtmessage = ''; + $scope.SendPrivateMessage = function (id,name) + { + // if ($scope.UserLeft == false) { + var txt = $("#txt" + id) + if (txt.val().trim() != '') { + //$("#txt392331de-393d-427d-a631-3f52caf06dd1").val() + var txt = $("#txt" + id) + console.log(txt); + signalR.SendPrivateMessage(id, txt.val().trim(), name); + // $scope.pvtmessage = ''; + txt.val(''); + } + // } + //else { + // Flash.create('danger', 'User is offline'); + //} } $scope.OnlineUsers = []; signalR.GetOnlineUsers(function (onlineUsers) { $scope.OnlineUsers = $.parseJSON(onlineUsers); - console.log($scope.OnlineUsers); - $scope.$apply(); + //console.log($scope.OnlineUsers); + //$scope.$apply(); + $scope.$evalAsync(); }); $scope.ChangeStatus = function (status) { signalR.UpdateStatus(status); @@ -77,60 +95,92 @@ signalR.NewOnlineUser(function (user) { $scope.OnlineUsers.push(user); $scope.$apply(); - var message = ' !!' + user.name + ' in online'; - Flash.create('success', message, 'custom-class'); - }); + //var message = ' !!' + user.name + ' in online'; + //Flash.create('success', message, 'custom-class'); + }); + signalR.UpdateConnectionId(function (oid,nid) { + if ($scope.OnlineUsers[i].ConnectionId == oid) + $scope.OnlineUsers[i].ConnectionId = nid; + $scope.$evalAsync(); + }); signalR.NewOfflineUser(function (user) { $.each($scope.OnlineUsers, function (i) { - if ($scope.OnlineUsers[i].name === user.name && $scope.OnlineUsers[i].ConnectionId==user.ConnectionId) - { - $scope.OnlineUsers.splice(i, 1); - var message = ' !! ' + user.name + ' left the chat '; + if ($scope.OnlineUsers[i]!=undefined) + if ($scope.OnlineUsers[i].name === user.name && $scope.OnlineUsers[i].ConnectionId==user.ConnectionId) { + $scope.OnlineUsers.splice(i, 1); + var message = ' !! ' + user.name + ' left the chat '; + Flash.create('danger', message); + } + }); + if ($scope.UserInPrivateChat != undefined) + { debugger; - Flash.create('danger', message); + if ($scope.UserInPrivateChat.ConnectionId == user.ConnectionId) { + $scope.UserLeft = true; } - }); + else { + $scope.UserLeft = false; + } + } // $scope.OnlineUsers.push(user); $scope.$apply(); - }); - $scope.SkeyPress =function(e) { + }); + $scope.UserLeft = false; + $scope.SkeyPress = function (e, id) { + //debugger; if (e.which == 13) - { - $scope.SendPrivateMessage(); - $scope.usertyping = '' + { + $scope.SendPrivateMessage(id,name); + $scope.usertyping = '' } else if (e.which == 46 || e.which == 8) { - signalR.UserTyping($scope.UserInPrivateChat.ConnectionId, 'Deleting..'); + signalR.UserTyping(id, 'Deleting..'); window.setTimeout(function () { $scope.usertyping = ''; }, 500); } - else { - signalR.UserTyping($scope.UserInPrivateChat.ConnectionId, 'Typing..'); + else { + //$scope.UserInPrivateChat.ConnectionId + signalR.UserTyping(id, 'Typing..'); window.setTimeout(function () { $scope.usertyping = ''; }, 500); } } - // PrivateMessage($index) + // PrivateMessage($index) + $scope.openPvtChat = function (index) + { + console.log(index); + var user = $scope.OnlineUsers[index]; + $scope.register_popup(user.ConnectionId, user.name); + } + $scope.closePvtChat=function(id) + { + debugger; + close_popup(id); + } $scope.PrivateMessage = function (index) { debugger; var user = $scope.OnlineUsers[index]; - $scope.ShowPrivateWindow = true; + // $scope.ShowPrivateWindow = true; $scope.UserInPrivateChat = user; - console.log($scope.OnlineUsers); - $scope.$apply(); + // console.log($scope.OnlineUsers); + //$scope.$apply(); + $scope.$evalAsync(); }; $scope.usertyping = ''; - signalR.IsTyping(function (connectionid, msg) { + signalR.IsTyping(function (connectionid, msg) { + if($scope.UserInPrivateChat!=undefined) if ($scope.UserInPrivateChat.ConnectionId == connectionid) $scope.usertyping = msg; else $scope.usertyping = ''; - $scope.$apply(); + // $scope.$apply(); + $scope.$evalAsync(); window.setTimeout(function () { $scope.usertyping = ''; - $scope.$apply(); + // $scope.$apply(); + $scope.$evalAsync(); }, 500); }); signalR.StatusChanged(function (connectionId, status) @@ -141,41 +191,152 @@ } }); // $scope.OnlineUsers.push(user); - $scope.$apply(); + // $scope.$apply(); + $scope.$evalAsync(); }); - signalR.RecievingPrivateMessage(function (toname,fromname, msg) { - if ($scope.ShowPrivateWindow == false) { - $scope.ShowPrivateWindow = true; - } + //$rootScope.RootPrivateMessages = []; + signalR.RecievingPrivateMessage(function (toname, fromname, msg, connectionId) { + // if ($scope.ShowPrivateWindow == false) { + // $scope.ShowPrivateWindow = true; + //} + debugger; + $scope.openchats = []; // var msgBdy = { room: r, msgx: { message: msg.message, sender: msg.sender, css: msg.css } }; //$scope.chatHistory.push(msgBdy); - $scope.PrivateMessages.push({ to: toname, from: fromname, message: msg }); - + // var user = $scope.OnlineUsers[connectionId]; + // console.log(user); + $scope.PrivateMessages.push({ to: toname, from: fromname, message: msg, ConnectionId: connectionId }); + + if ($rootScope.RootPrivateMessages!=undefined) + $rootScope.RootPrivateMessages.push({ to: toname, from: fromname, message: msg, ConnectionId: connectionId }); if ($scope.$parent.UserName != fromname) // otheruser's pm { if ($scope.UserInPrivateChat == null) { - $scope.UserInPrivateChat = { name: fromname, ConnectionId: toname } + $scope.UserInPrivateChat = { name: fromname, ConnectionId: toname }; } } + console.log($scope.PrivateMessages); + //if (fromname!=$rootScope.) + $scope.register_popup(connectionId, fromname); + $scope.$evalAsync(); + // $scope.$evalAsync(); + $rootScope.$evalAsync(); + $rootScope.updateMessage(); //$evalAsync(); /// To Scroll the message window. if ($("#PrivateChatArea div.panel-body").length == 1) { var $container = $("#PrivateChatArea div.panel-body"); $container[0].scrollTop = $container[0].scrollHeight; $container.animate({ scrollTop: $container[0].scrollHeight }, "fast"); - } - $scope.$evalAsync(); + } // $scope.AddMessageToRoom(msgBdy); }); -}); + $("#PrivateChatArea").css("display", "block"); -////////////////////////////////////////////// - -function OpenPrivateChatWindow(chatHub, id, userName) { - var ctrId = 'private_' + id; - if ($('#' + ctrId).length > 0) return; - createPrivateChatWindow(chatHub, id, ctrId, userName); + /////////////////////////////New Code For Multiple Chat Windows//////////////////////// + // @$scope.popupsId=[]; + //$scope.$parent.UserName + $scope.register_popup = function(id, name) { + for (var iii = 0; iii < popups.length; iii++) { + //already registered. Bring it to front. + if (id == popups[iii]) { + Array.remove(popups, iii); + popups.unshift(id); + calculate_popups(); + return; + } + } -} + var chatBoxElemet = '
' + chatBoxElemet += '