.NET 10 solution for Ping, a Discord style chat app: Domain, Application and Infrastructure projects plus the Api host. SignalR for chat and presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible storage for attachments, and OIDC auth shared with the Musify Zitadel instance. Includes the Compose stack for local development.
23 lines
826 B
C#
23 lines
826 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Ping.Application.Contracts;
|
|
|
|
namespace Ping.Application.Shared
|
|
{
|
|
public static class ChannelAccess
|
|
{
|
|
public static async Task<bool> HasAccessAsync(this IDatabase database, Guid channelId, long userId, CancellationToken cancellationToken)
|
|
{
|
|
var isDirectMessageParticipant = await database.ChannelMembers
|
|
.AnyAsync(m => m.ChannelId == channelId && m.UserId == userId, cancellationToken);
|
|
|
|
if (isDirectMessageParticipant)
|
|
return true;
|
|
|
|
return await database.Channels.AnyAsync(c =>
|
|
c.Id == channelId && c.ServerId != null &&
|
|
database.ServerMembers.Any(sm => sm.ServerId == c.ServerId && sm.UserId == userId),
|
|
cancellationToken);
|
|
}
|
|
}
|
|
}
|