fix message edit embed, ignore pk;edit triggers
This commit is contained in:
parent
8231c57bdf
commit
7ea945b427
6 changed files with 63 additions and 15 deletions
|
|
@ -36,7 +36,12 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
|||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task UpdateMessageAsync(IMessageCreate msg, CancellationToken ct = default)
|
||||
/// <summary>
|
||||
/// Updates an edited message.
|
||||
/// </summary>
|
||||
/// <returns>true if the message was already stored and got updated,
|
||||
/// false if the message wasn't stored and was newly inserted.</returns>
|
||||
public async Task<bool> UpdateMessageAsync(IMessageCreate msg, CancellationToken ct = default)
|
||||
{
|
||||
_logger.Debug("Updating message {MessageId}", msg.ID);
|
||||
|
||||
|
|
@ -44,13 +49,16 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
|||
var (isStored, _) = await HasProxyInfoAsync(msg.ID.Value);
|
||||
if (!isStored)
|
||||
{
|
||||
_logger.Debug("Edited message {MessageId} is not stored yet, storing it", msg.ID);
|
||||
await SaveMessageAsync(msg, ct);
|
||||
await tx.CommitAsync(ct);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var metadata = new Metadata(IsWebhook: msg.WebhookID.HasValue,
|
||||
msg.Attachments.Select(a => new Attachment(a.Filename, a.Size, a.ContentType.Value)));
|
||||
|
||||
|
||||
var dbMsg = await db.Messages.FindAsync(msg.ID.Value);
|
||||
if (dbMsg == null) throw new CataloggerError("Message was null despite HasProxyInfoAsync returning true");
|
||||
|
||||
|
|
@ -62,9 +70,9 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
|||
|
||||
db.Update(dbMsg);
|
||||
await db.SaveChangesAsync(ct);
|
||||
await tx.CommitAsync(ct);
|
||||
return true;
|
||||
}
|
||||
|
||||
await tx.CommitAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<Message?> GetMessageAsync(ulong id, CancellationToken ct = default)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue