Gamend.Groups.Invites (gamend_core v1.0.1192)

Copy Markdown View Source

Group invitations: creating, accepting, declining, cancelling, and listing/counting pending invites.

Public API is re-exported by Gamend.Groups.

Summary

Functions

Accept a pending group invite by invite_id. The user must be the recipient of the invite. Works for all group types (public, private, hidden).

Cancel (delete) a group invitation that the current user sent. Only the sender can cancel their own invitation.

Count pending invitations for a user.

Count group invitations sent by a user.

Decline a pending group invite by invite_id. Only the recipient can decline. The invite is marked as "declined" (not deleted) so the sender can see the outcome.

Invite a user to a group. Creates a GroupInvite record and sends an informational notification. The invite record is independent of the notification — deleting notifications does not affect pending invites.

List pending group invitations for a user.

List group invitations sent by a user.

Functions

accept_invite(user_id, invite_id)

@spec accept_invite(Ecto.UUID.t(), Ecto.UUID.t()) ::
  {:ok, Gamend.Groups.GroupMember.t()} | {:error, atom()}

Accept a pending group invite by invite_id. The user must be the recipient of the invite. Works for all group types (public, private, hidden).

cancel_invite(user_id, invite_id)

@spec cancel_invite(Ecto.UUID.t(), Ecto.UUID.t()) :: :ok | {:error, atom()}

Cancel (delete) a group invitation that the current user sent. Only the sender can cancel their own invitation.

count_invitations(user_id)

@spec count_invitations(Ecto.UUID.t()) :: non_neg_integer()

Count pending invitations for a user.

count_sent_invitations(user_id)

@spec count_sent_invitations(Ecto.UUID.t()) :: non_neg_integer()

Count group invitations sent by a user.

decline_invite(user_id, invite_id)

@spec decline_invite(Ecto.UUID.t(), Ecto.UUID.t()) :: :ok | {:error, atom()}

Decline a pending group invite by invite_id. Only the recipient can decline. The invite is marked as "declined" (not deleted) so the sender can see the outcome.

invite_to_group(admin_id, group_id, target_user_id)

@spec invite_to_group(Ecto.UUID.t(), Ecto.UUID.t(), Ecto.UUID.t()) ::
  {:ok, Gamend.Groups.GroupInvite.t()}
  | {:ok, :request_approved}
  | {:error, atom()}

Invite a user to a group. Creates a GroupInvite record and sends an informational notification. The invite record is independent of the notification — deleting notifications does not affect pending invites.

If the target user already has a pending join request for this group, the request is automatically approved instead of creating an invite. In that case, returns {:ok, :request_approved}.

The admin must already be connected to the target — a friendship, or a group they are both already in. Without that an admin could put any user id at all into a group with them, which made a group invite a weaker control than a party invite, where Parties.check_leader_connected_to_target/2 has always required a connection. On a service children can reach, being addable to a stranger's group is the contact path that matters, so the two now agree. Returns {:error, :not_connected}.

list_invitations(user_id, opts \\ [])

@spec list_invitations(
  Ecto.UUID.t(),
  keyword()
) :: [map()]

List pending group invitations for a user.

list_sent_invitations(user_id, opts \\ [])

@spec list_sent_invitations(
  Ecto.UUID.t(),
  keyword()
) :: [map()]

List group invitations sent by a user.