fix message edit embed, ignore pk;edit triggers

This commit is contained in:
sam 2024-08-16 17:03:26 +02:00
parent 8231c57bdf
commit 7ea945b427
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
6 changed files with 63 additions and 15 deletions

View file

@ -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)