2019-09-29 19:40:13 +00:00
|
|
|
using System;
|
2019-06-14 20:48:19 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2020-02-22 19:11:37 +00:00
|
|
|
using System.Text.RegularExpressions;
|
2019-06-14 20:48:19 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-06-14 20:48:19 +00:00
|
|
|
using Newtonsoft.Json;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-06-14 20:48:19 +00:00
|
|
|
using NodaTime;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-07-18 15:13:42 +00:00
|
|
|
using Serilog;
|
2019-06-14 20:48:19 +00:00
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
namespace PluralKit.Core
|
2019-06-14 20:48:19 +00:00
|
|
|
{
|
|
|
|
public class DataFileService
|
|
|
|
{
|
2020-08-29 11:46:27 +00:00
|
|
|
private readonly IDatabase _db;
|
|
|
|
private readonly ModelRepository _repo;
|
|
|
|
private readonly ILogger _logger;
|
2019-06-14 20:48:19 +00:00
|
|
|
|
2020-08-29 11:46:27 +00:00
|
|
|
public DataFileService(ILogger logger, IDatabase db, ModelRepository repo)
|
2019-06-14 20:48:19 +00:00
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
_db = db;
|
2020-08-29 11:46:27 +00:00
|
|
|
_repo = repo;
|
2019-07-18 15:13:42 +00:00
|
|
|
_logger = logger.ForContext<DataFileService>();
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<DataFileSystem> ExportSystem(PKSystem system)
|
|
|
|
{
|
2020-08-29 11:46:27 +00:00
|
|
|
await using var conn = await _db.Obtain();
|
|
|
|
|
2019-10-06 07:03:28 +00:00
|
|
|
// Export members
|
2019-06-14 20:48:19 +00:00
|
|
|
var members = new List<DataFileMember>();
|
2020-08-29 11:46:27 +00:00
|
|
|
var pkMembers = _repo.GetSystemMembers(conn, system.Id); // Read all members in the system
|
2020-01-17 23:58:35 +00:00
|
|
|
|
|
|
|
await foreach (var member in pkMembers.Select(m => new DataFileMember
|
2019-10-06 07:03:28 +00:00
|
|
|
{
|
|
|
|
Id = m.Hid,
|
|
|
|
Name = m.Name,
|
|
|
|
DisplayName = m.DisplayName,
|
|
|
|
Description = m.Description,
|
2020-06-21 14:05:04 +00:00
|
|
|
Birthday = m.Birthday?.FormatExport(),
|
2019-10-06 07:03:28 +00:00
|
|
|
Pronouns = m.Pronouns,
|
|
|
|
Color = m.Color,
|
|
|
|
AvatarUrl = m.AvatarUrl,
|
2019-10-28 19:15:27 +00:00
|
|
|
ProxyTags = m.ProxyTags,
|
2019-10-30 13:11:24 +00:00
|
|
|
KeepProxy = m.KeepProxy,
|
2020-06-21 14:05:04 +00:00
|
|
|
Created = m.Created.FormatExport(),
|
2020-06-12 18:29:50 +00:00
|
|
|
MessageCount = m.MessageCount
|
2020-01-17 23:58:35 +00:00
|
|
|
})) members.Add(member);
|
2019-06-14 20:48:19 +00:00
|
|
|
|
2019-10-06 07:03:28 +00:00
|
|
|
// Export switches
|
2019-06-14 20:48:19 +00:00
|
|
|
var switches = new List<DataFileSwitch>();
|
2020-08-29 11:46:27 +00:00
|
|
|
var switchList = await _repo.GetPeriodFronters(conn, system.Id, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant());
|
2019-10-06 07:03:28 +00:00
|
|
|
switches.AddRange(switchList.Select(x => new DataFileSwitch
|
|
|
|
{
|
2020-06-21 14:05:04 +00:00
|
|
|
Timestamp = x.TimespanStart.FormatExport(),
|
2019-10-06 07:03:28 +00:00
|
|
|
Members = x.Members.Select(m => m.Hid).ToList() // Look up member's HID using the member export from above
|
|
|
|
}));
|
2019-06-14 20:48:19 +00:00
|
|
|
|
|
|
|
return new DataFileSystem
|
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
Version = 1,
|
2019-06-14 20:48:19 +00:00
|
|
|
Id = system.Hid,
|
|
|
|
Name = system.Name,
|
|
|
|
Description = system.Description,
|
|
|
|
Tag = system.Tag,
|
|
|
|
AvatarUrl = system.AvatarUrl,
|
|
|
|
TimeZone = system.UiTz,
|
|
|
|
Members = members,
|
|
|
|
Switches = switches,
|
2020-06-21 14:05:04 +00:00
|
|
|
Created = system.Created.FormatExport(),
|
2020-08-29 11:46:27 +00:00
|
|
|
LinkedAccounts = (await _repo.GetSystemAccounts(conn, system.Id)).ToList()
|
2019-06-14 20:48:19 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-29 12:15:30 +00:00
|
|
|
private MemberPatch ToMemberPatch(DataFileMember fileMember)
|
2020-06-11 19:11:50 +00:00
|
|
|
{
|
2020-06-29 12:15:30 +00:00
|
|
|
var newMember = new MemberPatch
|
2020-06-11 19:11:50 +00:00
|
|
|
{
|
|
|
|
Name = fileMember.Name,
|
|
|
|
DisplayName = fileMember.DisplayName,
|
|
|
|
Description = fileMember.Description,
|
|
|
|
Color = fileMember.Color,
|
|
|
|
Pronouns = fileMember.Pronouns,
|
|
|
|
AvatarUrl = fileMember.AvatarUrl,
|
|
|
|
KeepProxy = fileMember.KeepProxy,
|
2021-03-09 15:19:26 +00:00
|
|
|
MessageCount = fileMember.MessageCount,
|
2020-06-11 19:11:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (fileMember.Prefix != null || fileMember.Suffix != null)
|
2020-06-29 12:15:30 +00:00
|
|
|
newMember.ProxyTags = new[] {new ProxyTag(fileMember.Prefix, fileMember.Suffix)};
|
2020-06-11 19:11:50 +00:00
|
|
|
else
|
|
|
|
// Ignore proxy tags where both prefix and suffix are set to null (would be invalid anyway)
|
2020-06-29 12:15:30 +00:00
|
|
|
newMember.ProxyTags = (fileMember.ProxyTags ?? new ProxyTag[] { }).Where(tag => !tag.IsEmpty).ToArray();
|
2020-06-11 19:11:50 +00:00
|
|
|
|
|
|
|
if (fileMember.Birthday != null)
|
|
|
|
{
|
|
|
|
var birthdayParse = DateTimeFormats.DateExportFormat.Parse(fileMember.Birthday);
|
|
|
|
newMember.Birthday = birthdayParse.Success ? (LocalDate?)birthdayParse.Value : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newMember;
|
|
|
|
}
|
|
|
|
|
2019-07-11 20:46:18 +00:00
|
|
|
public async Task<ImportResult> ImportSystem(DataFileSystem data, PKSystem system, ulong accountId)
|
2019-06-14 20:48:19 +00:00
|
|
|
{
|
2020-08-29 11:46:27 +00:00
|
|
|
await using var conn = await _db.Obtain();
|
|
|
|
|
2019-10-20 07:16:57 +00:00
|
|
|
var result = new ImportResult {
|
|
|
|
AddedNames = new List<string>(),
|
|
|
|
ModifiedNames = new List<string>(),
|
2020-06-11 19:11:50 +00:00
|
|
|
System = system,
|
2019-10-20 07:16:57 +00:00
|
|
|
Success = true // Assume success unless indicated otherwise
|
|
|
|
};
|
2020-06-11 19:11:50 +00:00
|
|
|
|
2019-06-14 20:48:19 +00:00
|
|
|
// If we don't already have a system to save to, create one
|
2019-10-20 07:16:57 +00:00
|
|
|
if (system == null)
|
2020-06-11 19:11:50 +00:00
|
|
|
{
|
2020-08-29 11:46:27 +00:00
|
|
|
system = result.System = await _repo.CreateSystem(conn, data.Name);
|
|
|
|
await _repo.AddAccount(conn, system.Id, accountId);
|
2020-06-11 19:11:50 +00:00
|
|
|
}
|
2020-10-09 14:24:15 +00:00
|
|
|
|
|
|
|
var memberLimit = system.MemberLimitOverride ?? Limits.MaxMemberCount;
|
|
|
|
|
2019-06-14 20:48:19 +00:00
|
|
|
// Apply system info
|
2020-06-29 12:39:19 +00:00
|
|
|
var patch = new SystemPatch {Name = data.Name};
|
|
|
|
if (data.Description != null) patch.Description = data.Description;
|
|
|
|
if (data.Tag != null) patch.Tag = data.Tag;
|
|
|
|
if (data.AvatarUrl != null) patch.AvatarUrl = data.AvatarUrl;
|
|
|
|
if (data.TimeZone != null) patch.UiTz = data.TimeZone ?? "UTC";
|
2020-08-29 11:46:27 +00:00
|
|
|
await _repo.UpdateSystem(conn, system.Id, patch);
|
2020-06-11 19:11:50 +00:00
|
|
|
|
|
|
|
// -- Member/switch import --
|
2020-06-13 16:31:20 +00:00
|
|
|
await using (var imp = await BulkImporter.Begin(system, conn))
|
2019-10-20 07:16:57 +00:00
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
// Tally up the members that didn't exist before, and check member count on import
|
|
|
|
// If creating the unmatched members would put us over the member limit, abort before creating any members
|
2020-08-29 11:46:27 +00:00
|
|
|
var memberCountBefore = await _repo.GetSystemMemberCount(conn, system.Id);
|
2020-06-11 19:11:50 +00:00
|
|
|
var membersToAdd = data.Members.Count(m => imp.IsNewMember(m.Id, m.Name));
|
2020-10-09 14:24:15 +00:00
|
|
|
if (memberCountBefore + membersToAdd > memberLimit)
|
2019-10-30 13:11:24 +00:00
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
result.Success = false;
|
2020-10-09 14:24:15 +00:00
|
|
|
result.Message = $"Import would exceed the maximum number of members ({memberLimit}).";
|
2020-06-11 19:11:50 +00:00
|
|
|
return result;
|
2019-10-30 13:11:24 +00:00
|
|
|
}
|
2020-06-11 19:11:50 +00:00
|
|
|
|
|
|
|
async Task DoImportMember(BulkImporter imp, DataFileMember fileMember)
|
2019-06-15 09:55:11 +00:00
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
var isCreatingNewMember = imp.IsNewMember(fileMember.Id, fileMember.Name);
|
|
|
|
|
|
|
|
// Use the file member's id as the "unique identifier" for the importing (actual value is irrelevant but needs to be consistent)
|
|
|
|
_logger.Debug(
|
|
|
|
"Importing member with identifier {FileId} to system {System} (is creating new member? {IsCreatingNewMember})",
|
|
|
|
fileMember.Id, system.Id, isCreatingNewMember);
|
2020-06-29 12:15:30 +00:00
|
|
|
var newMember = await imp.AddMember(fileMember.Id, fileMember.Id, fileMember.Name, ToMemberPatch(fileMember));
|
2020-06-11 19:11:50 +00:00
|
|
|
|
|
|
|
if (isCreatingNewMember)
|
|
|
|
result.AddedNames.Add(newMember.Name);
|
|
|
|
else
|
|
|
|
result.ModifiedNames.Add(newMember.Name);
|
2019-06-15 09:55:11 +00:00
|
|
|
}
|
2020-06-11 19:11:50 +00:00
|
|
|
|
|
|
|
// Can't parallelize this because we can't reuse the same connection/tx inside the importer
|
|
|
|
foreach (var m in data.Members)
|
|
|
|
await DoImportMember(imp, m);
|
|
|
|
|
|
|
|
// Lastly, import the switches
|
|
|
|
await imp.AddSwitches(data.Switches.Select(sw => new BulkImporter.SwitchInfo
|
2019-10-26 17:45:30 +00:00
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
Timestamp = DateTimeFormats.TimestampExportFormat.Parse(sw.Timestamp).Value,
|
|
|
|
// "Members" here is from whatever ID the data file uses, which the bulk importer can map to the real IDs! :)
|
|
|
|
MemberIdentifiers = sw.Members.ToList()
|
|
|
|
}).ToList());
|
2019-09-29 19:40:13 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 19:38:43 +00:00
|
|
|
_logger.Information("Imported system {System}", system.Hid);
|
2020-06-11 19:11:50 +00:00
|
|
|
return result;
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct ImportResult
|
|
|
|
{
|
|
|
|
public ICollection<string> AddedNames;
|
|
|
|
public ICollection<string> ModifiedNames;
|
|
|
|
public PKSystem System;
|
2019-10-20 07:16:57 +00:00
|
|
|
public bool Success;
|
|
|
|
public string Message;
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public struct DataFileSystem
|
|
|
|
{
|
2020-06-11 19:11:50 +00:00
|
|
|
[JsonProperty("version")] public int Version;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("id")] public string Id;
|
|
|
|
[JsonProperty("name")] public string Name;
|
|
|
|
[JsonProperty("description")] public string Description;
|
|
|
|
[JsonProperty("tag")] public string Tag;
|
|
|
|
[JsonProperty("avatar_url")] public string AvatarUrl;
|
|
|
|
[JsonProperty("timezone")] public string TimeZone;
|
|
|
|
[JsonProperty("members")] public ICollection<DataFileMember> Members;
|
|
|
|
[JsonProperty("switches")] public ICollection<DataFileSwitch> Switches;
|
|
|
|
[JsonProperty("accounts")] public ICollection<ulong> LinkedAccounts;
|
|
|
|
[JsonProperty("created")] public string Created;
|
|
|
|
|
2019-06-14 20:48:19 +00:00
|
|
|
private bool TimeZoneValid => TimeZone == null || DateTimeZoneProviders.Tzdb.GetZoneOrNull(TimeZone) != null;
|
2019-06-15 09:55:11 +00:00
|
|
|
|
2020-02-22 19:11:37 +00:00
|
|
|
[JsonIgnore] public bool Valid =>
|
|
|
|
TimeZoneValid &&
|
|
|
|
Members != null &&
|
2020-10-22 20:50:56 +00:00
|
|
|
// no need to check this here, it is checked later as part of the import
|
|
|
|
// Members.Count <= Limits.MaxMemberCount &&
|
2020-02-22 19:11:37 +00:00
|
|
|
Members.All(m => m.Valid) &&
|
|
|
|
Switches != null &&
|
|
|
|
Switches.Count < 10000 &&
|
|
|
|
Switches.All(s => s.Valid) &&
|
|
|
|
!Name.IsLongerThan(Limits.MaxSystemNameLength) &&
|
|
|
|
!Description.IsLongerThan(Limits.MaxDescriptionLength) &&
|
|
|
|
!Tag.IsLongerThan(Limits.MaxSystemTagLength) &&
|
2020-02-23 11:45:26 +00:00
|
|
|
!AvatarUrl.IsLongerThan(1000);
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public struct DataFileMember
|
|
|
|
{
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("id")] public string Id;
|
|
|
|
[JsonProperty("name")] public string Name;
|
2019-09-29 04:29:32 +00:00
|
|
|
[JsonProperty("display_name")] public string DisplayName;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("description")] public string Description;
|
|
|
|
[JsonProperty("birthday")] public string Birthday;
|
|
|
|
[JsonProperty("pronouns")] public string Pronouns;
|
|
|
|
[JsonProperty("color")] public string Color;
|
|
|
|
[JsonProperty("avatar_url")] public string AvatarUrl;
|
2019-10-28 19:15:27 +00:00
|
|
|
|
|
|
|
// For legacy single-tag imports
|
|
|
|
[JsonProperty("prefix")] [JsonIgnore] public string Prefix;
|
|
|
|
[JsonProperty("suffix")] [JsonIgnore] public string Suffix;
|
|
|
|
|
|
|
|
// ^ is superseded by v
|
|
|
|
[JsonProperty("proxy_tags")] public ICollection<ProxyTag> ProxyTags;
|
2019-10-30 13:11:24 +00:00
|
|
|
|
|
|
|
[JsonProperty("keep_proxy")] public bool KeepProxy;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("message_count")] public int MessageCount;
|
|
|
|
[JsonProperty("created")] public string Created;
|
|
|
|
|
2020-02-22 19:11:37 +00:00
|
|
|
[JsonIgnore] public bool Valid =>
|
|
|
|
Name != null &&
|
|
|
|
!Name.IsLongerThan(Limits.MaxMemberNameLength) &&
|
|
|
|
!DisplayName.IsLongerThan(Limits.MaxMemberNameLength) &&
|
|
|
|
!Description.IsLongerThan(Limits.MaxDescriptionLength) &&
|
|
|
|
!Pronouns.IsLongerThan(Limits.MaxPronounsLength) &&
|
2020-02-25 15:33:49 +00:00
|
|
|
(Color == null || Regex.IsMatch(Color, "[0-9a-fA-F]{6}")) &&
|
2020-02-22 19:11:37 +00:00
|
|
|
(Birthday == null || DateTimeFormats.DateExportFormat.Parse(Birthday).Success) &&
|
2020-03-07 16:30:22 +00:00
|
|
|
|
2020-02-22 19:11:37 +00:00
|
|
|
// Sanity checks
|
|
|
|
!AvatarUrl.IsLongerThan(1000) &&
|
2020-03-07 16:30:22 +00:00
|
|
|
|
|
|
|
// Older versions have Prefix and Suffix as fields, meaning ProxyTags is null
|
|
|
|
(ProxyTags == null || ProxyTags.Count < 100 &&
|
|
|
|
ProxyTags.All(t => !t.ProxyString.IsLongerThan(100))) &&
|
2020-02-22 19:11:37 +00:00
|
|
|
!Prefix.IsLongerThan(100) && !Suffix.IsLongerThan(100);
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public struct DataFileSwitch
|
|
|
|
{
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("timestamp")] public string Timestamp;
|
|
|
|
[JsonProperty("members")] public ICollection<string> Members;
|
2020-02-22 19:11:37 +00:00
|
|
|
|
|
|
|
[JsonIgnore] public bool Valid =>
|
|
|
|
Members != null &&
|
|
|
|
Members.Count < 100 &&
|
|
|
|
DateTimeFormats.TimestampExportFormat.Parse(Timestamp).Success;
|
2019-06-15 09:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public struct TupperboxConversionResult
|
|
|
|
{
|
|
|
|
public bool HadGroups;
|
|
|
|
public bool HadIndividualTags;
|
|
|
|
public DataFileSystem System;
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct TupperboxProfile
|
|
|
|
{
|
|
|
|
[JsonProperty("tuppers")] public ICollection<TupperboxTupper> Tuppers;
|
|
|
|
[JsonProperty("groups")] public ICollection<TupperboxGroup> Groups;
|
|
|
|
|
|
|
|
[JsonIgnore] public bool Valid => Tuppers != null && Groups != null && Tuppers.All(t => t.Valid) && Groups.All(g => g.Valid);
|
|
|
|
|
|
|
|
public TupperboxConversionResult ToPluralKit()
|
|
|
|
{
|
|
|
|
// Set by member conversion function
|
|
|
|
string lastSetTag = null;
|
|
|
|
|
|
|
|
TupperboxConversionResult output = default(TupperboxConversionResult);
|
2019-12-28 14:53:11 +00:00
|
|
|
|
|
|
|
var members = Tuppers.Select(t => t.ToPluralKit(ref lastSetTag, ref output.HadIndividualTags,
|
|
|
|
ref output.HadGroups)).ToList();
|
2019-06-15 09:55:11 +00:00
|
|
|
|
2019-12-28 14:53:11 +00:00
|
|
|
// Nowadays we set each member's display name to their name + tag, so we don't set a global system tag
|
2019-06-15 09:55:11 +00:00
|
|
|
output.System = new DataFileSystem
|
|
|
|
{
|
2019-12-28 14:53:11 +00:00
|
|
|
Members = members,
|
|
|
|
Switches = new List<DataFileSwitch>()
|
2019-06-15 09:55:11 +00:00
|
|
|
};
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct TupperboxTupper
|
|
|
|
{
|
|
|
|
[JsonProperty("name")] public string Name;
|
|
|
|
[JsonProperty("avatar_url")] public string AvatarUrl;
|
2019-10-30 13:11:24 +00:00
|
|
|
[JsonProperty("brackets")] public IList<string> Brackets;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("posts")] public int Posts; // Not supported by PK
|
2019-10-30 13:11:24 +00:00
|
|
|
[JsonProperty("show_brackets")] public bool ShowBrackets;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("birthday")] public string Birthday;
|
|
|
|
[JsonProperty("description")] public string Description;
|
2019-12-28 14:53:11 +00:00
|
|
|
[JsonProperty("tag")] public string Tag;
|
2019-06-15 09:55:11 +00:00
|
|
|
[JsonProperty("group_id")] public string GroupId; // Not supported by PK
|
|
|
|
[JsonProperty("group_pos")] public int? GroupPos; // Not supported by PK
|
|
|
|
|
2020-03-04 18:49:02 +00:00
|
|
|
[JsonIgnore] public bool Valid =>
|
|
|
|
Name != null && Brackets != null && Brackets.Count % 2 == 0 &&
|
|
|
|
(Birthday == null || DateTimeFormats.TimestampExportFormat.Parse(Birthday).Success);
|
2019-06-15 09:55:11 +00:00
|
|
|
|
2019-10-30 13:11:24 +00:00
|
|
|
public DataFileMember ToPluralKit(ref string lastSetTag, ref bool multipleTags, ref bool hasGroup)
|
2019-06-15 09:55:11 +00:00
|
|
|
{
|
|
|
|
// If we've set a tag before and it's not the same as this one,
|
|
|
|
// then we have multiple unique tags and we pass that flag back to the caller
|
|
|
|
if (Tag != null && lastSetTag != null && lastSetTag != Tag) multipleTags = true;
|
|
|
|
lastSetTag = Tag;
|
|
|
|
|
|
|
|
// If this member is in a group, we have a (used) group and we flag that
|
|
|
|
if (GroupId != null) hasGroup = true;
|
|
|
|
|
|
|
|
// Brackets in Tupperbox format are arranged as a single array
|
|
|
|
// [prefix1, suffix1, prefix2, suffix2, prefix3... etc]
|
2019-10-30 13:11:24 +00:00
|
|
|
var tags = new List<ProxyTag>();
|
|
|
|
for (var i = 0; i < Brackets.Count / 2; i++)
|
|
|
|
tags.Add(new ProxyTag(Brackets[i * 2], Brackets[i * 2 + 1]));
|
2019-06-15 09:55:11 +00:00
|
|
|
|
2020-03-04 18:49:02 +00:00
|
|
|
// Convert birthday from ISO timestamp format to ISO date
|
2020-06-21 14:05:04 +00:00
|
|
|
var convertedBirthdate = Birthday != null
|
|
|
|
? LocalDate.FromDateTime(DateTimeFormats.TimestampExportFormat.Parse(Birthday).Value.ToDateTimeUtc())
|
|
|
|
: (LocalDate?) null;
|
2020-03-04 18:49:02 +00:00
|
|
|
|
2019-06-15 09:55:11 +00:00
|
|
|
return new DataFileMember
|
|
|
|
{
|
2019-10-29 07:41:44 +00:00
|
|
|
Id = Guid.NewGuid().ToString(), // Note: this is only ever used for lookup purposes
|
2019-06-15 09:55:11 +00:00
|
|
|
Name = Name,
|
|
|
|
AvatarUrl = AvatarUrl,
|
2020-06-21 14:05:04 +00:00
|
|
|
Birthday = convertedBirthdate?.FormatExport(),
|
2019-06-15 09:55:11 +00:00
|
|
|
Description = Description,
|
2019-10-30 13:11:24 +00:00
|
|
|
ProxyTags = tags,
|
2019-12-28 14:53:11 +00:00
|
|
|
KeepProxy = ShowBrackets,
|
|
|
|
DisplayName = Tag != null ? $"{Name} {Tag}" : null
|
2019-06-15 09:55:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct TupperboxGroup
|
|
|
|
{
|
|
|
|
[JsonProperty("id")] public int Id;
|
|
|
|
[JsonProperty("name")] public string Name;
|
|
|
|
[JsonProperty("description")] public string Description;
|
|
|
|
[JsonProperty("tag")] public string Tag;
|
|
|
|
|
|
|
|
[JsonIgnore] public bool Valid => true;
|
2019-06-14 20:48:19 +00:00
|
|
|
}
|
2020-10-22 20:50:56 +00:00
|
|
|
}
|