mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 06:17:55 +00:00
feat(webhooks): SUCCESSFUL_IMPORT event, better behaviour when creating entities
This commit is contained in:
parent
a05c3cfeed
commit
bc7e0df872
11 changed files with 73 additions and 27 deletions
|
|
@ -64,11 +64,6 @@ namespace PluralKit.Core
|
|||
name = name
|
||||
});
|
||||
var group = await _db.QueryFirst<PKGroup>(conn, query, extraSql: "returning *");
|
||||
_ = _dispatch.Dispatch(group.Id, new UpdateDispatchData()
|
||||
{
|
||||
Event = DispatchEvent.CREATE_GROUP,
|
||||
EventData = JObject.FromObject(new { name = name }),
|
||||
});
|
||||
_logger.Information("Created group {GroupId} in system {SystemId}: {GroupName}", group.Id, system, name);
|
||||
return group;
|
||||
}
|
||||
|
|
@ -78,11 +73,13 @@ namespace PluralKit.Core
|
|||
_logger.Information("Updated {GroupId}: {@GroupPatch}", id, patch);
|
||||
var query = patch.Apply(new Query("groups").Where("id", id));
|
||||
var group = await _db.QueryFirst<PKGroup>(conn, query, extraSql: "returning *");
|
||||
_ = _dispatch.Dispatch(id, new()
|
||||
{
|
||||
Event = DispatchEvent.UPDATE_GROUP,
|
||||
EventData = patch.ToJson(),
|
||||
});
|
||||
|
||||
if (conn == null)
|
||||
_ = _dispatch.Dispatch(id, new()
|
||||
{
|
||||
Event = DispatchEvent.UPDATE_GROUP,
|
||||
EventData = patch.ToJson(),
|
||||
});
|
||||
return group;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,11 +69,6 @@ namespace PluralKit.Core
|
|||
var member = await _db.QueryFirst<PKMember>(conn, query, "returning *");
|
||||
_logger.Information("Created {MemberId} in {SystemId}: {MemberName}",
|
||||
member.Id, systemId, memberName);
|
||||
_ = _dispatch.Dispatch(member.Id, new()
|
||||
{
|
||||
Event = DispatchEvent.CREATE_MEMBER,
|
||||
EventData = JObject.FromObject(new { name = memberName }),
|
||||
});
|
||||
return member;
|
||||
}
|
||||
|
||||
|
|
@ -81,11 +76,13 @@ namespace PluralKit.Core
|
|||
{
|
||||
_logger.Information("Updated {MemberId}: {@MemberPatch}", id, patch);
|
||||
var query = patch.Apply(new Query("members").Where("id", id));
|
||||
_ = _dispatch.Dispatch(id, new()
|
||||
{
|
||||
Event = DispatchEvent.UPDATE_MEMBER,
|
||||
EventData = patch.ToJson(),
|
||||
});
|
||||
|
||||
if (conn == null)
|
||||
_ = _dispatch.Dispatch(id, new()
|
||||
{
|
||||
Event = DispatchEvent.UPDATE_MEMBER,
|
||||
EventData = patch.ToJson(),
|
||||
});
|
||||
return _db.QueryFirst<PKMember>(conn, query, extraSql: "returning *");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace PluralKit.Core
|
|||
UPDATE_SWITCH_MEMBERS,
|
||||
DELETE_SWITCH,
|
||||
DELETE_ALL_SWITCHES,
|
||||
SUCCESSFUL_IMPORT,
|
||||
}
|
||||
|
||||
public struct UpdateDispatchData
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ namespace PluralKit.Core
|
|||
private readonly IDatabase _db;
|
||||
private readonly ModelRepository _repo;
|
||||
private readonly ILogger _logger;
|
||||
private readonly DispatchService _dispatch;
|
||||
|
||||
public DataFileService(IDatabase db, ModelRepository repo, ILogger logger)
|
||||
public DataFileService(IDatabase db, ModelRepository repo, ILogger logger, DispatchService dispatch)
|
||||
{
|
||||
_db = db;
|
||||
_repo = repo;
|
||||
_logger = logger;
|
||||
_dispatch = dispatch;
|
||||
}
|
||||
|
||||
public async Task<JObject> ExportSystem(PKSystem system)
|
||||
|
|
@ -72,7 +74,7 @@ namespace PluralKit.Core
|
|||
await using var conn = await _db.Obtain();
|
||||
await using var tx = await conn.BeginTransactionAsync();
|
||||
|
||||
return await BulkImporter.PerformImport(conn, tx, _repo, _logger, userId, system, importFile, confirmFunc);
|
||||
return await BulkImporter.PerformImport(conn, tx, _repo, _logger, _dispatch, userId, system, importFile, confirmFunc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace PluralKit.Core
|
|||
private ImportResultNew _result = new();
|
||||
|
||||
internal static async Task<ImportResultNew> PerformImport(IPKConnection conn, IPKTransaction tx, ModelRepository repo, ILogger logger,
|
||||
ulong userId, PKSystem? system, JObject importFile, Func<string, Task> confirmFunc)
|
||||
DispatchService dispatch, ulong userId, PKSystem? system, JObject importFile, Func<string, Task> confirmFunc)
|
||||
{
|
||||
await using var importer = new BulkImporter()
|
||||
{
|
||||
|
|
@ -82,6 +82,11 @@ namespace PluralKit.Core
|
|||
throw new ImportException("File type is unknown.");
|
||||
importer._result.Success = true;
|
||||
await tx.CommitAsync();
|
||||
|
||||
_ = dispatch.Dispatch(system.Id, new UpdateDispatchData()
|
||||
{
|
||||
Event = DispatchEvent.SUCCESSFUL_IMPORT
|
||||
});
|
||||
}
|
||||
catch (ImportException e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue