[backend/federation] Deliver activities to mentioned users

This commit is contained in:
Laura Hausmann 2024-02-12 05:05:00 +01:00
parent 1d090c8400
commit c5d773e46a
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 16 additions and 3 deletions

View file

@ -14,7 +14,7 @@ public class ActivityDeliverService(
DatabaseContext db,
QueueService queueService
) {
public async Task DeliverToFollowersAsync(ASActivity activity, User actor) {
public async Task DeliverToFollowersAsync(ASActivity activity, User actor, IEnumerable<User> recipients) {
logger.LogDebug("Delivering activity {id} to followers", activity.Id);
if (activity.Actor == null) throw new Exception("Actor must not be null");
@ -25,6 +25,11 @@ public class ActivityDeliverService(
.Distinct()
.ToListAsync();
inboxUrls = inboxUrls
.Concat(recipients.Select(p => p.SharedInbox ?? p.Inbox).Where(p => p != null).Select(p => p!))
.Distinct()
.ToList();
if (inboxUrls.Count == 0) return;
var keypair = await db.UserKeypairs.FirstAsync(p => p.User == actor);

View file

@ -76,12 +76,20 @@ public class NoteService(
var obj = await noteRenderer.RenderAsync(note, mentions);
var activity = ActivityRenderer.RenderCreate(obj, actor);
var recipients = await db.Users
.Where(p => note.VisibleUserIds.Contains(p.Id))
.Select(p => new User {
Host = p.Host,
Inbox = p.Inbox,
SharedInbox = p.SharedInbox
})
.ToListAsync();
if (note.Visibility == Note.NoteVisibility.Specified) {
var recipients = await db.Users.Where(p => note.VisibleUserIds.Contains(p.Id)).ToListAsync();
await deliverSvc.DeliverToAsync(activity, user, recipients);
}
else {
await deliverSvc.DeliverToFollowersAsync(activity, user);
await deliverSvc.DeliverToFollowersAsync(activity, user, recipients);
}
return note;