Exemplo n.º 1
0
        private async void GetDialogsInfo()
        {
            try
            {
                var unreadDialogs = await _messageService.GetDialogs(true);

                foreach (var dialog in unreadDialogs)
                {
                    if (dialog.Message.ChatId != 0)
                    {
                        continue;
                    }

                    var friend = FoundFriends.FirstOrDefault(f => f.Id == dialog.Message.UserId);
                    if (friend != null)
                    {
                        friend.NumberOfNewMessages = dialog.UnreadMessagesAmount;
                        //UnreadDialogs.Add(friend);
                    }
                }
                var newDialogFriends  = FoundFriends.Where(f => f.NumberOfNewMessages != null).ToList();
                var readDialofFriends = FoundFriends.Where(f => f.NumberOfNewMessages == null).ToList();
                newDialogFriends.AddRange(readDialofFriends);
                FoundFriends = newDialogFriends;
                OnPropertyChanged("FoundFriends");
            }
            catch (WebException)
            {
            }
        }
Exemplo n.º 2
0
        private async void AddMessages(Message message)
        {
            if (message.Out && message.Body.StartsWith(_cryptTool._isCryptedFlag)) //не выводим свое отправленное зашифрованное сообщение - незачем
            {
                return;
            }

            if ((SelectedUser == null || message.UserId != SelectedUser.Id) && !message.Out)
            {
                var friend = FoundFriends.FirstOrDefault(f => f.Id == message.UserId);
                if (friend != null)
                {
                    if (friend.NumberOfNewMessages == null)
                    {
                        friend.NumberOfNewMessages = 1;
                    }
                    else
                    {
                        friend.NumberOfNewMessages++;
                    }
                    //UnreadDialogs.Add(friend);
                    FoundFriends.Remove(friend);
                    FoundFriends.Insert(0, friend);
                    FoundFriends = new List <User>(FoundFriends);
                }
                OnPropertyChanged("FoundFriends");
            }

            if (SelectedUser == null)
            {
                return;
            }


            var decryptedMessage = _cryptTool.SplitAndUnpackReceivedMessage(message.Body);

            message.Body = decryptedMessage;
            TakeFileNamesFromBody(message);
            if (message.Attachments != null && message.Attachments.Where(a => a.File == null).ToList().Count != 0)
            {
                message.HasUndefinedContent = true;
                message.Attachments         = new ObservableCollection <Attachment>(message.Attachments.Where(a => a.File != null));
            }


            if (message.UserId != SelectedUser.Id)
            {
                return;
            }
            message.User = message.Out ? AuthorizeService.Instance.CurrentUser : SelectedUser;

            if (!message.Out)
            {
                try
                {
                    message.IsNotRead = false;
                    _messageService.MarkMessagesAsRead(new List <int> {
                        message.Id
                    }, SelectedUser.Id);
                    await FindKeyRequestAndReply(message);
                    await GetKeyFileFromMessage(message);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
            //todo переделать биндинг
            var messages = new List <Message>();

            messages.AddRange(Messages);
            messages.Add(message);
            Messages    = messages;
            ScrollToEnd = true;
        }