public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string targetUserName = args[0]; ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName); targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser; if (targetUser == null) { await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (!targetUser.Online()) { await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (caller.UserId == targetUser.UserId) { await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string msg = null; if (args.Length > 1) { msg = String.Join(" ", args.Skip(1)).Trim(); } var callerRoom = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId); ChatHubMessage chatHubMessage = new ChatHubMessage() { ChatHubRoomId = callerContext.RoomId, ChatHubUserId = caller.UserId, User = caller, Content = msg ?? string.Empty, Type = Enum.GetName(typeof(ChatHubMessageType), ChatHubMessageType.Whisper) }; context.ChatHubRepository.AddChatHubMessage(chatHubMessage); var chatHubMessageClientModel = context.ChatHubService.CreateChatHubMessageClientModel(chatHubMessage); var users = new List <ChatHubUser>(); users.Add(caller); users.Add(targetUser); foreach (var item in users) { var rooms = context.ChatHubRepository.GetChatHubRoomsByUser(item).Public().Active().ToList(); var connections = item.Connections.Active(); foreach (var room in rooms) { foreach (var connection in connections) { await context.ChatHub.Clients.Client(connection.ConnectionId).SendAsync("AddMessage", chatHubMessageClientModel); } } } }
public async Task SendGroupNotification(string message, int roomId, string connectionId, ChatHubUser contextUser, ChatHubMessageType chatHubMessageType) { ChatHubMessage chatHubMessage = new ChatHubMessage() { ChatHubRoomId = roomId, ChatHubUserId = contextUser.UserId, User = contextUser, Content = message ?? string.Empty, Type = Enum.GetName(typeof(ChatHubMessageType), chatHubMessageType) }; this.chatHubRepository.AddChatHubMessage(chatHubMessage); ChatHubMessage chatHubMessageClientModel = this.chatHubService.CreateChatHubMessageClientModel(chatHubMessage); var connectionsIds = this.chatHubService.GetAllExceptConnectionIds(contextUser); await Clients.GroupExcept(roomId.ToString(), connectionsIds).SendAsync("AddMessage", chatHubMessageClientModel); }
public IQueryable <ChatHubIgnore> GetIgnoredUsers(ChatHubUser user) { return(db.Entry(user) .Collection(u => u.Ignores) .Query().Select(i => i)); }
public async Task EnterChatRoom(int roomId) { ChatHubUser user = await this.GetChatHubUserAsync(); ChatHubRoom room = chatHubRepository.GetChatHubRoom(roomId); if (room.Status == ChatHubRoomStatus.Archived.ToString()) { if (!Context.User.HasClaim(ClaimTypes.Role, RoleNames.Admin) && !Context.User.HasClaim(ClaimTypes.Role, RoleNames.Host)) { throw new HubException("You cannot enter an archived room."); } } if (room.Public() || room.Protected()) { if (this.chatHubService.IsBlacklisted(room, user)) { throw new HubException("You have been added to blacklist for this room."); } } if (room.Protected()) { if (!Context.User.Identity.IsAuthenticated) { throw new HubException("This room is for authenticated user only."); } } if (room.Private()) { if (!this.chatHubService.IsWhitelisted(room, user)) { if (room.CreatorId != user.UserId) { await this.AddWaitingRoomItem(user, room); throw new HubException("No valid private room connection. You have been added to waiting list."); } } } if (room.OneVsOne()) { if (!this.chatHubService.IsValidOneVsOneConnection(room, user)) { throw new HubException("No valid one vs one room id."); } } if (room.Public() || room.Protected() || room.Private() || room.OneVsOne()) { ChatHubRoomChatHubUser room_user = new ChatHubRoomChatHubUser() { ChatHubRoomId = room.Id, ChatHubUserId = user.UserId }; chatHubRepository.AddChatHubRoomChatHubUser(room_user); ChatHubRoom chatHubRoomClientModel = await this.chatHubService.CreateChatHubRoomClientModelAsync(room); foreach (var connection in user.Connections.Active()) { await Groups.AddToGroupAsync(connection.ConnectionId, room.Id.ToString()); await Clients.Client(connection.ConnectionId).SendAsync("AddRoom", chatHubRoomClientModel); } ChatHubUser chatHubUserClientModel = this.chatHubService.CreateChatHubUserClientModel(user); await Clients.Group(room.Id.ToString()).SendAsync("AddUser", chatHubUserClientModel, room.Id.ToString()); await this.SendGroupNotification(string.Format("{0} entered chat room with client device {1}.", user.DisplayName, this.chatHubService.MakeStringAnonymous(Context.ConnectionId, 7, '*')), room.Id, Context.ConnectionId, user, ChatHubMessageType.Enter_Leave); } }
private async Task <bool> ExecuteCommandManager(ChatHubUser chatHubUser, string message, int roomId) { var commandManager = new CommandManager(Context.ConnectionId, roomId, chatHubUser, this, chatHubService, chatHubRepository, userManager); return(await commandManager.TryHandleCommand(message)); }
public IQueryable <ChatHubRoom> GetChatHubRoomsByUser(ChatHubUser user) { return(db.Entry(user) .Collection(u => u.UserRooms) .Query().Select(u => u.Room)); }
public bool IsValidOneVsOneConnection(ChatHubRoom room, ChatHubUser caller) { return(room.OneVsOneId.Split('|').OrderBy(item => item).Any(item => item == caller.UserId.ToString())); }
public override async Task Execute(CommandServicesContext commandServicesContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser caller) { IdentityUser identityUser = await commandServicesContext.UserManager.FindByNameAsync(caller.Username); if (!commandServicesContext.UserManager.IsInRoleAsync(identityUser, Oqtane.Shared.Constants.AdminRole).Result) { return; } await ExecuteAdminOperation(commandServicesContext, commandCallerContext, args, caller); }
private void OnAddIngoredUserExexute(object sender, ChatHubUser user) { this.IgnoredUsers.AddIgnoredUser(user); this.RunUpdateUI(); }
public static void RemoveIgnoredByUser(this List <ChatHubUser> ignoredByUsers, ChatHubUser user) { var item = ignoredByUsers.FirstOrDefault(x => x.UserId == user.UserId); if (item != null) { ignoredByUsers.Remove(item); } }
public abstract Task ExecuteAdminOperation(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller);
public static bool Online(this ChatHubUser user) { return(user.Connections.Where(c => c.Status == Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Active)).Any()); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { await context.ChatHub.Clients.Client(callerContext.ConnectionId).SendAsync("ClearHistory", callerContext.RoomId); }
async Task ICommand.Execute(CommandServicesContext commandServiceContext, CommandCallerContext commandCallerContext, string[] args, ChatHubUser user) { await Execute(commandServiceContext, commandCallerContext, args, user); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string targetUserName = args[0]; ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName); targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser; if (targetUser == null) { await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } await context.ChatHub.UnignoreUser(targetUser.Username); }
private void OnRemoveIgnoredByUserExecute(object sender, ChatHubUser user) { this.IgnoredByUsers.RemoveIgnoredByUser(user); this.RunUpdateUI(); }
public async Task <ChatHubUser> GetUserByDisplayName(string displayName) { ChatHubUser user = await db.ChatHubUser.Include(u => u.Connections).Where(u => u.DisplayName == displayName).Where(u => u.Connections.Any(c => c.Status == Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Active))).FirstOrDefaultAsync(); return(user); }
public void OnUpdateConnectedUserExecute(object sender, ChatHubUser user) { this.ConnectedUser = user; this.RunUpdateUI(); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } args.Reverse(); for (int i = 0; i < args.Length; i++) { args[i] = args[i].Reverse(); } string msg = String.Join(" ", args).Trim(); ChatHubMessage chatHubMessage = new ChatHubMessage() { ChatHubRoomId = callerContext.RoomId, ChatHubUserId = caller.UserId, User = caller, Content = msg, Type = ChatHubMessageType.Guest.ToString() }; context.ChatHubRepository.AddChatHubMessage(chatHubMessage); ChatHubMessage chatHubMessageClientModel = context.ChatHubService.CreateChatHubMessageClientModel(chatHubMessage); var connectionsIds = context.ChatHubService.GetAllExceptConnectionIds(caller); await context.ChatHub.Clients.GroupExcept(callerContext.RoomId.ToString(), connectionsIds).SendAsync("AddMessage", chatHubMessageClientModel); }
private async void OnDisconnectExecute(object sender, ChatHubUser user) { await this.DisconnectAsync(); }
private async Task <ChatHubUser> OnConnectedGuest() { string guestname = null; guestname = Context.GetHttpContext().Request.Query["guestname"]; guestname = guestname.Trim(); if (string.IsNullOrEmpty(guestname) || !this.IsValidGuestUsername(guestname)) { throw new HubException("No valid username."); } string username = this.CreateUsername(guestname); string displayname = this.CreateDisplaynameFromUsername(username); if (await this.chatHubRepository.GetUserByDisplayName(displayname) != null) { throw new HubException("Displayname already in use. Goodbye."); } string email = "*****@*****.**"; string password = "******"; ChatHubUser chatHubUser = new ChatHubUser() { SiteId = 1, Username = username, DisplayName = displayname, Email = email, LastIPAddress = Context.GetHttpContext().Connection.RemoteIpAddress.ToString(), }; chatHubUser = this.chatHubRepository.AddChatHubUser(chatHubUser); if (chatHubUser != null && chatHubUser.Username != RoleNames.Host) { List <Role> roles = this.roles.GetRoles(chatHubUser.SiteId).Where(item => item.IsAutoAssigned).ToList(); foreach (Role role in roles) { UserRole userrole = new UserRole(); userrole.UserId = chatHubUser.UserId; userrole.RoleId = role.RoleId; userrole.EffectiveDate = null; userrole.ExpiryDate = null; userRoles.AddUserRole(userrole); } } ChatHubConnection ChatHubConnection = new ChatHubConnection() { ChatHubUserId = chatHubUser.UserId, ConnectionId = Context.ConnectionId, IpAddress = Context.GetHttpContext().Connection.RemoteIpAddress.ToString(), UserAgent = Context.GetHttpContext().Request.Headers["User-Agent"].ToString(), Status = Enum.GetName(typeof(ChatHubConnectionStatus), ChatHubConnectionStatus.Active) }; ChatHubConnection = this.chatHubRepository.AddChatHubConnection(ChatHubConnection); ChatHubSettings ChatHubSetting = new ChatHubSettings() { UsernameColor = "#7744aa", MessageColor = "#44aa77", ChatHubUserId = chatHubUser.UserId }; ChatHubSetting = this.chatHubRepository.AddChatHubSetting(ChatHubSetting); return(chatHubUser); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string usernameColor = args[0]; if(!string.IsNullOrEmpty(usernameColor)) { var settings = caller.Settings; settings.UsernameColor = usernameColor; context.ChatHubRepository.UpdateChatHubSetting(settings); await context.ChatHub.SendClientNotification("Username Color Updated.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); } }
public async Task LeaveChatRoom(int roomId) { ChatHubUser user = await this.GetChatHubUserAsync(); ChatHubRoom room = chatHubRepository.GetChatHubRoom(roomId); if (!this.chatHubRepository.GetChatHubUsersByRoom(room).Any(item => item.UserId == user.UserId)) { throw new HubException("User already left room."); } if (room.Public() || room.Protected()) { if (this.chatHubService.IsBlacklisted(room, user)) { throw new HubException("You have been added to blacklist for this room."); } } if (room.Protected()) { if (!Context.User.Identity.IsAuthenticated) { throw new HubException("This room is for authenticated user only."); } } if (room.Private()) { if (!this.chatHubService.IsWhitelisted(room, user)) { throw new HubException("No valid private room connection."); } } if (room.OneVsOne()) { if (!this.chatHubService.IsValidOneVsOneConnection(room, user)) { throw new HubException("No valid one vs one room id."); } } if (room.Public() || room.Protected() || room.Private() || room.OneVsOne()) { this.chatHubRepository.DeleteChatHubRoomChatHubUser(roomId, user.UserId); ChatHubRoom chatHubRoomClientModel = await this.chatHubService.CreateChatHubRoomClientModelAsync(room); foreach (var connection in user.Connections.Active()) { await Groups.RemoveFromGroupAsync(connection.ConnectionId, room.Id.ToString()); await Clients.Client(connection.ConnectionId).SendAsync("RemoveRoom", chatHubRoomClientModel); } ChatHubUser chatHubUserClientModel = this.chatHubService.CreateChatHubUserClientModel(user); await Clients.Group(room.Id.ToString()).SendAsync("RemoveUser", chatHubUserClientModel, room.Id.ToString()); await this.SendGroupNotification(string.Format("{0} left chat room with client device {1}.", user.DisplayName, this.chatHubService.MakeStringAnonymous(Context.ConnectionId, 7, '*')), room.Id, Context.ConnectionId, user, ChatHubMessageType.Enter_Leave); } }
public async Task <IActionResult> PostImageUpload() { string connectionId = null; if (Request.Headers.ContainsKey("connectionId")) { connectionId = Request.Headers["connectionId"]; if (string.IsNullOrEmpty(connectionId)) { return(new BadRequestObjectResult(new { Message = "No connection id." })); } } ChatHubUser user = await this.chatHubService.IdentifyGuest(connectionId); if (user == null) { return(new BadRequestObjectResult(new { Message = "No user found." })); } string displayName = string.Empty; if (Request.Headers.ContainsKey("displayName")) { displayName = Request.Headers["displayName"]; if (string.IsNullOrEmpty(displayName)) { return(new BadRequestObjectResult(new { Message = "No display name." })); } } string roomId = string.Empty; if (Request.Headers.ContainsKey("roomId")) { roomId = Request.Headers["roomId"]; if (string.IsNullOrEmpty(roomId)) { return(new BadRequestObjectResult(new { Message = "No room id." })); } } string moduleId = string.Empty; if (Request.Headers.ContainsKey("moduleId")) { moduleId = Request.Headers["moduleId"]; if (string.IsNullOrEmpty(moduleId)) { return(new BadRequestObjectResult(new { Message = "No module id." })); } } IFormFileCollection files = Request.Form.Files; if (files == null || files.Count <= 0) { return(new BadRequestObjectResult(new { Message = "No files." })); } string content = string.Concat(files.Count, " ", "Photo(s)"); ChatHubRoom chatHubRoom = this.chatHubRepository.GetChatHubRoom(Int32.Parse(roomId)); if (chatHubRoom == null) { return(new BadRequestObjectResult(new { Message = "No room found." })); } ChatHubMessage chatHubMessage = new ChatHubMessage() { ChatHubRoomId = chatHubRoom.Id, ChatHubUserId = user.UserId, Type = Enum.GetName(typeof(ChatHubMessageType), ChatHubMessageType.Image), Content = content, User = user }; chatHubMessage = this.chatHubRepository.AddChatHubMessage(chatHubMessage); try { var maxFileSize = 10; var maxFileCount = 3; string folderName = "modules/oqtane.chathubs/images/selfies"; string webRootPath = string.Concat(this.webHostEnvironment.ContentRootPath, "\\wwwroot"); string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (files.Count > maxFileCount) { return(new BadRequestObjectResult(new { Message = "Maximum number of files exceeded." })); } foreach (IFormFile file in files) { if (file.Length > (maxFileSize * 1024 * 1024)) { return(new BadRequestObjectResult(new { Message = "File size Should Be UpTo " + maxFileSize + "MB" })); } var supportedFileExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif" }; string fileExtension = Path.GetExtension(file.FileName); if (!supportedFileExtensions.Contains(fileExtension)) { return(new BadRequestObjectResult(new { Message = "Unknown file type(s)." })); } /* * ObjectResult result = await this.PostAsync(file); * dynamic obj = result.Value; * string imageClassification = string.Empty; * if (result.StatusCode.Value == 200) * { * if (obj.predictedLabel == "dickpic") * { * var percent = string.Format("{0:P2}", Math.Round((float)obj.probability, 3)); * if ((float)obj.probability >= 0.99) * { * imageClassification = string.Concat(" | ", "(", "most likely identified as ", obj.predictedLabel, ": ", percent, ")"); * } * } * } */ int imageWidth, imageHeight; string fileName = string.Concat(Guid.NewGuid().ToString(), fileExtension); string fullPath = Path.Combine(newPath, fileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); FileInfo fileInfo = new FileInfo(file.FileName); var sizeInBytes = file.Length; Bitmap img = new Bitmap(stream); imageWidth = img.Width; imageHeight = img.Height; } ChatHubPhoto chatHubPhoto = new ChatHubPhoto() { ChatHubMessageId = chatHubMessage.Id, Source = fileName, Size = file.Length, Thumb = fileName, Caption = string.Concat(user.DisplayName, " | ", Math.Round(Convert.ToDecimal(file.Length / (1024.0m * 1024.0m)), 2), "MB" /*, imageClassification*/), Message = chatHubMessage, Width = imageWidth, Height = imageHeight }; chatHubPhoto = this.chatHubRepository.AddChatHubPhoto(chatHubPhoto); } chatHubMessage = this.chatHubService.CreateChatHubMessageClientModel(chatHubMessage); await this.chatHub.Clients.Group(chatHubMessage.ChatHubRoomId.ToString()).SendAsync("AddMessage", chatHubMessage); return(new OkObjectResult(new { Message = "Successfully Uploaded Files." })); } catch (Exception ex) { return(new BadRequestObjectResult(new { Message = "Error Uploading Files." })); } }
public async Task SendClientNotification(string message, int roomId, string connectionId, ChatHubUser targetUser, ChatHubMessageType chatHubMessageType) { ChatHubMessage chatHubMessage = new ChatHubMessage() { ChatHubRoomId = roomId, ChatHubUserId = targetUser.UserId, User = targetUser, Content = message ?? string.Empty, Type = Enum.GetName(typeof(ChatHubMessageType), chatHubMessageType) }; this.chatHubRepository.AddChatHubMessage(chatHubMessage); ChatHubMessage chatHubMessageClientModel = this.chatHubService.CreateChatHubMessageClientModel(chatHubMessage); await Clients.Client(connectionId).SendAsync("AddMessage", chatHubMessageClientModel); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string targetUserName = args[0]; ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName); targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser; if (targetUser == null) { await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (caller.UserId == targetUser.UserId) { // TODO: Delete the rest of the user data context.ChatHubRepository.DeleteChatHubMessages(caller.UserId); context.ChatHubRepository.DeleteChatHubConnections(caller.UserId); context.ChatHubRepository.DeleteChatHubRooms(caller.UserId, context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId).ModuleId); context.ChatHubRepository.DeleteChatHubUser(caller.UserId); throw new HubException(string.Format("Successfully deleted all database entries. System do not know an user named {0} anymore.", caller.DisplayName)); } }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string targetUserName = args[0]; ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName); targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser; if (targetUser == null) { await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (!targetUser.Online()) { await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (caller.UserId == targetUser.UserId) { await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string msg = null; if (args.Length > 1) { msg = String.Join(" ", args.Skip(1)).Trim(); } var callerRoom = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId); var oneVsOneRoom = context.ChatHubService.GetOneVsOneRoom(caller, targetUser, callerRoom.ModuleId); if (oneVsOneRoom != null) { await context.ChatHub.EnterChatRoom(oneVsOneRoom.Id); ChatHubInvitation chatHubInvitation = new ChatHubInvitation() { Guid = Guid.NewGuid(), RoomId = oneVsOneRoom.Id, Hostname = caller.DisplayName }; foreach (var connection in targetUser.Connections.Active()) { await context.ChatHub.Clients.Client(connection.ConnectionId).SendAsync("AddInvitation", chatHubInvitation); } } }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { await context.ChatHub.SendCommandMetaDatas(callerContext.RoomId); }
public IQueryable <ChatHubIgnore> GetIgnoredByUsers(ChatHubUser user) { return(db.ChatHubIgnore.Include(i => i.User).Select(i => i).Where(i => i.Id == user.UserId && (i.ModifiedOn.AddDays(7)) >= DateTime.Now)); }
public override async Task Execute(CommandServicesContext context, CommandCallerContext callerContext, string[] args, ChatHubUser caller) { if (args.Length == 0) { await context.ChatHub.SendClientNotification("No arguments found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string targetUserName = args[0]; ChatHubUser targetUser = await context.ChatHubRepository.GetUserByDisplayName(targetUserName); targetUser = targetUser == null ? await context.ChatHubRepository.GetUserByUserNameAsync(targetUserName) : targetUser; if (targetUser == null) { await context.ChatHub.SendClientNotification("No user found.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (!targetUser.Online()) { await context.ChatHub.SendClientNotification("User not online.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (caller.UserId == targetUser.UserId) { await context.ChatHub.SendClientNotification("Calling user can not be target user.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } string msg = null; if (args.Length > 1) { msg = String.Join(" ", args.Skip(1)).Trim(); } var callerRoom = context.ChatHubRepository.GetChatHubRoom(callerContext.RoomId); if (caller.UserId != callerRoom.CreatorId) { await context.ChatHub.SendClientNotification("Whitelist user command can be executed from room creator only.", callerContext.RoomId, callerContext.ConnectionId, caller, ChatHubMessageType.System); return; } if (callerRoom.Public() || callerRoom.Protected() || callerRoom.Private()) { ChatHubWhitelistUser chatHubWhitelistUser = context.ChatHubRepository.AddChatHubWhitelistUser(targetUser); ChatHubRoomChatHubWhitelistUser room_whitelistuser = new ChatHubRoomChatHubWhitelistUser() { ChatHubRoomId = callerRoom.Id, ChatHubWhitelistUserId = chatHubWhitelistUser.Id, }; context.ChatHubRepository.AddChatHubRoomChatHubWhitelistUser(room_whitelistuser); foreach (var connection in caller.Connections.Active()) { await context.ChatHub.SendClientNotification("Command whitelist user succeeded.", callerContext.RoomId, connection.ConnectionId, caller, ChatHubMessageType.System); } } }