[backend/federation] Fix remote custom emoji reactions (ISH-154)

This commit is contained in:
Laura Hausmann 2024-03-11 03:04:32 +01:00
parent 58a514394c
commit 4d21aa1670
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 11 additions and 10 deletions

View file

@ -51,13 +51,14 @@ public class ActivityDeliverService(
{ {
if (note.Visibility != Note.NoteVisibility.Specified) if (note.Visibility != Note.NoteVisibility.Specified)
{ {
await DeliverToFollowersAsync(activity, actor, [note.User]); await DeliverToFollowersAsync(activity, actor, note.User.Host == null ? [] : [note.User]);
return; return;
} }
await DeliverToAsync(activity, actor, await db.Users.Where(p => note.VisibleUserIds var recipients = await db.Users
.Prepend(note.User.Id) .Where(p => note.VisibleUserIds.Prepend(note.User.Id).Contains(p.Id) && p.Host != null)
.Contains(p.Id)) .ToArrayAsync();
.ToArrayAsync());
await DeliverToAsync(activity, actor, recipients);
} }
} }

View file

@ -76,8 +76,6 @@ public class ActivityRenderer(
public ASEmojiReact RenderReact(NoteReaction reaction, Emoji? emoji) public ASEmojiReact RenderReact(NoteReaction reaction, Emoji? emoji)
{ {
if (reaction.Note.UserHost == null)
throw GracefulException.BadRequest("Refusing to render like activity: note user must be remote");
if (reaction.User.Host != null) if (reaction.User.Host != null)
throw GracefulException.BadRequest("Refusing to render like activity: actor must be local"); throw GracefulException.BadRequest("Refusing to render like activity: actor must be local");
@ -91,9 +89,11 @@ public class ActivityRenderer(
if (emoji != null) if (emoji != null)
{ {
var name = emoji.Host == null ? emoji.Name : $"{emoji.Name}@{emoji.Host}";
var e = new ASEmoji var e = new ASEmoji
{ {
Id = emoji.PublicUrl, Name = emoji.Name, Image = new ASImage { Url = new ASLink(emoji.PublicUrl) } Id = emoji.PublicUrl, Name = name, Image = new ASImage { Url = new ASLink(emoji.PublicUrl) }
}; };
res.Tags = [e]; res.Tags = [e];

View file

@ -1184,7 +1184,7 @@ public class NoteService(
await db.Database await db.Database
.ExecuteSqlAsync($"""UPDATE "note" SET "reactions" = jsonb_set("reactions", ARRAY[{name}], (COALESCE("reactions"->>{name}, '0')::int + 1)::text::jsonb) WHERE "id" = {note.Id}"""); .ExecuteSqlAsync($"""UPDATE "note" SET "reactions" = jsonb_set("reactions", ARRAY[{name}], (COALESCE("reactions"->>{name}, '0')::int + 1)::text::jsonb) WHERE "id" = {note.Id}""");
if (user.Host == null && note.User.Host != null) if (user.Host == null)
{ {
var emoji = await emojiSvc.ResolveEmoji(reaction.Reaction); var emoji = await emojiSvc.ResolveEmoji(reaction.Reaction);
var activity = activityRenderer.RenderReact(reaction, emoji); var activity = activityRenderer.RenderReact(reaction, emoji);
@ -1218,7 +1218,7 @@ public class NoteService(
await db.Database await db.Database
.ExecuteSqlAsync($"""UPDATE "note" SET "reactions" = jsonb_set("reactions", ARRAY[{name}], (COALESCE("reactions"->>{name}, '1')::int - 1)::text::jsonb) WHERE "id" = {note.Id}"""); .ExecuteSqlAsync($"""UPDATE "note" SET "reactions" = jsonb_set("reactions", ARRAY[{name}], (COALESCE("reactions"->>{name}, '1')::int - 1)::text::jsonb) WHERE "id" = {note.Id}""");
if (user.Host == null && note.User.Host != null) if (user.Host == null)
{ {
var actor = userRenderer.RenderLite(user); var actor = userRenderer.RenderLite(user);
var emoji = await emojiSvc.ResolveEmoji(reaction.Reaction); var emoji = await emojiSvc.ResolveEmoji(reaction.Reaction);