[backend/federation] Deliver activities to mentioned users
This commit is contained in:
parent
1d090c8400
commit
c5d773e46a
2 changed files with 16 additions and 3 deletions
|
@ -14,7 +14,7 @@ public class ActivityDeliverService(
|
||||||
DatabaseContext db,
|
DatabaseContext db,
|
||||||
QueueService queueService
|
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);
|
logger.LogDebug("Delivering activity {id} to followers", activity.Id);
|
||||||
if (activity.Actor == null) throw new Exception("Actor must not be null");
|
if (activity.Actor == null) throw new Exception("Actor must not be null");
|
||||||
|
|
||||||
|
@ -25,6 +25,11 @@ public class ActivityDeliverService(
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToListAsync();
|
.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;
|
if (inboxUrls.Count == 0) return;
|
||||||
|
|
||||||
var keypair = await db.UserKeypairs.FirstAsync(p => p.User == actor);
|
var keypair = await db.UserKeypairs.FirstAsync(p => p.User == actor);
|
||||||
|
|
|
@ -76,12 +76,20 @@ public class NoteService(
|
||||||
var obj = await noteRenderer.RenderAsync(note, mentions);
|
var obj = await noteRenderer.RenderAsync(note, mentions);
|
||||||
var activity = ActivityRenderer.RenderCreate(obj, actor);
|
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) {
|
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);
|
await deliverSvc.DeliverToAsync(activity, user, recipients);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await deliverSvc.DeliverToFollowersAsync(activity, user);
|
await deliverSvc.DeliverToFollowersAsync(activity, user, recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
return note;
|
return note;
|
||||||
|
|
Loading…
Add table
Reference in a new issue