👔 Adjust set file permission calls
This commit is contained in:
@@ -20,8 +20,6 @@ public partial class ChatService(
|
|||||||
RemoteWebReaderService webReader
|
RemoteWebReaderService webReader
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
private const string ChatFileUsageIdentifier = "chat";
|
|
||||||
|
|
||||||
[GeneratedRegex(@"https?://(?!.*\.\w{1,6}(?:[#?]|$))[^\s]+", RegexOptions.IgnoreCase)]
|
[GeneratedRegex(@"https?://(?!.*\.\w{1,6}(?:[#?]|$))[^\s]+", RegexOptions.IgnoreCase)]
|
||||||
private static partial Regex GetLinkRegex();
|
private static partial Regex GetLinkRegex();
|
||||||
|
|
||||||
@@ -199,6 +197,9 @@ public partial class ChatService(
|
|||||||
db.ChatMessages.Add(message);
|
db.ChatMessages.Add(message);
|
||||||
await db.SaveChangesAsync();
|
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
|
// Copy the value to ensure the delivery is correct
|
||||||
message.Sender = sender;
|
message.Sender = sender;
|
||||||
message.ChatRoom = room;
|
message.ChatRoom = room;
|
||||||
@@ -647,9 +648,7 @@ public partial class ChatService(
|
|||||||
{
|
{
|
||||||
// Only allow editing regular text messages
|
// Only allow editing regular text messages
|
||||||
if (message.Type != "text")
|
if (message.Type != "text")
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Only regular messages can be edited.");
|
throw new InvalidOperationException("Only regular messages can be edited.");
|
||||||
}
|
|
||||||
|
|
||||||
var isContentChanged = content is not null && content != message.Content;
|
var isContentChanged = content is not null && content != message.Content;
|
||||||
var isAttachmentsChanged = attachmentsId is not null;
|
var isAttachmentsChanged = attachmentsId is not null;
|
||||||
@@ -667,6 +666,10 @@ public partial class ChatService(
|
|||||||
if (isContentChanged || isAttachmentsChanged)
|
if (isContentChanged || isAttachmentsChanged)
|
||||||
message.EditedAt = SystemClock.Instance.GetCurrentInstant();
|
message.EditedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
|
||||||
|
if (isAttachmentsChanged)
|
||||||
|
foreach (var attachment in message.Attachments)
|
||||||
|
await filesClient.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
|
||||||
|
|
||||||
db.Update(message);
|
db.Update(message);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ public partial class PostService(
|
|||||||
ActivityPubObjectFactory objFactory
|
ActivityPubObjectFactory objFactory
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
private const string PostFileUsageIdentifier = "post";
|
|
||||||
|
|
||||||
private static List<SnPost> TruncatePostContent(List<SnPost> input)
|
private static List<SnPost> TruncatePostContent(List<SnPost> input)
|
||||||
{
|
{
|
||||||
const int maxLength = 256;
|
const int maxLength = 256;
|
||||||
@@ -164,13 +162,8 @@ public partial class PostService(
|
|||||||
.Select(id => post.Attachments.First(a => a.Id == id))
|
.Select(id => post.Attachments.First(a => a.Id == id))
|
||||||
.ToList();
|
.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)
|
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.");
|
throw new InvalidOperationException("Categories contains one or more categories that wasn't exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldVisibility = post.Visibility;
|
|
||||||
db.Update(post);
|
db.Update(post);
|
||||||
await db.SaveChangesAsync();
|
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 });
|
||||||
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 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process link preview in the background to avoid delaying post update
|
// Process link preview in the background to avoid delaying post update
|
||||||
_ = Task.Run(async () => await CreateLinkPreviewAsync(post));
|
_ = Task.Run(async () => await CreateLinkPreviewAsync(post));
|
||||||
|
|
||||||
// Send ActivityPub Update activity in background for public posts
|
// Send ActivityPub Update activity in background for public posts
|
||||||
if (post.Visibility == Shared.Models.PostVisibility.Public)
|
if (post.Visibility == Shared.Models.PostVisibility.Public)
|
||||||
{
|
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -372,7 +351,6 @@ public partial class PostService(
|
|||||||
logger.LogError($"Error when sending ActivityPub Update activity: {err.Message}");
|
logger.LogError($"Error when sending ActivityPub Update activity: {err.Message}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user