User Groups
UserGroups::UserGroups
Constructs a user group list from existing data (stored from dump()
) and the user's
secret key for generating the data encryption key. To construct a blank list (i.e. with no
pre-existing dumped data to load) pass std::nullopt
as the second argument.
Declaration
Parameters
ed25519_secretkey
— contains the libsodium secret key used to encrypt/decrypt the data when pushing/pulling from the swarm. This can either be the full 64-byte value (which is technically the 32-byte seed followed by the 32-byte pubkey), or just the 32-byte seed of the secret key.dumped
— eitherstd::nullopt
to construct a new, empty object; or binary state data that was previously dumped from an instance of this class by callingdump()
.
Returns
UserGroups
- Constructor
UserGroups::begin
Iterators for iterating through all groups. Typically you access this implicit via a
for loop over the UserGroups
object:
for (auto& group : usergroups) {
if (auto* comm = std::get_if<community_info>(&group)) {
// use comm->name, comm->priority, etc.
} else if (auto* lg = std::get_if<legacy_group_info>(&convo)) {
// use lg->session_id, lg->priority, etc.
}
}
This iterates through all groups in sorted order (sorted first by convo type [groups, communities, legacy groups], then by id within the type).
It is NOT permitted to add/remove/modify records while iterating. If such is needed it must be done in two passes: once to collect the modifications, then a loop applying the collected modifications.
Declaration
Parameters
This endpoint takes no inputs.
Returns
iterator
- Returns an iterator for the beginning of the groups
UserGroups::begin_communities
Declaration
Parameters
This endpoint takes no inputs.
Returns
- an iterator that iterates only through community conversations. (The regular
.end()
iterator is valid for testing the end of this iterator).
UserGroups::begin_groups
Declaration
Parameters
This endpoint takes no inputs.
Returns
- an iterator that iterates only through group conversations. (The regular
.end()
iterator is valid for testing the end of this iterator).
UserGroups::begin_legacy_groups
Declaration
Parameters
This endpoint takes no inputs.
Returns
- an iterator that iterates only through legacy group conversations. (The regular
.end()
iterator is valid for testing the end of this iterator).
UserGroups::create_group
Constructs a group_info
object with newly generated (random) keys and returns the
group_info containing these keys. The group will have the id and secretkey populated; other
fields are defaulted. You still need to pass this to set()
to store it, after setting any
other fields as desired.
Declaration
Parameters
This endpoint takes no inputs.
Returns
group_info
- Returns a filled out group_info struct for a new, randomly generated group.
UserGroups::empty
Returns true if the group list is empty.
Declaration
Parameters
This endpoint takes no inputs.
Returns
bool
- Returns true if the contact list is empty
UserGroups::encryption_domain
Returns the domain. Is constant, will always return "Contacts"
Declaration
Parameters
This endpoint takes no inputs.
Returns
const char*
- Returns "UserGroups"
UserGroups::end
Iterator for passing the end of the groups
Declaration
Parameters
This endpoint takes no inputs.
Returns
iterator
- Returns an iterator for the end of the groups
UserGroups::erase
Removes a conversation taking the community_info, group_info, or legacy_group_info instance (rather than the pubkey/url) for convenience.
Declaration
bool erase(const group_info& g);
bool erase(const community_info& g);
bool erase(const legacy_group_info& c);
bool erase(const any_group_info& info);
Parameters
group_info
— any group info struct
Returns
bool
- Returns true if found and removed, false otherwise
UserGroups::erase_community
Removes a community group. Returns true if found and removed, false if not present.
Arguments are the same as get_community
.
Declaration
Parameters
base_url
— text string containing the base URLroom
— room token to lookup
Returns
bool
- Returns true if found and removed, false otherwise
UserGroups::erase_group
Removes a (new, closed) group conversation. Returns true if found and removed, false if not present.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID, but starts with 03)
Returns
bool
- Returns true if found and removed, false otherwise
UserGroups::erase_legacy_group
Removes a legacy group conversation. Returns true if found and removed, false if not present.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID)
Returns
bool
- Returns true if found and removed, false otherwise
UserGroups::get_community
Looks up and returns a community (aka open group) conversation. Takes the base URL and room
token (case insensitive). Retuns nullopt if the open group was not found, otherwise a
filled out community_info
. Note that the room
argument here is case-insensitive, but
the returned value will be the room as stored in the object (i.e. it may have a different
case from the requested room
value).
Declaration
std::optional<community_info> get_community(
std::string_view base_url, std::string_view room) const;
Parameters
- First Function:
base_url
— base URLroom
— room token (case insensitive)- Second Function
partial_url
— Looks up a community from a url permitting to omit the pubkey
Returns
std::optional<community_info>
- Returns the filled out community_info struct if found
UserGroups::get_group
Looks up and returns a group (aka new closed group) by group ID (hex, looks like a Session
ID but starting with 03). Returns nullopt if the group was not found, otherwise returns a
filled out group_info
.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID but starting 03 instead of 05)
Returns
std::optional<group_info>
- Returns the filled out group_info struct if found, nullopt if not found.
UserGroups::get_legacy_group
Looks up and returns a legacy group by group ID (hex, looks like a Session ID). Returns
nullopt if the group was not found, otherwise returns a filled out legacy_group_info
.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID)
Returns
std::optional<legacy_group_info>
- Returns the filled out legacy_group_info struct if found
UserGroups::get_or_construct_community
Same as get_community
, except if the community isn't found a new blank one is created for
you, prefilled with the url/room/pubkey.
Declaration
community_info get_or_construct_community(
std::string_view base_url,
std::string_view room,
std::string_view pubkey_encoded) const;
community_info get_or_construct_community(
std::string_view base_url, std::string_view room, ustring_view pubkey) const;
Parameters
base_url
— text string containing the base URLroom
— is case-insensitive for the lookup: if a matching room is found then the returned value reflects the room case of the existing record, which is not necessarily the same as theroom
argument given here (to force a case change, set it within the returned object).pubkey
— is not used to find an existing community, but if the community found has a different pubkey from the one given then the returned record has its pubkey updated in the return instance (note that this changed value is not committed to storage, however, until the instance is passed toset()
). For the string_view version the pubkey is accepted as hex, base32z, or base64.
Returns
community_info
- Returns the filled out community_info struct
UserGroups::get_or_construct_community(string_view)
Shortcut to pass the url through community::parse_full_url, then call the above
get_or_construct_community
.
Declaration
Parameters
full_url
— text string containing the full URL including pubkey
Returns
community_info
- Returns the filled out community_info struct
UserGroups::get_or_construct_group
Gets or constructs a blank group_info for the given group id.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID)
Returns
group_info
- Returns the filled out group_info struct
UserGroups::get_or_construct_legacy_group
Gets or constructs a blank legacy_group_info for the given group id.
Declaration
Parameters
pubkey_hex
— group ID (hex, looks like a session ID)
Returns
legacy_group_info
- Returns the filled out legacy_group_info struct
UserGroups::set
Inserts or replaces existing group info. For example, to update the info for a community you would do:
auto info = conversations.get_or_construct_community(some_session_id);
info.last_read = new_unix_timestamp;
conversations.set(info);
Declaration
void set(const group_info& info);
void set(const community_info& info);
void set(const legacy_group_info& info);
Parameters
info
— group info struct to insert. Can becommunity_info
,group_info
, orlegacy_group_info
.
Returns
UserGroups::size
Returns the number of groups (of any type).
Declaration
Parameters
This endpoint takes no inputs.
Returns
size_t
- Returns the number of groups
UserGroups::size_communities
Returns the number of communities
Declaration
Parameters
This endpoint takes no inputs.
Returns
size_t
- Returns the number of groups
UserGroups::size_groups
Returns the number of (non-legacy) groups
Declaration
Parameters
This endpoint takes no inputs.
Returns
size_t
- Returns the number of groups
UserGroups::size_legacy_groups
Returns the number of legacy groups
Declaration
Parameters
This endpoint takes no inputs.
Returns
size_t
- Returns the number of legacy groups
UserGroups::storage_namespace
Returns the Contacts namespace.
Declaration
Parameters
This endpoint takes no inputs.
Returns
Namespace
- Returns Namespace::UserGroups
legacy_group_info::counts
Returns a pair of the number of admins, and regular members of this group. (If all you want
is the overall number just use .members().size()
instead).
Declaration
Parameters
This endpoint takes no inputs.
Returns
std::pair<size_t, size_t>
— Returns a pair of the counts of members of the group. Containssize_t
— number of adminssize_t
— number of regular members
legacy_group_info::erase
Removes a member (by session id) from this group. Returns true if the member was removed, false if the member was not present.
Declaration
Parameters
session_id
— Hex string of the Session ID
Returns
bool
— Returns true if the member was found and removed, false otherwise
legacy_group_info::insert
Adds a member (by session id and admin status) to this group. Returns true if the member was inserted or changed admin status, false if the member already existed. Throws std::invalid_argument if the given session id is invalid.
Declaration
Parameters
session_id
— Hex string of the Session IDadmin
— boolean if the user is to have admin powers
Returns
bool
— Returns true if the member was inserted or changed, otherwise false.
legacy_group_info::members
Accesses the session ids (in hex) of members of this group. The key is the hex session_id; the value indicates whether the member is an admin (true) or not (false).
Declaration
Parameters
This endpoint takes no inputs.
Returns
std::map<std::string, bool>&
— Returns a reference to the members of the group. Containsstd::string
— Hex Session IDbool
— Whether the member is an admin (true)