| 123456789101112131415161718192021222324252627282930313233 |
- using Application.Abstractions.Hub;
- using Microsoft.AspNetCore.SignalR;
- namespace Infrastructure.Hubs;
- internal sealed class FeedBroadcaster(IHubContext<AppHub, IAppHubClient>? hub = null) : IFeedBroadcaster
- {
- public async Task BroadcastNewPostAsync(IEnumerable<int> followerMemberIDs, FeedPostToast toast, CancellationToken ct = default)
- {
- if (hub is null)
- {
- return;
- }
- var groups = followerMemberIDs.Select(id => $"member:{id}").ToList();
- if (groups.Count == 0)
- {
- return;
- }
- await hub.Clients.Groups(groups).ReceiveFeedPost(new
- {
- toast.PostID,
- toast.AuthorSID,
- toast.AuthorName,
- toast.AuthorThumb,
- toast.Subject,
- toast.Thumbnail,
- toast.CreatedAt
- });
- }
- }
|