Archived
1
0

Core refactoring (app doesn't work)

This commit is contained in:
Michael Gordeev
2020-05-09 23:16:19 +03:00
parent 2b1f06dd93
commit 2a987e33a2
35 changed files with 1135 additions and 817 deletions
+83
View File
@@ -0,0 +1,83 @@
using FoxTube.Models;
using FoxTube.Utils;
using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Notifications;
namespace FoxTube.Services
{
public static class Inbox
{
private static readonly HttpClient client = new HttpClient();
private static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
public static async void PushNew()
{
try
{
// TODO: Add backend
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/FoxTube/Messages?toast=true&publishedAfter={storage.Values["Inbox.lastCheck"]}&lang={Settings.Language}&appVersion={Metrics.CurrentVersion}");
storage.Values["Inbox.lastCheck"] = DateTime.UtcNow.Ticks;
if (response.StatusCode == HttpStatusCode.NoContent)
return;
string[] toasts = JsonConvert.DeserializeObject<string[]>(await response.Content.ReadAsStringAsync());
foreach (string toast in toasts)
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(toast.ToXml()));
}
catch (Exception e)
{
Metrics.SendReport(new Exception("Unable to retrieve toast notifications", e));
}
}
public static async Task<InboxItem[]> GetMessages()
{
try
{
// TODO: Add backend
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/API/FoxTube/Inbox?lang={Settings.Language}&currentVersion={Metrics.CurrentVersion}");
if (response.StatusCode == HttpStatusCode.NoContent)
return new InboxItem[0];
return JsonConvert.DeserializeObject<InboxItem[]>(await response.Content.ReadAsStringAsync());
}
catch (Exception e)
{
Metrics.SendReport(new Exception("Unable to retrieve inbox messages", e));
return new InboxItem[0];
}
}
/// <summary>
/// Fires toast notification with the last changelog content
/// </summary>
public static async void PushChangelog()
{
try
{
// TODO: Add backend
Settings.LastReviewedVersion = Metrics.CurrentVersion;
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/API/FoxTube/Changelogs?toast=true&lang={Settings.Language}&version={Metrics.CurrentVersion}");
if (response.StatusCode == HttpStatusCode.NoContent)
return;
ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification((await response.Content.ReadAsStringAsync()).ToXml()));
}
catch (Exception e)
{
Metrics.SendReport(new Exception("Unable to retrieve changelog", e));
}
}
}
}