👔 Adjust set file permission calls
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ public partial class PostService(
|
||||
ActivityPubObjectFactory objFactory
|
||||
)
|
||||
{
|
||||
private const string PostFileUsageIdentifier = "post";
|
||||
|
||||
private static List<SnPost> TruncatePostContent(List<SnPost> input)
|
||||
{
|
||||
const int maxLength = 256;
|
||||
@@ -164,13 +162,8 @@ public partial class PostService(
|
||||
.Select(id => post.Attachments.First(a => a.Id == id))
|
||||
.ToList();
|
||||
|
||||
if (post.Visibility == Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
foreach (var attachment in post.Attachments)
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
|
||||
if (tags is not null)
|
||||
@@ -334,31 +327,17 @@ public partial class PostService(
|
||||
throw new InvalidOperationException("Categories contains one or more categories that wasn't exists.");
|
||||
}
|
||||
|
||||
var oldVisibility = post.Visibility;
|
||||
db.Update(post);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
if (post.Visibility == Shared.Models.PostVisibility.Public && oldVisibility != Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
else if (oldVisibility == Shared.Models.PostVisibility.Public && post.Visibility != Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
foreach (var attachment in post.Attachments)
|
||||
{
|
||||
await files.UnsetFilePublicAsync(new UnsetFilePublicRequest { FileId = attachment.Id });
|
||||
}
|
||||
}
|
||||
foreach (var attachment in post.Attachments)
|
||||
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||
|
||||
// Process link preview in the background to avoid delaying post update
|
||||
_ = Task.Run(async () => await CreateLinkPreviewAsync(post));
|
||||
|
||||
// Send ActivityPub Update activity in background for public posts
|
||||
if (post.Visibility == Shared.Models.PostVisibility.Public)
|
||||
{
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -372,7 +351,6 @@ public partial class PostService(
|
||||
logger.LogError($"Error when sending ActivityPub Update activity: {err.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return post;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user