[backend/masto-client] Add & populate MastoReplyUserId column (ISH-247)
This commit is contained in:
parent
969622bfc7
commit
22a4de63f3
8 changed files with 6181 additions and 32 deletions
|
@ -92,36 +92,37 @@ public class NoteRenderer(
|
|||
|
||||
var res = new StatusEntity
|
||||
{
|
||||
Id = note.Id,
|
||||
Uri = uri,
|
||||
Url = note.Url ?? uri,
|
||||
Account = account,
|
||||
ReplyId = note.ReplyId,
|
||||
ReplyUserId = note.ReplyUserId,
|
||||
Renote = renote,
|
||||
Quote = quote,
|
||||
ContentType = "text/x.misskeymarkdown",
|
||||
CreatedAt = note.CreatedAt.ToStringIso8601Like(),
|
||||
EditedAt = note.UpdatedAt?.ToStringIso8601Like(),
|
||||
RepliesCount = note.RepliesCount,
|
||||
RenoteCount = note.RenoteCount,
|
||||
FavoriteCount = note.LikeCount,
|
||||
IsFavorited = liked,
|
||||
IsRenoted = renoted,
|
||||
IsBookmarked = bookmarked,
|
||||
IsMuted = null, //FIXME
|
||||
IsSensitive = note.Cw != null,
|
||||
ContentWarning = note.Cw ?? "",
|
||||
Visibility = StatusEntity.EncodeVisibility(note.Visibility),
|
||||
Content = content,
|
||||
Text = data?.Source == true ? text : null,
|
||||
Mentions = mentions,
|
||||
IsPinned = pinned,
|
||||
Attachments = attachments,
|
||||
Emojis = noteEmoji,
|
||||
Poll = poll,
|
||||
Reactions = reactions,
|
||||
Filtered = filterResult
|
||||
Id = note.Id,
|
||||
Uri = uri,
|
||||
Url = note.Url ?? uri,
|
||||
Account = account,
|
||||
ReplyId = note.ReplyId,
|
||||
ReplyUserId = note.MastoReplyUserId ?? note.ReplyUserId,
|
||||
MastoReplyUserId = note.MastoReplyUserId,
|
||||
Renote = renote,
|
||||
Quote = quote,
|
||||
ContentType = "text/x.misskeymarkdown",
|
||||
CreatedAt = note.CreatedAt.ToStringIso8601Like(),
|
||||
EditedAt = note.UpdatedAt?.ToStringIso8601Like(),
|
||||
RepliesCount = note.RepliesCount,
|
||||
RenoteCount = note.RenoteCount,
|
||||
FavoriteCount = note.LikeCount,
|
||||
IsFavorited = liked,
|
||||
IsRenoted = renoted,
|
||||
IsBookmarked = bookmarked,
|
||||
IsMuted = null, //FIXME
|
||||
IsSensitive = note.Cw != null,
|
||||
ContentWarning = note.Cw ?? "",
|
||||
Visibility = StatusEntity.EncodeVisibility(note.Visibility),
|
||||
Content = content,
|
||||
Text = data?.Source == true ? text : null,
|
||||
Mentions = mentions,
|
||||
IsPinned = pinned,
|
||||
Attachments = attachments,
|
||||
Emojis = noteEmoji,
|
||||
Poll = poll,
|
||||
Reactions = reactions,
|
||||
Filtered = filterResult
|
||||
};
|
||||
|
||||
return res;
|
||||
|
@ -275,7 +276,8 @@ public class NoteRenderer(
|
|||
}
|
||||
|
||||
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])
|
||||
|
|
|
@ -54,6 +54,8 @@ public class StatusEntity : IEntity
|
|||
[J("language")] public string? Language => null; //FIXME
|
||||
[J("id")] public required string Id { get; set; }
|
||||
|
||||
[JI] public string? MastoReplyUserId;
|
||||
|
||||
public static string EncodeVisibility(Note.NoteVisibility visibility)
|
||||
{
|
||||
return visibility switch
|
||||
|
|
6095
Iceshrimp.Backend/Core/Database/Migrations/20240407190040_AddNoteMastoReplyUserIdColumn.Designer.cs
generated
Normal file
6095
Iceshrimp.Backend/Core/Database/Migrations/20240407190040_AddNoteMastoReplyUserIdColumn.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2369,6 +2369,11 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
.HasDefaultValue(false)
|
||||
.HasColumnName("localOnly");
|
||||
|
||||
b.Property<string>("MastoReplyUserId")
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("mastoReplyUserId");
|
||||
|
||||
b.Property<List<Note.MentionedUser>>("MentionedRemoteUsers")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
|
|
|
@ -137,6 +137,13 @@ public class Note : IEntity
|
|||
[StringLength(32)]
|
||||
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>
|
||||
/// [Denormalized]
|
||||
/// </summary>
|
||||
|
|
|
@ -49,7 +49,7 @@ public static class NoteThreadHelpers
|
|||
parent.Descendants.Add(node);
|
||||
node.Parent = parent;
|
||||
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))
|
||||
|
|
|
@ -121,6 +121,10 @@ public class NoteService(
|
|||
|
||||
var tags = ResolveHashtags(text);
|
||||
|
||||
var mastoReplyUserId = reply?.UserId != user.Id
|
||||
? reply?.UserId
|
||||
: reply.MastoReplyUserId ?? reply.ReplyUserId ?? reply.UserId;
|
||||
|
||||
var note = new Note
|
||||
{
|
||||
Id = IdHelpers.GenerateSlowflakeId(),
|
||||
|
@ -128,6 +132,7 @@ public class NoteService(
|
|||
Cw = cw?.Trim(),
|
||||
Reply = reply,
|
||||
ReplyUserId = reply?.UserId,
|
||||
MastoReplyUserId = mastoReplyUserId,
|
||||
ReplyUserHost = reply?.UserHost,
|
||||
Renote = renote,
|
||||
RenoteUserId = renote?.UserId,
|
||||
|
@ -614,6 +619,10 @@ public class NoteService(
|
|||
dbNote.ReplyUserId = dbNote.Reply.UserId;
|
||||
dbNote.ReplyUserHost = dbNote.Reply.UserHost;
|
||||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue