public void NewMsg(MessageViewModel message) { var sender = AllConnectedParticipants.Find(x => x.Participant.Id == message.FromId); if (sender != null) { var groupDestinatary = AllGroupParticipants.Where(x => x.Id == message.ToId).FirstOrDefault(); if (groupDestinatary != null) { // Notify all users in the group except the sender var usersInGroupToNotify = AllConnectedParticipants .Where(p => p.Participant.Id != sender.Participant.Id && groupDestinatary.ChattingTo.Any(g => g.Id == p.Participant.Id) ) .Select(g => g.Participant.Id); Clients.Clients(usersInGroupToNotify.ToList()).SendAsync("messageReceived", groupDestinatary, message); } else { Clients.Client(message.ToId).SendAsync("messageReceived", sender.Participant, message); } } }
public void SendMsg(string msg) { //{"type":1,"fromId":123,"toId":"8ss_ttkQHMql3M-SFviTFQ","message":"123","dateSent":"2020-05-03T14:22:47.965Z"} var message = JsonConvert.DeserializeObject <MessageViewModel>(msg); var sender = AllConnectedParticipants.Find(x => x.Participant.Id == message.FromId); if (sender != null) { var groupDestinatary = AllGroupParticipants.Where(x => x.Id == message.ToId).FirstOrDefault(); if (groupDestinatary != null) { // Notify all users in the group except the sender var usersInGroupToNotify = AllConnectedParticipants .Where(p => p.Participant.Id != sender.Participant.Id && groupDestinatary.ChattingTo.Any(g => g.Id == p.Participant.Id) ) .Select(g => g.Participant.Id); Clients.Clients(usersInGroupToNotify.ToList()).SendAsync("messageReceived", groupDestinatary, message); } else { Clients.Client(message.ToId).SendAsync("messageReceived", sender.Participant, message); } } }
public void Join(string userName) { lock (ParticipantsConnectionLock) { var oldConnectedParticipants = AllConnectedParticipants.Where(x => x.Participant.Id == Context.UserIdentifier); if (oldConnectedParticipants.Count() == 0) { AllConnectedParticipants.Add(new ParticipantResponseViewModel() { Metadata = new ParticipantMetadataViewModel() { TotalUnreadMessages = 0 }, Participant = new ChatParticipantViewModel() { DisplayName = userName, Id = Context.UserIdentifier } }); } // This will be used as the user's unique ID to be used on ng-chat as the connected user. // You should most likely use another ID on your application Clients.Caller.SendAsync("generatedUserId", Context.UserIdentifier); Clients.All.SendAsync("friendsListChanged", AllConnectedParticipants); } }
private static IEnumerable <ParticipantResponseViewModel> FilteredGroupParticipants(string currentUserId) { return(AllConnectedParticipants .Where(p => p.Participant.ParticipantType == ChatParticipantTypeEnum.User || AllGroupParticipants.Any(g => g.Id == p.Participant.Id && g.ChattingTo.Any(u => u.Id == currentUserId)) )); }
public async Task SendMessage(MessageViewModel message) { var sender = AllConnectedParticipants.Find(x => x.HubContextId == message.FromUser.HubContextId && x.UserId == Context.User.GetClaim(OpenIdConnectConstants.Claims.Subject)); if (sender != null) { var userList = await(from p in this._ctx.Participants where p.Group.Id.ToString() == message.GroupId select p.User.Id).ToArrayAsync(); // Notify all users in the group except the sender var usersInGroupToNotify = AllConnectedParticipants .Where(p => p.HubContextId != sender.HubContextId && userList.Contains(p.UserId)); this.insertMessage(usersInGroupToNotify, message, sender); Clients.Clients(usersInGroupToNotify.Select(d => d.HubContextId).ToList()).SendAsync("messageReceived", message); } }
public static IEnumerable <ChatParticipantViewModel> getConnectedParticpant(string UserId) { return(AllConnectedParticipants.Where(d => d.UserId == UserId)); }
public static IEnumerable <ParticipantResponseViewModel> ConnectedParticipants(string currentUserId) { return(AllConnectedParticipants .Where(x => x.Participant.Id != currentUserId)); }