Mare 0.9 (#65)

* add jwt expiry

* start of 0.9 api impl

* some stuff idk

* some more impl

* some cleanup

* remove grouppair, add configuration, rework some pair drawing stuff

* do some stuff

* rework some ui

* I don't even know anymore

* add cancellationtoken

* token bla

* ui fixes etc

* probably individual adding/removing now working fully as expected

* add working report popup

* I guess it's more syncshell shit or so

* popup shit idk

* work out most of the syncshell bullshit I guess

* delete some old crap

* are we actually getting closer to the end

* update pair info stuff

* more fixes/adjustments, idk

* refactor some things

* some rework

* some more cleanup

* cleanup

* make menu buttons w i d e

* better icon text buttons

* add all syncshell folder and ordering fixes

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2023-10-17 21:36:44 +02:00
committed by GitHub
parent f15b8f6bbd
commit 14575a4a6b
111 changed files with 3456 additions and 3174 deletions

View File

@@ -1,3 +0,0 @@
namespace MareSynchronos.Services.ServerConfiguration;
public record JwtCache(string ApiUrl, string PlayerName, uint WorldId, string SecretKey);

View File

@@ -1,5 +1,6 @@
using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Models;
using MareSynchronos.Services.Mediator;
using MareSynchronos.WebAPI;
using Microsoft.Extensions.Logging;
using System.Diagnostics;
@@ -11,18 +12,20 @@ public class ServerConfigurationManager
private readonly ServerConfigService _configService;
private readonly DalamudUtilService _dalamudUtil;
private readonly ILogger<ServerConfigurationManager> _logger;
private readonly MareMediator _mareMediator;
private readonly NotesConfigService _notesConfig;
private readonly ServerTagConfigService _serverTagConfig;
private readonly Dictionary<JwtCache, string> _tokenDictionary = new();
public ServerConfigurationManager(ILogger<ServerConfigurationManager> logger, ServerConfigService configService,
ServerTagConfigService serverTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil)
ServerTagConfigService serverTagConfig, NotesConfigService notesConfig, DalamudUtilService dalamudUtil,
MareMediator mareMediator)
{
_logger = logger;
_configService = configService;
_serverTagConfig = serverTagConfig;
_notesConfig = notesConfig;
_dalamudUtil = dalamudUtil;
_mareMediator = mareMediator;
EnsureMainExists();
}
@@ -92,7 +95,7 @@ public class ServerConfigurationManager
{
try
{
return _configService.Current.ServerStorage.ElementAt(idx);
return _configService.Current.ServerStorage[idx];
}
catch
{
@@ -107,20 +110,6 @@ public class ServerConfigurationManager
return _configService.Current.ServerStorage.Select(v => v.ServerName).ToArray();
}
public string? GetToken()
{
var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult();
var worldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult();
var secretKey = GetSecretKey();
if (secretKey == null) return null;
if (_tokenDictionary.TryGetValue(new JwtCache(CurrentApiUrl, charaName, worldId, secretKey), out var token))
{
return token;
}
return null;
}
public bool HasValidConfig()
{
return CurrentServer != null;
@@ -129,19 +118,10 @@ public class ServerConfigurationManager
public void Save()
{
var caller = new StackTrace().GetFrame(1)?.GetMethod()?.ReflectedType?.Name ?? "Unknown";
_logger.LogDebug(caller + " Calling config save");
_logger.LogDebug("{caller} Calling config save", caller);
_configService.Save();
}
public void SaveToken(string token)
{
var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult();
var worldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult();
var secretKey = GetSecretKey();
if (string.IsNullOrEmpty(secretKey)) throw new InvalidOperationException("No secret key set");
_tokenDictionary[new JwtCache(CurrentApiUrl, charaName, worldId, secretKey)] = token;
}
public void SelectServer(int idx)
{
_configService.Current.CurrentServer = idx;
@@ -185,6 +165,7 @@ public class ServerConfigurationManager
{
CurrentServerTagStorage().ServerAvailablePairTags.Add(tag);
_serverTagConfig.Save();
_mareMediator.Publish(new RefreshUiMessage());
}
internal void AddTagForUid(string uid, string tagName)
@@ -192,10 +173,11 @@ public class ServerConfigurationManager
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
{
tags.Add(tagName);
_mareMediator.Publish(new RefreshUiMessage());
}
else
{
CurrentServerTagStorage().UidServerPairedUserTags[uid] = new() { tagName };
CurrentServerTagStorage().UidServerPairedUserTags[uid] = [tagName];
}
_serverTagConfig.Save();
@@ -295,6 +277,7 @@ public class ServerConfigurationManager
RemoveTagForUid(uid, tag, save: false);
}
_serverTagConfig.Save();
_mareMediator.Publish(new RefreshUiMessage());
}
internal void RemoveTagForUid(string uid, string tagName, bool save = true)
@@ -302,8 +285,23 @@ public class ServerConfigurationManager
if (CurrentServerTagStorage().UidServerPairedUserTags.TryGetValue(uid, out var tags))
{
tags.Remove(tagName);
if (save)
{
_serverTagConfig.Save();
_mareMediator.Publish(new RefreshUiMessage());
}
}
}
internal void RenameTag(string oldName, string newName)
{
CurrentServerTagStorage().ServerAvailablePairTags.Remove(oldName);
CurrentServerTagStorage().ServerAvailablePairTags.Add(newName);
foreach (var existingTags in CurrentServerTagStorage().UidServerPairedUserTags.Select(k => k.Value))
{
if (existingTags.Remove(oldName))
existingTags.Add(newName);
}
}
@@ -314,6 +312,8 @@ public class ServerConfigurationManager
internal void SetNoteForGid(string gid, string note, bool save = true)
{
if (string.IsNullOrEmpty(gid)) return;
CurrentNotesStorage().GidServerComments[gid] = note;
if (save)
_notesConfig.Save();
@@ -321,6 +321,8 @@ public class ServerConfigurationManager
internal void SetNoteForUid(string uid, string note, bool save = true)
{
if (string.IsNullOrEmpty(uid)) return;
CurrentNotesStorage().UidServerComments[uid] = note;
if (save)
_notesConfig.Save();