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