Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
        public void SendMessage(MessageViewModel message)
        {
            var sender = AllConnectedParticipants.Find(x => x.Participant.Id == message.FromId);

            if (sender != null)
            {
                Clients.Client(message.ToId).SendAsync("messageReceived", sender.Participant, message);
            }
        }
Пример #4
0
    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);
        }
    }
Пример #5
0
        public async Task SendMessage(MessageViewModel message)
        {
            var sender = AllConnectedParticipants.Find(x => x.Participant.Id == message.FromId);

            if (sender != null)
            {
                var destinataryProfile = await _profileRepository.GetDestinataryProfileByAuth0Id(message.ToId);

                var currentUserProfileId = await _profileRepository.GetCurrentProfileIdByAuth0Id(Context.UserIdentifier);

                // If currentUser is on the destinataryProfile's ChatMemberslist AND is blocked then do not go any further.
                if (!destinataryProfile.ChatMemberslist.Any(m => m.ProfileId == currentUserProfileId && m.Blocked == true))
                {
                    var encryptedMessage = _cryptography.Encrypt(message.Message);
                    message.Message = encryptedMessage;

                    await _profileRepository.SaveMessage(message);

                    await _profileRepository.NotifyNewChatMember(Context.UserIdentifier, destinataryProfile.Auth0Id);

                    await Clients.Group(message.ToId).SendAsync("messageReceived", sender.Participant, message);
                }
            }
        }