Esempio n. 1
0
        public void ReadMessages(int dialogId)
        {
            UserDTO          owner;
            UserDTO          reader = Helper.GetUser(Context.User.Identity.Name);
            DialogDTO        dDTO   = messService.GetDialog(dialogId, reader.Id).Data;
            DialogMessageDTO lastM;

            if (dDTO.LastMessInDialog != null)
            {
                lastM = dDTO.LastMessInDialog;
                owner = lastM.FromUser;

                ConnectedUser cuR = users.FirstOrDefault(us => us.userId == reader.Id);
                ConnectedUser cuO = users.FirstOrDefault(us => us.userId == owner.Id);
                if (cuR != null && cuO != null)
                {
                    if (messService.DialogNewMessCount(dialogId, reader.Id).Data != 0)
                    {
                        messService.ReadMessages(dialogId, reader.Id);
                        Clients.Client(cuR.ConnectionId).showReadMessages(cuR.ConnectionId, cuO.ConnectionId);
                        Clients.Client(cuO.ConnectionId).showReadMessages(cuR.ConnectionId, cuO.ConnectionId);
                    }
                }
            }


            //foreach (UserDTO uDTO in messService.GetUsersInDialog(dDTO.Id).Data.Where(u => u.Id == reader.Id || u.Id == owner.Id))
            //{
            //    ConnectedUser cu = users.FirstOrDefault(us => us.userId == uDTO.Id);
            //    if (cu != null)
            //    {
            //        if(messService.DialogNewMessCount(dialogId,reader.Id).Data != 0)
            //        {
            //            messService.ReadMessages(dialogId, uDTO.Id);
            //            Clients.Client(cu.ConnectionId).showReadMessages();
            //        }
            //    }
            //}



            //int id = Helper.GetUser(Context.User.Identity.Name).Data.Id;
            //if (messService.DialogNewMessCount(dialogId, id).Data!=0)
            //{
            //    messService.ReadMessages(dialogId, id);
            //    Clients.All.showReadMessages();
            //}
        }
Esempio n. 2
0
        //===================Messages===================//
        public void SendMessage(int dialogId, string Text)
        {
            bool                  isToday  = true;
            UserDTO               fromUser = Helper.GetUser(Context.User.Identity.Name);
            DialogDTO             dDTO     = messService.GetDialog(dialogId, fromUser.Id).Data;
            DialogMessageDTO      prevdm   = dDTO.LastMessInDialog;
            IEnumerable <UserDTO> uid      = messService.GetUsersInDialog(dDTO.Id).Data;
            DialogMessageDTO      dm       = messService.SendMessage(new DialogMessageDTO()
            {
                DialogId = dialogId, FromUserId = fromUser.Id, Text = Text, Date = DateTime.Now, Status = false
            }).Data;

            if (prevdm != null)
            {
                if (prevdm.Date.Year == DateTime.Now.Year && prevdm.Date.Month == DateTime.Now.Month && prevdm.Date.Day == prevdm.Date.Day)
                {
                    isToday = false;
                }
            }
            foreach (UserDTO uDTO in uid)
            {
                ConnectedUser cu = users.FirstOrDefault(us => us.userId == uDTO.Id);
                if (cu != null)
                {
                    if (uDTO.Id == fromUser.Id)
                    {
                        if (uid.Count() == 2)
                        {
                            Clients.Client(cu.ConnectionId).showMessageForCaller(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = fromUser.FirstName + " " + fromUser.LastName,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                        else
                        {
                            Clients.Client(cu.ConnectionId).showMessageForCaller(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = dDTO.Name,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                    }
                    else
                    {
                        if (uid.Count() == 2)
                        {
                            Clients.Client(cu.ConnectionId).showMessage(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = fromUser.FirstName + " " + fromUser.LastName,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                        else
                        {
                            Clients.Client(cu.ConnectionId).showMessage(
                                new
                            {
                                messId        = dm.Id,
                                userId        = fromUser.Id,
                                UserProfImage = fromUser.ProfileImage.FilePath,
                                FromUserName  = fromUser.FirstName + " " + fromUser.LastName,
                                dialogId      = dDTO.Id,
                                DialProfImage = dDTO.ProfileImage.FilePath,
                                DialogName    = dDTO.Name,
                                Date          = dm.Date.ToString("HH:mm"),
                                DateSec       = TimeSpan.FromTicks(dm.Date.Ticks).TotalSeconds,
                                Text          = Text,
                                isToday       = isToday
                            });
                        }
                    }
                }
            }
        }