👔 Adjust set file permission calls

This commit is contained in:
2026-01-13 19:30:43 +08:00
parent 69736f0850
commit 979e0cb3f2
2 changed files with 11 additions and 30 deletions

View File

@@ -20,8 +20,6 @@ public partial class ChatService(
RemoteWebReaderService webReader
)
{
private const string ChatFileUsageIdentifier = "chat";
[GeneratedRegex(@"https?://(?!.*\.\w{1,6}(?:[#?]|$))[^\s]+", RegexOptions.IgnoreCase)]
private static partial Regex GetLinkRegex();
@@ -199,6 +197,9 @@ public partial class ChatService(
db.ChatMessages.Add(message);
await db.SaveChangesAsync();
foreach (var attachment in message.Attachments)
await filesClient.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
// Copy the value to ensure the delivery is correct
message.Sender = sender;
message.ChatRoom = room;
@@ -647,9 +648,7 @@ public partial class ChatService(
{
// Only allow editing regular text messages
if (message.Type != "text")
{
throw new InvalidOperationException("Only regular messages can be edited.");
}
var isContentChanged = content is not null && content != message.Content;
var isAttachmentsChanged = attachmentsId is not null;
@@ -667,6 +666,10 @@ public partial class ChatService(
if (isContentChanged || isAttachmentsChanged)
message.EditedAt = SystemClock.Instance.GetCurrentInstant();
if (isAttachmentsChanged)
foreach (var attachment in message.Attachments)
await filesClient.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
db.Update(message);
await db.SaveChangesAsync();