public void LoadNextInlineBotResults() { if (_isLoadingNextInlineBotResults) { return; } if (CurrentInlineBot == null) { return; } if (_currentInlineBotResults == null) { return; } if (_currentInlineBotResults.NextOffset == null) { return; } var currentInlineBot = CurrentInlineBot; var currentInlineBotResults = _currentInlineBotResults; var currentText = _currentText; var user = CurrentInlineBot as TLUser; if (user == null) { return; } var username = user.UserName; _isLoadingNextInlineBotResults = true; IsWorking = true; var geoPoint = GetGeoPoint(user as TLUser45); System.Diagnostics.Debug.WriteLine("GetInlineBotResults location={0} text={1}", geoPoint, currentText); //Telegram.Api.Helpers.Execute.ShowDebugMessage(string.Format("messages.getInlineBotResults username={0} query={1}", currentInlineBot.UserName, currentText)); MTProtoService.GetInlineBotResultsAsync(currentInlineBot.ToInputUser(), Peer, geoPoint, new TLString(currentText), currentInlineBotResults.NextOffset, result => BeginOnUIThread(() => { _isLoadingNextInlineBotResults = false; IsWorking = false; if (CurrentInlineBot == currentInlineBot && currentInlineBotResults == _currentInlineBotResults && _currentText == currentText) { for (var i = 0; i < result.Results.Count; i++) { result.Results[i].QueryId = result.QueryId; InlineBotResults.Results.Add(result.Results[i]); } if (InlineBotResults.Results.Count > 0) { View.PauseChatPlayers(); } } TLBotResults cachedResult; if (_cachedInlineBotResults.TryGetValue(string.Format("{0}_{1}", username, currentText), out cachedResult)) { _cachedInlineBotResults[string.Format("{0}_{1}", username, currentText)] = MergeInlineBotResults(cachedResult, result); } else { _cachedInlineBotResults[string.Format("{0}_{1}", username, currentText)] = result; } }), error => BeginOnUIThread(() => { _isLoadingNextInlineBotResults = false; IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("messages.getInlineBotResults error " + error); })); }
public void GetInlineBotResults(string text) { //Telegram.Api.Helpers.Execute.ShowDebugMessage("GetInlineBotResults text='" + text + "'"); if (text == null) { return; } var currentInlineBot = CurrentInlineBot as TLUser; if (currentInlineBot == null) { return; } var username = currentInlineBot.UserName; if (TLString.IsNullOrEmpty(username)) { return; } var user45 = currentInlineBot as TLUser45; if (!CheckBotInlineGeoAccess(user45)) { return; } if (StartGeoWatching(text, user45)) { return; } var currentText = text; _currentText = text; ClearInlineBotResults(); TLBotResults cachedResult; if (_cachedInlineBotResults.TryGetValue(string.Format("{0}_{1}", username, text), out cachedResult)) { if (cachedResult != null) { BeginOnUIThread(TimeSpan.FromSeconds(0.5), () => { if (CurrentInlineBot != currentInlineBot) { return; } if (_currentText != currentText) { return; } System.Diagnostics.Debug.WriteLine(" CachedResults location={0} text={1}", _watcher != null? _watcher.Position.Location : null, text); CreateInlineBotResults(); InlineBotResults.Gallery = cachedResult.Gallery; var cachedResult51 = cachedResult as TLBotResults51; if (cachedResult51 != null) { InlineBotResults.SwitchPM = cachedResult51.SwitchPM; } for (var i = 0; i < cachedResult.Results.Count; i++) { if (i == InlineBotMaxResults) { break; } InlineBotResults.Results.Add(cachedResult.Results[i]); } if (InlineBotResults.Results.Count > 0) { View.PauseChatPlayers(); } _currentInlineBotResults = cachedResult; }); } } else { BeginOnUIThread(TimeSpan.FromSeconds(0.5), () => { if (CurrentInlineBot != currentInlineBot) { return; } if (_currentText != currentText) { return; } var geoPoint = GetGeoPoint(user45); //System.Diagnostics.Debug.WriteLine(" GetInlineBotResults location={0} text={1}", geoPoint, text); IsWorking = true; //Telegram.Api.Helpers.Execute.ShowDebugMessage(string.Format("messages.getInlineBotResults username={0} query={1}", currentInlineBot.UserName, currentText)); MTProtoService.GetInlineBotResultsAsync(currentInlineBot.ToInputUser(), Peer, geoPoint, new TLString(currentText), TLString.Empty, result => BeginOnUIThread(() => { IsWorking = false; CreateInlineBotResults(); if (CurrentInlineBot == currentInlineBot && _currentText == currentText) { InlineBotResults.Gallery = result.Gallery; var cachedResult51 = result as TLBotResults51; if (cachedResult51 != null) { InlineBotResults.SwitchPM = cachedResult51.SwitchPM; } for (var i = 0; i < result.Results.Count; i++) { if (i == InlineBotMaxResults) { break; } result.Results[i].QueryId = result.QueryId; InlineBotResults.Results.Add(result.Results[i]); } if (InlineBotResults.Results.Count > 0) { View.PauseChatPlayers(); } } _currentInlineBotResults = result; _cachedInlineBotResults[string.Format("{0}_{1}", username, currentText)] = result; }), error => BeginOnUIThread(() => { IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("messages.getInlineBotResults error " + error); })); }); } }