[backend/services] Set denormalized note properties replyUserId and replyuserHost correctly
This commit is contained in:
parent
7fcf9a5179
commit
0d5f987a8d
2 changed files with 26 additions and 14 deletions
|
@ -130,7 +130,7 @@ public class StatusController(
|
|||
if (idempotencyKey != null) {
|
||||
var hit = await cache.FetchAsync($"idempotency:{idempotencyKey}", TimeSpan.FromHours(24),
|
||||
() => $"_:{HttpContext.TraceIdentifier}");
|
||||
|
||||
|
||||
if (hit != $"_:{HttpContext.TraceIdentifier}") {
|
||||
for (var i = 0; i <= 10; i++) {
|
||||
if (!hit.StartsWith('_')) break;
|
||||
|
@ -153,8 +153,11 @@ public class StatusController(
|
|||
|
||||
var visibility = StatusEntity.DecodeVisibility(request.Visibility);
|
||||
var reply = request.ReplyId != null
|
||||
? await db.Notes.Where(p => p.Id == request.ReplyId).EnsureVisibleFor(user).FirstOrDefaultAsync() ??
|
||||
throw GracefulException.BadRequest("Reply target is nonexistent or inaccessible")
|
||||
? await db.Notes.Where(p => p.Id == request.ReplyId)
|
||||
.IncludeCommonProperties()
|
||||
.EnsureVisibleFor(user)
|
||||
.FirstOrDefaultAsync()
|
||||
?? throw GracefulException.BadRequest("Reply target is nonexistent or inaccessible")
|
||||
: null;
|
||||
|
||||
var attachments = request.MediaIds != null
|
||||
|
@ -163,7 +166,7 @@ public class StatusController(
|
|||
|
||||
var note = await noteSvc.CreateNoteAsync(user, visibility, request.Text, request.Cw, reply,
|
||||
attachments: attachments);
|
||||
|
||||
|
||||
if (idempotencyKey != null)
|
||||
await cache.SetAsync($"idempotency:{idempotencyKey}", note.Id, TimeSpan.FromHours(24));
|
||||
|
||||
|
|
|
@ -65,15 +65,19 @@ public class NoteService(
|
|||
var actor = await userRenderer.RenderAsync(user);
|
||||
|
||||
var note = new Note {
|
||||
Id = IdHelpers.GenerateSlowflakeId(),
|
||||
Text = text,
|
||||
Cw = cw,
|
||||
Reply = reply,
|
||||
Renote = renote,
|
||||
UserId = user.Id,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UserHost = null,
|
||||
Visibility = visibility,
|
||||
Id = IdHelpers.GenerateSlowflakeId(),
|
||||
Text = text,
|
||||
Cw = cw,
|
||||
Reply = reply,
|
||||
ReplyUserId = reply?.UserId,
|
||||
ReplyUserHost = reply?.UserHost,
|
||||
Renote = renote,
|
||||
RenoteUserId = renote?.UserId,
|
||||
RenoteUserHost = renote?.UserHost,
|
||||
UserId = user.Id,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UserHost = null,
|
||||
Visibility = visibility,
|
||||
|
||||
FileIds = attachments?.Select(p => p.Id).ToList() ?? [],
|
||||
AttachedFileTypes = attachments?.Select(p => p.Type).ToList() ?? [],
|
||||
|
@ -182,9 +186,14 @@ public class NoteService(
|
|||
CreatedAt = createdAt,
|
||||
UserHost = user.Host,
|
||||
Visibility = note.GetVisibility(actor),
|
||||
Reply = note.InReplyTo?.Id != null ? await ResolveNoteAsync(note.InReplyTo.Id) : null
|
||||
Reply = note.InReplyTo?.Id != null ? await ResolveNoteAsync(note.InReplyTo.Id) : null,
|
||||
};
|
||||
|
||||
if (dbNote.Reply != null) {
|
||||
dbNote.ReplyUserId = dbNote.Reply.UserId;
|
||||
dbNote.ReplyUserHost = dbNote.Reply.UserHost;
|
||||
}
|
||||
|
||||
if (dbNote.Text is { Length: > 100000 })
|
||||
throw GracefulException.UnprocessableEntity("Content cannot be longer than 100.000 characters");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue