Ejemplo n.º 1
0
        public async Task <ViewResult> Unread()
        {
            int currentUserId = User.Identity.GetUserId <int>();
            var dialogs       = await dialogService.GetUserDialogsAsync(currentUserId, d => d.Messages.Any(m => !m.ToViewed));

            var modelDialogs = Mapper.Map <IEnumerable <Dialog>, IEnumerable <DialogViewModel> >(dialogs);
            var model        = new DialogListViewModel()
            {
                Dialogs = modelDialogs
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        private void OpenDialogs()
        {
            if (_dialogList == null)
            {
                _eventService = new EventsService(_vkApi);
                _eventService.LongPool();
                _dialogRepository = new DialogRepository(_vkApi, _eventService);

                _dialogList = new DialogListViewModel(_vkApi, _dialogRepository);
            }
            if (_viewModels.Contains(_dialogList))
            {
                ActiveViewModel = _dialogList;
            }
            else
            {
                _viewModels.Add(_dialogList);
                ActiveViewModel = _viewModels.Last();
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Inbox()
        {
            int currentUserId = User.Identity.GetUserId <int>();
            var dialogs       = await dialogService.GetUserDialogsAsync(currentUserId, i => i.Companion, i => i.Creator, i => i.Messages);

            var modelDialogs = new List <DialogViewModel>(); Mapper.Map <IEnumerable <Dialog>, IEnumerable <DialogViewModel> >(dialogs);

            foreach (var dialog in dialogs)
            {
                var dialogModel = Mapper.Map <Dialog, DialogViewModel>(dialog);
                dialogModel.CountOfNewMessages = dialog.Messages.Count(d => d.SenderId != currentUserId && !d.ToViewed);
                modelDialogs.Add(dialogModel);
            }
            var model = new DialogListViewModel()
            {
                Dialogs = modelDialogs
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Unread(string sortOrder, string currentFilter, string searchString, string senderName, int?page)
        {
            ViewData["CurrentSort"]  = sortOrder;
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
            //ViewBag.FilterParam = String.IsNullOrEmpty(filter) ? "all" : "";
            ViewData["SenderName"]    = senderName;
            ViewData["SearchString"]  = searchString;
            ViewData["CurrentFilter"] = currentFilter;
            var currentUser      = _userProfileService.GetUserProfileById(User.Identity.GetUserId());
            var dialogs          = _dialogService.GetUserDialogs(currentUser.Id, i => i.Messages).ToList();
            var modelListDialogs = new List <DialogViewModel>();

            DialogListViewModel model = new DialogListViewModel()
            {
                Dialogs = Mapper.Map <IEnumerable <Dialog>, IEnumerable <DialogViewModel> >(dialogs.OrderByDescending(d => d.Messages.LastOrDefault().CreatedDate))
            };

            foreach (var d in model.Dialogs)
            {
                var otherUserId = _dialogService.GetOtherUserInDialog(d.Id, User.Identity.GetUserId());
                var otherUser   = _userProfileService.GetUserProfileById(otherUserId);
                if (otherUser != null)
                {
                    d.otherUserId        = otherUser.Id;
                    d.otherUserName      = otherUser.Name;
                    d.otherUserImage     = otherUser.Avatar48Path;
                    d.CountOfNewMessages = d.Messages.Count(m => !m.ToViewed && m.SenderId != currentUser.Id);
                }
                if (d.CountOfNewMessages != 0)
                {
                    modelListDialogs.Add(d);
                }
            }
            model.Dialogs = modelListDialogs;
            return(View(model));
        }
Ejemplo n.º 5
0
        // GET: Message
        public ActionResult Inbox(string sortOrder, string currentFilter, string searchString, string senderName, int?page)
        {
            ViewData["CurrentSort"]  = sortOrder;
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
            //ViewBag.FilterParam = String.IsNullOrEmpty(filter) ? "all" : "";
            ViewData["SenderName"]    = senderName;
            ViewData["SearchString"]  = searchString;
            ViewData["CurrentFilter"] = currentFilter;
            var currentUser = _userProfileService.GetUserProfileById(User.Identity.GetUserId());
            var dialogs     = _dialogService.GetUserDialogs(currentUser.Id, i => i.Messages);

            //var messages = _db.Messages.Find(m => m.ReceiverId == User.Identity.GetUserId());

            if (!String.IsNullOrEmpty(searchString))
            {
                //dialogs = dialogs.Where(s => s.MessageBody.Contains(searchString) && s.ReceiverId == User.Identity.GetUserId());
            }
            if (!String.IsNullOrEmpty(senderName))
            {
                //var userProfile = _userProfileService.GetUserProfiles().Where(m => m.ApplicationUser.UserName == senderName).FirstOrDefault();
                //if (userProfile != null)
                //{
                //    messages = messages.Where(s => s.SenderId == userProfile.Id && s.ReceiverId == User.Identity.GetUserId());
                //}
                //else
                //{
                //    messages = Array.Empty<Message>();
                //}
            }

            switch (currentFilter)
            {
            case "read":
                IList <Dialog> readDialogs = new List <Dialog>();
                foreach (var dialog in dialogs)
                {
                    if (dialog.Messages.Any(m => m.ToViewed))
                    {
                        readDialogs.Add(dialog);
                    }
                }
                dialogs = readDialogs;
                break;

            case "unread":
                IList <Dialog> unreadDialogs = new List <Dialog>();
                foreach (var dialog in dialogs)
                {
                    if (dialog.Messages.Any(m => !m.ToViewed))
                    {
                        unreadDialogs.Add(dialog);
                    }
                }
                dialogs = unreadDialogs;
                break;

            default:
                break;
            }
            //switch (sortOrder)
            //{
            //    case "name_desc":
            //        //messages = messages.OrderByDescending(s => s.SenderName);
            //        break;
            //    case "Date":
            //        messages = messages.OrderBy(s => s.CreatedDate);
            //        break;
            //    case "date_desc":
            //        messages = messages.OrderByDescending(s => s.CreatedDate);
            //        break;

            //    default:  // Name ascending
            //        messages = messages.OrderByDescending(s => s.CreatedDate);
            //        break;
            //}

            DialogListViewModel model = new DialogListViewModel()
            {
                Dialogs = Mapper.Map <IEnumerable <Dialog>, IEnumerable <DialogViewModel> >(dialogs.OrderByDescending(d => d.Messages.LastOrDefault().CreatedDate))
            };

            foreach (var d in model.Dialogs)
            {
                var otherUserId = _dialogService.GetOtherUserInDialog(d.Id, User.Identity.GetUserId());
                var otherUser   = _userProfileService.GetUserProfileById(otherUserId);
                if (otherUser != null)
                {
                    d.otherUserId        = otherUser.Id;
                    d.otherUserName      = otherUser.Name;
                    d.otherUserImage     = otherUser.Avatar48Path;
                    d.CountOfNewMessages = d.Messages.Count(m => !m.ToViewed && m.SenderId != currentUser.Id);
                }
            }
            return(View(model));
        }