Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created December 8, 2025 19:10
Show Gist options
  • Select an option

  • Save dcomartin/a6d35607da592eb035b772087aac1c0e to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/a6d35607da592eb035b772087aac1c0e to your computer and use it in GitHub Desktop.
public class GroupMembership
{
private const int MaxMembers = 100_000;
private readonly HashSet<Guid> _members = new();
public Guid GroupChatId { get; private set; }
public GroupMembership(Guid groupChatId)
{
GroupChatId = groupChatId;
}
public void AddMember(Guid userId)
{
if (_members.Count >= MaxMembers)
throw new InvalidOperationException("Too many members");
_members.Add(userId);
}
public void RemoveMember(Guid userId)
{
_members.Remove(userId);
}
public IReadOnlyCollection<Guid> Members => _members;
}
public class GroupChat
{
public Guid Id { get; private set; }
public GroupChat(Guid id)
{
Id = id;
}
public void PostMessage(Guid senderUserId, string message)
{
// Assume sender membership is already validated externally
// Here we handle domain logic related to messaging
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment