private void InsertMessage(TLMessageCommon message) { var messagesWithLinks = LinkUtils.ProcessLinks(new List <TLMessageBase> { message }, _mediaWebPagesCache); if (messagesWithLinks.Count > 0) { BeginOnUIThread(() => { InsertMessages(messagesWithLinks); Status = string.Empty; if (Items.Count == 0) { IsEmptyList = true; NotifyOfPropertyChange(() => IsEmptyList); } }); } }
public void LoadNextSlice() { if (_isLoadingNextSlice) { return; } if (CurrentItem is TLBroadcastChat && !(CurrentItem is TLChannel)) { Status = string.Empty; if (Items.Count == 0) { IsEmptyList = true; NotifyOfPropertyChange(() => IsEmptyList); } return; } var channel = CurrentItem as TLChannel; if (channel != null && channel.MigratedFromChatId != null) { if (IsLastSliceLoaded) { LoadNextMigratedHistorySlice(); return; } var lastMessage = Items.LastOrDefault() as TLMessageCommon; if (lastMessage != null && lastMessage.ToId is TLPeerChat) { LoadNextMigratedHistorySlice(); return; } } if (IsLastSliceLoaded) { return; } var maxId = 0; var lastItem = Items.LastOrDefault(); if (lastItem != null) { maxId = lastItem.Index; } IsWorking = true; _isLoadingNextSlice = true; MTProtoService.SearchAsync( CurrentItem.ToInputPeer(), TLString.Empty, null, InputMessageFilter, new TLInt(0), new TLInt(0), new TLInt(0), new TLInt(maxId), new TLInt(Constants.FileSliceLength), new TLInt(0), messages => { LinkUtils.ProcessLinks(messages.Messages, _mediaWebPagesCache); BeginOnUIThread(() => { Status = string.Empty; IsWorking = false; _isLoadingNextSlice = false; AddMessages(messages.Messages.ToList()); if (messages.Messages.Count < Constants.PhotoVideoSliceLength) { IsLastSliceLoaded = true; LoadNextMigratedHistorySlice(); } IsEmptyList = Items.Count == 0; NotifyOfPropertyChange(() => IsEmptyList); }); }, error => { Status = string.Empty; IsWorking = false; _isLoadingNextSlice = false; Execute.ShowDebugMessage("messages.search error " + error); }); }
private void LoadNextMigratedHistorySlice() { var channel = CurrentItem as TLChannel; if (channel == null || channel.MigratedFromChatId == null) { return; } if (_isLastMigratedHistorySliceLoaded) { return; } if (_isLoadingNextMigratedHistorySlice) { return; } var maxMessageId = int.MaxValue; for (var i = 0; i < Items.Count; i++) { var messageCommon = Items[i] as TLMessageCommon; if (messageCommon == null) { continue; } var peerChat = messageCommon.ToId as TLPeerChat; if (peerChat == null) { continue; } if (Items[i].Index != 0 && Items[i].Index < maxMessageId) { maxMessageId = Items[i].Index; } } if (maxMessageId == int.MaxValue) { maxMessageId = channel.MigratedFromMaxId != null ? channel.MigratedFromMaxId.Value : 0; } _isLoadingNextMigratedHistorySlice = true; IsWorking = true; MTProtoService.SearchAsync( new TLInputPeerChat { ChatId = channel.MigratedFromChatId }, TLString.Empty, null, InputMessageFilter, new TLInt(0), new TLInt(0), new TLInt(0), new TLInt(maxMessageId), new TLInt(Constants.FileSliceLength), new TLInt(0), result => { LinkUtils.ProcessLinks(result.Messages, _mediaWebPagesCache); BeginOnUIThread(() => { _isLoadingNextMigratedHistorySlice = false; IsWorking = false; Status = string.Empty; if (result.Messages.Count < Constants.MessagesSlice) { _isLastMigratedHistorySliceLoaded = true; } AddMessages(result.Messages); IsEmptyList = Items.Count == 0; NotifyOfPropertyChange(() => IsEmptyList); }); }, error => BeginOnUIThread(() => { _isLoadingNextMigratedHistorySlice = false; IsWorking = false; Status = string.Empty; Execute.ShowDebugMessage("messages.getHistory error " + error); })); }
public void LoadNextSlice() { if (LazyItems.Count > 0) { return; } if (IsWorking) { return; } if (_isLastSliceLoaded) { return; } if (CurrentItem is TLBroadcastChat && !(CurrentItem is TLChannel)) { Status = string.Empty; if (Items.Count == 0) { IsEmptyList = true; NotifyOfPropertyChange(() => IsEmptyList); } return; } IsWorking = true; MTProtoService.SearchAsync( CurrentItem.ToInputPeer(), TLString.Empty, new TLInputMessagesFilterUrl(), new TLInt(0), new TLInt(0), new TLInt(0), new TLInt(_lastMinId), new TLInt(Constants.FileSliceLength), messages => { var messagesWithLinks = LinkUtils.ProcessLinks(messages.Messages, _mediaWebPagesCache); BeginOnUIThread(() => { if (messages.Messages.Count == 0 || messages.Messages.Count < Constants.FileSliceLength) { _isLastSliceLoaded = true; } if (messages.Messages.Count > 0) { _lastMinId = messages.Messages.Min(x => x.Index); } AddMessages(messagesWithLinks); Status = string.Empty; if (Items.Count == 0) { IsEmptyList = true; NotifyOfPropertyChange(() => IsEmptyList); } IsWorking = false; }); }, error => { Execute.ShowDebugMessage("messages.search error " + error); Status = string.Empty; IsWorking = false; }); }