public async Task OnLoad(object data) { IsLoadingPrevious = true; Message.WasRead = true; var userId = Message.Partner.Model.GetUserId(); var cacheMessages = await Cache.GetMessages(); var messages = cacheMessages.Where(m => m.Recipient == userId || m.Sender == userId) .Select(m => JsonConvert.DeserializeObject <DirectMessage>(m.Data)) .Where(m => m.GetMessageId() < Message.Id) .OrderBy(m => m.CreatedAt); foreach (var m in messages) { var msg = new MessageViewModel(m, Message.Context, Configuration, ViewServiceRepository) { WasRead = true }; await Dispatcher.RunAsync(() => PreviousMessages.Add(msg)); } RaisePropertyChanged(nameof(PreviousMessages)); IsLoadingPrevious = false; await Dispatcher.RunAsync(() => ScrollRequested?.Invoke(this, EventArgs.Empty)); }
/// <summary> /// Called when the textbox is submitted. /// </summary> /// <param name="text"></param> private void OnTextboxSubmit(string text) { if (Overlay.ActiveChannel == null) { return; } var chatMessage = new ChatMessage(Overlay.ActiveChannel.Name, text); ChatManager.SendMessage(Overlay.ActiveChannel, chatMessage); // Delete element if message is found if (PreviousMessages.Contains(text)) { PreviousMessages.Remove(text); } // Save messages PreviousMessages.Add(text); // Scroll to the bottom when sending chat messages var messageContainer = Overlay.ChannelMessageContainers[Overlay.ActiveChannel]; messageContainer.ScrollTo(-messageContainer.ContentContainer.Height, 800); }