public void Handle(TLUpdateWebPage updateWebPage) { Execute.BeginOnUIThread(() => { var webPageBase = updateWebPage.WebPage; foreach (var webPageKeyValue in _webPagesCache) { var mediaBase = webPageKeyValue.Value; var webPageMessageMedia = mediaBase as TLMessageMediaWebPage; if (webPageMessageMedia != null) { var webPage = webPageMessageMedia.WebPage; if (webPage != null) { if (webPage.Id.Value == webPageBase.Id.Value) { webPageMessageMedia.WebPage = webPageBase; if (string.Equals(Text, webPageKeyValue.Key)) { if (webPageBase is TLWebPage || webPageBase is TLWebPagePending) { SaveReply(); Reply = new TLDecryptedMessagesContainter { WebPageMedia = webPageMessageMedia }; } else { RestoreReply(); } } break; } } } } foreach (var item in Items) { var message45 = item as TLDecryptedMessage45; if (message45 != null) { var mediaWebPage = message45.Media as TLDecryptedMessageMediaWebPage; if (mediaWebPage != null) { var webPage = mediaWebPage.WebPage; if (webPage != null && webPage.Id.Value == updateWebPage.WebPage.Id.Value) { mediaWebPage.WebPage = updateWebPage.WebPage; message45.NotifyOfPropertyChange(() => message45.MediaSelf); } } } } }); }
private void GetWebPagePreviewAsync(string t) { if (t == null) { return; } var text = t.Trim(); TLMessageMediaBase webPageMedia; if (_webPagesCache.TryGetValue(text, out webPageMedia)) { var webPageMessageMedia = webPageMedia as TLMessageMediaWebPage; if (webPageMessageMedia != null) { var webPage = webPageMessageMedia.WebPage as TLWebPage; if (webPage != null) { SaveReply(); Reply = new TLDecryptedMessagesContainter { WebPageMedia = webPageMedia }; } else { RestoreReply(); } } return; } else { RestoreReply(); } Execute.BeginOnUIThread(TimeSpan.FromSeconds(1.0), () => { if (!string.Equals(Text, text)) { return; } if (text.IndexOf(".", StringComparison.Ordinal) == -1) { return; } Uri uri; var uriString = text.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? text : "http://" + text; if (Uri.TryCreate(uriString, UriKind.Absolute, out uri)) { if (!CheckWebPagePreviewsNotification()) { return; } MTProtoService.GetWebPagePreviewAsync(new TLString(text), result => Execute.BeginOnUIThread(() => { _webPagesCache[text] = result; if (!string.Equals(Text, text)) { return; } var webPageMessageMedia = result as TLMessageMediaWebPage; if (webPageMessageMedia != null) { var webPage = webPageMessageMedia.WebPage; if (webPage is TLWebPage || webPage is TLWebPagePending) { SaveReply(); Reply = new TLDecryptedMessagesContainter { WebPageMedia = result }; } } }), error => { Execute.ShowDebugMessage("messages.getWebPagePreview error " + error); }); } }); }