Amarula.Group (amarula v0.4.2)
View SourceGroup chats — the %Amarula.Group{} struct and every group operation.
The struct is the consumer-facing view of group metadata (addresses as
Amarula.Address); you get one from metadata/2 and list/1. The operations
(create/3, leave/2, update_subject/3, participant and invite management,
join-request approval) build a w:g2 IQ and parse the reply. Each returns
:ok / {:ok, value} / {:error, {:group_op_failed, code, text}}.
group is a @g.us jid string (e.g. from a group's :address).
A group is a container of participants, not a person: :address names the
group (:group kind), :participants are the member Amarula.Addresses.
Summary
Types
Affected participant in a group op: %{jid, status} (status "200" = ok).
Functions
Join a group by invite code. Returns the joined group's jid.
Create a group named subject with the given participant jids. Returns the new
group's metadata.
Build a Group from a Amarula.Protocol.Groups.Metadata map.
Fetch the group's invite code.
Look up group metadata from an invite code without joining.
Turn join-approval (admin approves joiners) :on/:off.
Leave a group.
List all groups we participate in ([%Amarula.Group{}]).
Who may add members: :admin_add (admins only) or :all_member_add.
Fetch a group's metadata (%Amarula.Group{}). group is an Address or jid.
Add/remove/promote/demote participants. action is :add/:remove/:promote/
:demote. Returns the affected participants with per-jid status.
Approve/reject pending join requests for participants. action is :approve/:reject.
List pending join-approval requests as
[%{jid: Amarula.Address.t(), requested_at: integer | nil}] — who asked to join
and when. Approve/reject them with request_update/4.
Revoke + regenerate the group's invite code. Returns the new code.
Toggle disappearing messages. 0 = off; otherwise seconds of expiration.
Set (or clear, with nil/"") a group's description.
Set your own member tag (per-group self-label) in group, or clear it with
"". Capped at 30 chars (a longer one is rejected, not truncated). A message
send (not an IQ op), so it lives on the facade too as Amarula.update_member_tag/3
— this is the group-scoped alias.
Change a group setting: :announcement/:not_announcement (only admins post),
:locked/:unlocked (only admins edit info).
Change a group's subject (title).
Types
Affected participant in a group op: %{jid, status} (status "200" = ok).
@type conn() :: GenServer.server()
@type participant() :: %{ address: Amarula.Address.t(), admin: :admin | :superadmin | nil }
@type t() :: %Amarula.Group{ address: Amarula.Address.t(), owner: Amarula.Address.t() | nil, participants: [participant()], size: non_neg_integer(), subject: String.t() | nil }
Functions
Join a group by invite code. Returns the joined group's jid.
Create a group named subject with the given participant jids. Returns the new
group's metadata.
Build a Group from a Amarula.Protocol.Groups.Metadata map.
Fetch the group's invite code.
Look up group metadata from an invite code without joining.
Turn join-approval (admin approves joiners) :on/:off.
Leave a group.
List all groups we participate in ([%Amarula.Group{}]).
Who may add members: :admin_add (admins only) or :all_member_add.
@spec metadata(conn(), Amarula.Address.t() | String.t()) :: {:ok, t()} | {:error, term()}
Fetch a group's metadata (%Amarula.Group{}). group is an Address or jid.
@spec participants( conn(), String.t(), [String.t()], Amarula.Protocol.Groups.Ops.action() ) :: {:ok, [affected()]} | {:error, term()}
Add/remove/promote/demote participants. action is :add/:remove/:promote/
:demote. Returns the affected participants with per-jid status.
@spec request_update(conn(), String.t(), [String.t()], :approve | :reject) :: {:ok, [affected()]} | {:error, term()}
Approve/reject pending join requests for participants. action is :approve/:reject.
@spec requests(conn(), String.t()) :: {:ok, [%{jid: Amarula.Address.t(), requested_at: integer() | nil}]} | {:error, term()}
List pending join-approval requests as
[%{jid: Amarula.Address.t(), requested_at: integer | nil}] — who asked to join
and when. Approve/reject them with request_update/4.
Revoke + regenerate the group's invite code. Returns the new code.
@spec toggle_ephemeral(conn(), String.t(), non_neg_integer()) :: :ok | {:error, term()}
Toggle disappearing messages. 0 = off; otherwise seconds of expiration.
Set (or clear, with nil/"") a group's description.
@spec update_member_tag(conn(), String.t(), String.t()) :: Amarula.send_result() | {:error, :member_tag_too_long}
Set your own member tag (per-group self-label) in group, or clear it with
"". Capped at 30 chars (a longer one is rejected, not truncated). A message
send (not an IQ op), so it lives on the facade too as Amarula.update_member_tag/3
— this is the group-scoped alias.
@spec update_setting(conn(), String.t(), Amarula.Protocol.Groups.Ops.setting()) :: :ok | {:error, term()}
Change a group setting: :announcement/:not_announcement (only admins post),
:locked/:unlocked (only admins edit info).
Change a group's subject (title).