protected override void OnNavigatedTo(NavigationEventArgs e) { var isDark = Application.Current.RequestedTheme == ApplicationTheme.Dark; if (isDark) { SPanel.Background = new SolidColorBrush(Windows.UI.Colors.Black); } TootCollectionBind = new ObservableCollection <object>(); TootContainer.DataContext = TootCollectionBind; base.OnNavigatedTo(e); var settings = (string)e.Parameter; HttpConnectionClass token = new HttpConnectionClass(GetToken.getAuthClass()); //List<StatusClass> tootlist = null; StatusClass_new[] tootlist; string baseuri = "https://" + token.auth.server; if (baseuri != "https://mamot.fr") { if (settings == "notifications") { baseuri = baseuri + "/api/v1/streaming/user"; } else if (settings == "PublicTimeline") { baseuri = baseuri + "/api/v1/streaming/public"; } else if (settings == "LocalPublicTimeline") { baseuri = baseuri + "/api/v1/streaming/public?local=true"; } else { baseuri = baseuri + "/api/v1/streaming/user"; } } else { if (settings == "notifications") { baseuri = baseuri + "/api/v1/streaming/user"; } else if (settings == "PublicTimeline") { baseuri = baseuri + "/api/v1/streaming/public"; } else if (settings == "LocalPublicTimeline") { baseuri = baseuri + "/api/v1/streaming/public?local=true"; } else { // even this doesn't work on the LQDN instance... it's just broken baseuri = baseuri + "/api/v1/streaming/?&access_token=" + token.auth.token + "&stream=user"; } } HttpClient client = token.client; tootrefresh = ThreadPool.RunAsync(async(source) => { Stream msg; try { msg = await client.GetStreamAsync(baseuri); } catch { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (async() => { var errorDialog = new ContentDialog { Name = "Connection error", Title = "Streaming doesn't currently work properly. The app will work with reduced functionallity.", IsPrimaryButtonEnabled = false, SecondaryButtonText = "ok" }; await errorDialog.ShowAsync(); })); return; } while (1 == 1) { var st = new StreamReader(msg); string text = st.ReadLine(); if (text == null) { try { msg = await client.GetStreamAsync(baseuri); // reset the connection } catch { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (async() => { var errorDialog = new ContentDialog { Name = "Connection error", Title = "Streaming doesn't currently work properly. The app will work with reduced functionallity.", IsPrimaryButtonEnabled = false, SecondaryButtonText = "ok" }; await errorDialog.ShowAsync(); })); return; } } else if ((text.ToArray())[0] != ':') { string[] text2 = text.Split(':'); var intermediate = (text.Split('\n')); string text3 = intermediate.Aggregate((a, b) => a + b); string stdata = st.ReadLine(); stdata = new string(stdata.Skip(5).ToArray()); if (text2[1] == " delete") { st.DiscardBufferedData(); } if (text2[1] == " update") { while (stdata.Last() != '}') { stdata = stdata + st.ReadLine(); } StatusClass_new status = StatusClass_new.parseToot(stdata); // Insert at the beginning await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (() => { Toot toot = new Toot(status); TootCollectionBind.Add(toot); })); } else if (text2[1] == " notification") { NotificationClass_new notification = NotificationClass_new.parseNotification(stdata); if (notification.id != null) { if (notification.type == "favourite") { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (() => { TextBlock block = new TextBlock(); Toot toot; if (notification.account.display_name != "") { block.Text = notification.account.display_name + " favourited your post."; } else { block.Text = notification.account.acct + " favourited your post."; } toot = new Toot(notification.status); TootCollectionBind.Add(block); TootCollectionBind.Add(toot); })); } if (notification.type == "reblog") { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (() => { TextBlock block = new TextBlock(); Toot toot; if (notification.account.display_name != "") { block.Text = notification.account.display_name + " boosted your post."; } else { block.Text = notification.account.acct + " boosted your post."; } toot = new Toot(notification.status); TootCollectionBind.Add(block); TootCollectionBind.Add(toot); })); } if (notification.type == "follow") { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (() => { TextBlock block = new TextBlock(); if (notification.account.display_name == "") { block.Text = notification.account.display_name + " now follows you."; } else { block.Text = notification.account.acct + " now follows you."; } TootCollectionBind.Add(block); })); } if (notification.type == "mention") { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, (() => { Toot toot; toot = new Toot(notification.status); TootCollectionBind.Add(toot); })); } } } } } } ); if (settings != "notifications") { if (settings == "PublicTimeline") { //tootlist = StatusClass.getPublicTimeline(token); tootlist = StatusClass_new.GetPublicTimeline(token); } else if (settings == "LocalPublicTimeline") { tootlist = StatusClass_new.GetPublicLocalTimeline(token); } else { tootlist = StatusClass_new.GetTimeline(token); } for (int i = tootlist.Length - 1; i >= 0; i--) { Toot toot; toot = new Toot(tootlist[i]); TootCollectionBind.Add(toot); } } else { NotificationClass_new[] notifications = NotificationClass_new.getNotifications(token); for (int i = notifications.Length - 1; i >= 0; i--) { if (notifications[i].id != null) { if (notifications[i].type == "favourite") { TextBlock block = new TextBlock(); Toot toot; if (notifications[i].account.display_name != "") { block.Text = notifications[i].account.display_name + " favourited your post."; } else { block.Text = notifications[i].account.acct + " favourited your post."; } toot = new Toot(notifications[i].status); TootCollectionBind.Add(block); TootCollectionBind.Add(toot); } if (notifications[i].type == "reblog") { TextBlock block = new TextBlock(); Toot toot; if (notifications[i].account.display_name != "") { block.Text = notifications[i].account.display_name + " boosted your post."; } else { block.Text = notifications[i].account.acct + " boosted your post."; } toot = new Toot(notifications[i].status); TootCollectionBind.Add(block); TootCollectionBind.Add(toot); } if (notifications[i].type == "follow") { TextBlock block = new TextBlock(); if (notifications[i].account.display_name != "") { block.Text = notifications[i].account.display_name + " now follows you."; } else { block.Text = notifications[i].account.acct + " now follows you."; } TootCollectionBind.Add(block); } if (notifications[i].type == "mention") { Toot toot; toot = new Toot(notifications[i].status); TootCollectionBind.Add(toot); } } } } }
void IBackgroundTask.Run(IBackgroundTaskInstance taskInstance) { AuthenticateClass token = new AuthenticateClass(); token.appname = null; var authfile = ApplicationData.Current.LocalFolder.GetFileAsync("auth.txt"); authfile.AsTask().Wait(); var tokenfile = authfile.GetResults(); var ioop = FileIO.ReadTextAsync(tokenfile); ioop.AsTask().Wait(); token.token = ioop.GetResults(); token.server = MainPage.getServerName(); string baseuri = "https://" + token.server; baseuri = baseuri + "/api/v1/streaming/user"; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.token); var msg = client.GetStreamAsync(baseuri); msg.Wait(); var msga = msg.Result; while (1 == 1) { var st = new StreamReader(msga); string text = st.ReadLine(); if ((text.ToArray())[0] != ':') { string[] text2 = text.Split(':'); string text3 = st.ReadLine(); string stdata = new string((text3.Skip(5)).ToArray()); if (text2[1] == " notification") { NotificationClass_new notification = NotificationClass_new.parseNotification(stdata); if (notification.id != null) { if (notification.type == "favourite") { } if (notification.type == "reblog") { } if (notification.type == "follow") { if (notification.account.avatar[0] == 'h') { notification.account.avatar = "https://" + token.server + notification.account.avatar; } ToastVisual visual = new ToastVisual() { BindingGeneric = new ToastBindingGeneric() { Children = { new AdaptiveText() { Text = notification.account.display_name + " followed you." }, new AdaptiveImage() { Source = notification.account.avatar } } } }; ToastContent toastContent = new ToastContent() { Visual = visual }; var toast = new ToastNotification(toastContent.GetXml()); toast.ExpirationTime = DateTime.Now.AddDays(1); ToastNotificationManager.CreateToastNotifier().Show(toast); } if (notification.type == "mention") { } } } } } }