public static void AddInvitation(this List <ChatHubInvitation> invitations, ChatHubInvitation invitation) { if (!invitations.Any(x => x.Guid == invitation.Guid)) { invitations.Add(invitation); } }
public void AddInvitation(ChatHubInvitation invitation) { if (!this.Invitations.Any(x => x.Guid == invitation.Guid)) { this.Invitations.Add(invitation); } }
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); } } }
private void OnRemoveChatHubInvitationExecute(object sender, ChatHubInvitation item) { this.Invitations.RemoveInvitation(item.Guid); }
private void OnAddChatHubInvitationExecute(object sender, ChatHubInvitation item) { this.Invitations.AddInvitation(item); }