Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube.Core/Services/InboxService.cs
T
2020-06-11 21:17:18 +03:00

78 lines
2.3 KiB
C#

using FoxTube.Models.Collections;
using FoxTube.Utils;
using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.UI.Notifications;
namespace FoxTube.Services
{
public static class InboxService
{
public const string lastChangelogVersionKey = "Inbox.lastChangelogVersion";
public const string lastCheckKey = "Inbox.lastChangelogVersion";
private static readonly HttpClient client = new HttpClient();
public static InboxCollection GetInboxCollection() =>
new InboxCollection();
public static async Task PushNew()
{
try
{
// TODO: Add backend
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/FoxTube/Inbox?" +
$"toast=true&" +
$"publishedAfter={Storage.Registry.Values[lastCheckKey]}&" +
$"lang={Storage.GetValue<string>(Storage.Settings.UILanguage)}&" +
$"appVersion={Metrics.CurrentVersion}");
Storage.Registry.Values[lastCheckKey] = 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));
}
}
/// <summary>
/// Fires toast notification with the last changelog content
/// </summary>
public static async void PushChangelog()
{
try
{
// TODO: Add backend
if ((string)Storage.Registry.Values[lastChangelogVersionKey] == Metrics.CurrentVersion)
return;
Storage.Registry.Values[lastChangelogVersionKey] = Metrics.CurrentVersion;
HttpResponseMessage response = await client.GetAsync($"https://xfox111.net/API/FoxTube/Changelog?" +
$"lang={Storage.GetValue<string>(Storage.Settings.UILanguage)}&" +
$"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));
}
}
}
}