Following lists are public; followers are visible to the user and to mutual followers.
Adds GET /users/{id}/followers and /following, exposes isFollowing and canViewFollowers
on the profile, and returns isFollowedByViewer from user search so the web player no
longer calls /is-following per user.
31 lines
865 B
C#
31 lines
865 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Musify.Application.Contracts;
|
|
|
|
namespace Musify.Application.Users
|
|
{
|
|
public static class FollowVisibility
|
|
{
|
|
public static async Task<bool> CanViewFollowersAsync(
|
|
IDatabase database,
|
|
long? viewerId,
|
|
long userId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (viewerId is not { } viewer)
|
|
return false;
|
|
|
|
if (viewer == userId)
|
|
return true;
|
|
|
|
var mutualRows = await database.UserFollows
|
|
.AsNoTracking()
|
|
.CountAsync(f =>
|
|
(f.FollowerId == viewer && f.FollowedId == userId) ||
|
|
(f.FollowerId == userId && f.FollowedId == viewer),
|
|
cancellationToken);
|
|
|
|
return mutualRows == 2;
|
|
}
|
|
}
|
|
}
|