public void JoinChat(string chatRoomName, string UserName) { if (!String.IsNullOrEmpty(UserName) && LoginUsers.Any(x => x.DisplayUserName == UserName)) { if (!ChatingUsers.Any(x => x.DisplayUserName == UserName && x.ChatRoomName == chatRoomName)) { ChatUser currentUser = new ChatUser { ChatUserName = Context.User.Identity.Name, ChatRoomName = chatRoomName, DisplayUserName = UserName }; ChatUser reciver = ChatingUsers.Find(x => x.ChatUserName != Context.User.Identity.Name && x.ChatRoomName == chatRoomName); if (reciver != null) { // Ako postoji sugovornik u grupi uzmi javni ključ i napravi novi dervirani ključ currentUser.SetDeriveKey(reciver.PublicKey); // Ako sugovornik ima već ključ za potpisivanje uzmi i stavi za ključ za potpisivanje trenutnog korisnika // Ako nema napravi novi ključ i postavi ga if (reciver.KeyForSigning != null) { currentUser.KeyForSigning = reciver.KeyForSigning; } else { currentUser.SetKeyForSigning(Guid.NewGuid().ToString()); reciver.KeyForSigning = currentUser.KeyForSigning; } // Ako sugovornik nema dervirani ključ postavi ga koristeči javni ključ trenutnog korisnika if (reciver.CurrentDeriveKey == null) { reciver.SetDeriveKey(currentUser.PublicKey); ChatingUsers[ChatingUsers.IndexOf(reciver)] = reciver; } } else { // Ako sugovornik još nema napravi novi ključ za potpisivanje currentUser.SetKeyForSigning(Guid.NewGuid().ToString()); } ChatingUsers.Add(currentUser); Groups.Add(Context.ConnectionId, chatRoomName); } else { ChatUser currentUser = ChatingUsers.Find(x => x.DisplayUserName == UserName && x.ChatRoomName == chatRoomName); ChatingUsers.Find(x => x.DisplayUserName == UserName && x.ChatRoomName == chatRoomName).ChatUserName = Context.User.Identity.Name; if (currentUser.CurrentDeriveKey == null) { ChatUser reciver = ChatingUsers.Find(x => x.ChatUserName != Context.User.Identity.Name && x.ChatRoomName == chatRoomName); if (reciver != null) { ChatingUsers.Find(x => x.DisplayUserName == UserName && x.ChatRoomName == chatRoomName).SetDeriveKey(reciver.PublicKey); } } } } GetListOfUsersInRoom(chatRoomName); }