Invites

Invites allow you to add users to a channel with a pending state. The invited user receives a notification and can accept or reject the invite.

Unread counts are not incremented for channels with a pending invite.

Invite Users

chat.updateChannel("messaging", "general", UpdateChannelRequest.builder()
    .invites(List.of(
        ChannelMemberRequest.builder().userID("thierry").build(),
        ChannelMemberRequest.builder().userID("tommaso").build()))
    .build()).execute();

Accept an Invite

Call acceptInvite to accept a pending invite. You can optionally include a message parameter to post a system message when the user joins (e.g., "Nick joined this channel!").

chat.updateChannel("messaging", "general", UpdateChannelRequest.builder()
    .acceptInvite(true)
    .userID("nick")
    .message(MessageRequest.builder().text("Nick joined the channel").userID("nick").build())
    .build()).execute();

Reject an Invite

Call rejectInvite to decline a pending invite. Client-side calls use the currently connected user. Server-side calls require a user_id parameter.

chat.updateChannel("messaging", "general", UpdateChannelRequest.builder()
    .rejectInvite(true)
    .userID("nick")
    .build()).execute();

Query Invites by Status

Use queryChannels with the invite filter to retrieve channels based on invite status. Valid values are pending, accepted, and rejected.

Query Accepted Invites

chat.queryChannels(QueryChannelsRequest.builder()
    .filterConditions(Map.of("invite", "accepted"))
    .build()).execute();

Query Rejected Invites

chat.queryChannels(QueryChannelsRequest.builder()
    .filterConditions(Map.of("invite", "rejected"))
    .build()).execute();

Query Pending Invites

FilterObject filter = Filters.eq("invite", "pending");
int offset = 0;
int limit = 10;
QuerySorter<Channel> sort = new QuerySortByField<>();
int messageLimit = 0;
int memberLimit = 0;
QueryChannelsRequest request = new QueryChannelsRequest(filter, offset, limit, sort, messageLimit, memberLimit);

client.queryChannels(request).enqueue(result -> {
  if (result.isSuccess()) {
    List<Channel> channels = result.getOrNull();
  } else {
    // Handle error
  }
});