[backend/masto-client] Add & populate MastoReplyUserId column (ISH-247)

This commit is contained in:
Laura Hausmann 2024-04-07 21:01:16 +02:00
parent 969622bfc7
commit 22a4de63f3
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
8 changed files with 6181 additions and 32 deletions

View file

@ -97,7 +97,8 @@ public class NoteRenderer(
Url = note.Url ?? uri, Url = note.Url ?? uri,
Account = account, Account = account,
ReplyId = note.ReplyId, ReplyId = note.ReplyId,
ReplyUserId = note.ReplyUserId, ReplyUserId = note.MastoReplyUserId ?? note.ReplyUserId,
MastoReplyUserId = note.MastoReplyUserId,
Renote = renote, Renote = renote,
Quote = quote, Quote = quote,
ContentType = "text/x.misskeymarkdown", ContentType = "text/x.misskeymarkdown",
@ -275,7 +276,8 @@ public class NoteRenderer(
} }
public async Task<IEnumerable<StatusEntity>> RenderManyAsync( public async Task<IEnumerable<StatusEntity>> RenderManyAsync(
IEnumerable<Note> notes, User? user, Filter.FilterContext? filterContext = null, List<AccountEntity>? accounts = null IEnumerable<Note> notes, User? user, Filter.FilterContext? filterContext = null,
List<AccountEntity>? accounts = null
) )
{ {
var noteList = notes.SelectMany<Note, Note?>(p => [p, p.Renote]) var noteList = notes.SelectMany<Note, Note?>(p => [p, p.Renote])

View file

@ -54,6 +54,8 @@ public class StatusEntity : IEntity
[J("language")] public string? Language => null; //FIXME [J("language")] public string? Language => null; //FIXME
[J("id")] public required string Id { get; set; } [J("id")] public required string Id { get; set; }
[JI] public string? MastoReplyUserId;
public static string EncodeVisibility(Note.NoteVisibility visibility) public static string EncodeVisibility(Note.NoteVisibility visibility)
{ {
return visibility switch return visibility switch

View file

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
public partial class AddNoteMastoReplyUserIdColumn : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "mastoReplyUserId",
table: "note",
type: "character varying(32)",
maxLength: 32,
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "mastoReplyUserId",
table: "note");
}
}
}

View file

@ -2369,6 +2369,11 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasDefaultValue(false) .HasDefaultValue(false)
.HasColumnName("localOnly"); .HasColumnName("localOnly");
b.Property<string>("MastoReplyUserId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("mastoReplyUserId");
b.Property<List<Note.MentionedUser>>("MentionedRemoteUsers") b.Property<List<Note.MentionedUser>>("MentionedRemoteUsers")
.IsRequired() .IsRequired()
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()

View file

@ -137,6 +137,13 @@ public class Note : IEntity
[StringLength(32)] [StringLength(32)]
public string? ReplyUserId { get; set; } public string? ReplyUserId { get; set; }
/// <summary>
/// Mastodon requires a slightly differently computed replyUserId field. To save processing time, we do this ahead of time.
/// </summary>
[Column("mastoReplyUserId")]
[StringLength(32)]
public string? MastoReplyUserId { get; set; }
/// <summary> /// <summary>
/// [Denormalized] /// [Denormalized]
/// </summary> /// </summary>

View file

@ -49,7 +49,7 @@ public static class NoteThreadHelpers
parent.Descendants.Add(node); parent.Descendants.Add(node);
node.Parent = parent; node.Parent = parent;
if (parent.Self.Account.Id == node.Self.Account.Id) if (parent.Self.Account.Id == node.Self.Account.Id)
node.Self.ReplyUserId = parent.Self.ReplyUserId ?? parent.Self.Account.Id; node.Self.ReplyUserId = node.Self.MastoReplyUserId ?? parent.Self.ReplyUserId ?? parent.Self.Account.Id;
} }
foreach (var note in nodes.Where(p => p.Descendants.Count > 0)) foreach (var note in nodes.Where(p => p.Descendants.Count > 0))

View file

@ -121,6 +121,10 @@ public class NoteService(
var tags = ResolveHashtags(text); var tags = ResolveHashtags(text);
var mastoReplyUserId = reply?.UserId != user.Id
? reply?.UserId
: reply.MastoReplyUserId ?? reply.ReplyUserId ?? reply.UserId;
var note = new Note var note = new Note
{ {
Id = IdHelpers.GenerateSlowflakeId(), Id = IdHelpers.GenerateSlowflakeId(),
@ -128,6 +132,7 @@ public class NoteService(
Cw = cw?.Trim(), Cw = cw?.Trim(),
Reply = reply, Reply = reply,
ReplyUserId = reply?.UserId, ReplyUserId = reply?.UserId,
MastoReplyUserId = mastoReplyUserId,
ReplyUserHost = reply?.UserHost, ReplyUserHost = reply?.UserHost,
Renote = renote, Renote = renote,
RenoteUserId = renote?.UserId, RenoteUserId = renote?.UserId,
@ -614,6 +619,10 @@ public class NoteService(
dbNote.ReplyUserId = dbNote.Reply.UserId; dbNote.ReplyUserId = dbNote.Reply.UserId;
dbNote.ReplyUserHost = dbNote.Reply.UserHost; dbNote.ReplyUserHost = dbNote.Reply.UserHost;
dbNote.ThreadId = dbNote.Reply.ThreadId ?? dbNote.Reply.Id; dbNote.ThreadId = dbNote.Reply.ThreadId ?? dbNote.Reply.Id;
dbNote.MastoReplyUserId = dbNote.Reply.UserId != actor.Id
? dbNote.Reply.UserId
: dbNote.Reply.MastoReplyUserId ?? dbNote.Reply.ReplyUserId ?? dbNote.Reply.UserId;
} }
if (dbNote.Renote != null) if (dbNote.Renote != null)