Amarula.Protocol.Groups.Ops (amarula v0.1.0)

View Source

Group management operations: build the w:g2 IQs that CHANGE a group, and parse their replies. Port of the group op builders in Baileys groups.ts (the write side; Groups.Metadata is the read side).

Every op is a <iq xmlns="w:g2" type=get|set to=<group>> with a single child naming the action. Builders return a %Node{}; parsers turn the reply into the affected participants / invite code / etc. The IQ round-trip lives in Connection (via send_waiter_iq).

Summary

Functions

Accept an invite by code — joins the group.

Create a group with subject and initial participants (jids).

Fetch the group's invite code (get).

Look up a group's metadata from an invite code without joining (get).

Turn join-approval (admin must approve joiners) on/off.

Leave group id (a bare id or full jid).

Who may add members: :admin_add or :all_member_add.

Parse the joined group's jid from an accept-invite reply.

Parse the invite code from an invite/revoke reply.

Parse the affected-participants list from an add/remove/promote/demote reply.

Parse pending join requests into a list of attr maps.

Parse the affected participants from an approve/reject reply.

Add/remove/promote/demote participants (jids) in a group.

List pending join-approval requests (get).

Approve/reject pending join requests for participants (jids).

Revoke + regenerate the group's invite code (set).

Change a group setting: announcement (admins-only msgs) / locked (admins-only edit).

Toggle disappearing messages. 0 turns it off; else seconds of expiration.

Set or clear the group description. nil/"" clears it; prev is the previous description id (from metadata) when editing.

Change the group subject (title).

Types

action()

@type action() :: :add | :remove | :promote | :demote

affected()

@type affected() :: %{jid: String.t() | nil, status: String.t()}

setting()

@type setting() :: :announcement | :not_announcement | :locked | :unlocked

Functions

accept_invite(code)

@spec accept_invite(String.t()) :: Amarula.Protocol.Binary.Node.t()

Accept an invite by code — joins the group.

create(subject, participants)

Create a group with subject and initial participants (jids).

invite_code(group_jid)

@spec invite_code(String.t()) :: Amarula.Protocol.Binary.Node.t()

Fetch the group's invite code (get).

invite_info(code)

@spec invite_info(String.t()) :: Amarula.Protocol.Binary.Node.t()

Look up a group's metadata from an invite code without joining (get).

join_approval_mode(group_jid, mode)

@spec join_approval_mode(String.t(), :on | :off) :: Amarula.Protocol.Binary.Node.t()

Turn join-approval (admin must approve joiners) on/off.

leave(id)

Leave group id (a bare id or full jid).

member_add_mode(group_jid, mode)

@spec member_add_mode(String.t(), :admin_add | :all_member_add) ::
  Amarula.Protocol.Binary.Node.t()

Who may add members: :admin_add or :all_member_add.

parse_accepted_jid(reply)

@spec parse_accepted_jid(Amarula.Protocol.Binary.Node.t()) ::
  {:ok, String.t()} | {:error, term()}

Parse the joined group's jid from an accept-invite reply.

parse_invite_code(reply)

@spec parse_invite_code(Amarula.Protocol.Binary.Node.t()) ::
  {:ok, String.t()} | {:error, term()}

Parse the invite code from an invite/revoke reply.

parse_participants(reply, action)

@spec parse_participants(Amarula.Protocol.Binary.Node.t(), action()) ::
  {:ok, [affected()]} | {:error, term()}

Parse the affected-participants list from an add/remove/promote/demote reply.

parse_request_list(reply)

@spec parse_request_list(Amarula.Protocol.Binary.Node.t()) :: {:ok, [map()]}

Parse pending join requests into a list of attr maps.

parse_request_update(reply, action)

@spec parse_request_update(Amarula.Protocol.Binary.Node.t(), :approve | :reject) ::
  {:ok, [affected()]}

Parse the affected participants from an approve/reject reply.

participants_update(group_jid, participants, action)

@spec participants_update(String.t(), [String.t()], action()) ::
  Amarula.Protocol.Binary.Node.t()

Add/remove/promote/demote participants (jids) in a group.

request_list(group_jid)

@spec request_list(String.t()) :: Amarula.Protocol.Binary.Node.t()

List pending join-approval requests (get).

request_update(group_jid, participants, action)

@spec request_update(String.t(), [String.t()], :approve | :reject) ::
  Amarula.Protocol.Binary.Node.t()

Approve/reject pending join requests for participants (jids).

revoke_invite(group_jid)

@spec revoke_invite(String.t()) :: Amarula.Protocol.Binary.Node.t()

Revoke + regenerate the group's invite code (set).

setting_update(group_jid, setting)

@spec setting_update(String.t(), setting()) :: Amarula.Protocol.Binary.Node.t()

Change a group setting: announcement (admins-only msgs) / locked (admins-only edit).

toggle_ephemeral(group_jid, expiration)

@spec toggle_ephemeral(String.t(), non_neg_integer()) ::
  Amarula.Protocol.Binary.Node.t()

Toggle disappearing messages. 0 turns it off; else seconds of expiration.

update_description(group_jid, description, prev \\ nil)

@spec update_description(String.t(), String.t() | nil, String.t() | nil) ::
  Amarula.Protocol.Binary.Node.t()

Set or clear the group description. nil/"" clears it; prev is the previous description id (from metadata) when editing.

update_subject(group_jid, subject)

@spec update_subject(String.t(), String.t()) :: Amarula.Protocol.Binary.Node.t()

Change the group subject (title).