コード例 #1
0
        private async Task LoadChatMessages(DateTime datetime, bool isNewChatQuery)
        {
            if (isNewChatQuery)
            {
                EndTime = DateTime.Now;
            }
            else
            {
                IsScrollingTop = true;
            }

            List <ChatMessage> listChat = await _networkService.QueryChatAsync(App.User.api_token, EventId, Constants.ChatType.InternalChat, isNewChatQuery, datetime);

            var hasNewChat = false;

            if (listChat != null && listChat.Count > 0)
            {
                if (isNewChatQuery)
                {
                    listChat.Reverse();
                }
                foreach (var chat in listChat)
                {
                    chat.IsFromMe = chat.UserID == App.User.ID;
                    if (chat.CreateTime != DateTime.MinValue && BeginTime > chat.CreateTime)
                    {
                        BeginTime = chat.CreateTime.Value;
                    }
                    if (isNewChatQuery)
                    {
                        var existed = ChatMessages.Any(c => c.ChatID == chat.ChatID);
                        if (!existed)
                        {
                            hasNewChat = true;
                            ChatMessages.Add(chat);
                        }
                    }
                    else
                    {
                        hasNewChat = true;
                        ChatMessages.Insert(0, chat);
                    }
                }
            }

            if (hasNewChat)
            {
                await RaisePropertyChanged(nameof(ChatMessages));
            }
            if (hasNewChat && isNewChatQuery && !IsScrollingTop)
            {
                await RaisePropertyChanged(nameof(RequestScroll));
            }
        }
コード例 #2
0
        private async void UpdateMessages()
        {
            var convo = await _store.GetConversationAsync(_conversationid);

            if (convo == null)
            {
                DropEvents();
                return;
            }

            var reader   = convo.GetMessageReader();
            var messages = await reader.ReadBatchAsync();

            var currindex = ChatMessages.Count();

            foreach (var message in messages)
            {
                if (ChatMessages.Any(x => x.messageId == message.Id))
                {
                    break;
                }

                if (currindex > ChatMessages.Count())
                {
                    currindex = ChatMessages.Count();
                }

                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                              () =>
                {
                    try
                    {
                        ChatMessages.Insert(currindex, new ChatMessageViewControl(message.Id));
                    }
                    catch
                    {
                    }
                });
            }
        }