Beispiel #1
0
        private void LoadMessages(List <MessageDTO> messages, bool newMessages)
        {
            messages.Sort((x, y) => x.SendDate.CompareTo(y.SendDate));
            foreach (var message in messages)
            {
                if (Conversations.All(x => x.Username != message.Username))
                {
                    var conversation = new Conversation()
                    {
                        InterlocutorId = message.UserId,
                        Name           = message.Name,
                        Username       = message.Username,
                        Messages       = new ObservableCollection <Message>(),
                        IsActive       = true,
                        Color          = new SolidColorBrush(Color.FromRgb((byte)_random.Next(30, 255),
                                                                           (byte)_random.Next(30, 255), (byte)_random.Next(30, 255))),
                    };

                    if (newMessages)
                    {
                        conversation.UnreadMessages++;
                    }

                    conversation.Messages.Add(new Message()
                    {
                        Content  = message.Content,
                        Id       = message.Id,
                        IsAuthor = message.IsAuthor
                    });

                    Conversations.Add(conversation);
                }
                else
                {
                    var conversation = Conversations.First(x => x.Username == message.Username);
                    if (conversation.Messages.All(x => x.Id != message.Id))
                    {
                        conversation.Messages.Add(new Message()
                        {
                            Content  = message.Content,
                            Id       = message.Id,
                            IsAuthor = message.IsAuthor
                        });

                        if (newMessages)
                        {
                            conversation.UnreadMessages++;
                        }
                    }
                }

                _parent.MessagesListBox.Items.Refresh();
            }
        }
Beispiel #2
0
        public async void SearchPossibleUsers(string text)
        {
            if (ServiceManager.IsConnected)
            {
                if (_isSearching)
                {
                    return;
                }
                _isSearching = true;
                ClearSearchUsers();
                _canClear = false;

                var temp          = new List <Conversation>();
                var possibleUsers = await ServiceManager.GetPossibleUsers(text);

                if (string.IsNullOrEmpty(_parent.SearchTextBox.Text))
                {
                    _isSearching = false;
                    return;
                }

                foreach (var conversation in Conversations)
                {
                    conversation.IsActive = conversation.Username.StartsWith(text);
                }

                foreach (var user in possibleUsers)
                {
                    if (Conversations.All(x => x.Username != user.Username))
                    {
                        var conversation = new Conversation()
                        {
                            InterlocutorId = user.UserId,
                            Name           = user.Name,
                            Username       = user.Username,
                            Messages       = new ObservableCollection <Message>(),
                            IsActive       = true,
                            Color          = new SolidColorBrush(Color.FromRgb((byte)_random.Next(30, 255),
                                                                               (byte)_random.Next(30, 255), (byte)_random.Next(30, 255))),
                        };

                        Conversations.Add(conversation);
                        temp.Add(conversation);
                    }
                }

                _tempList = temp;
                _parent.ConversationsListBox.Items.Refresh();
                _canClear    = true;
                _isSearching = false;
            }
        }