val channelClient = client.channel("messaging", "general")
channelClient.inviteMembers(memberIds = listOf("nick")).enqueue { result ->
if (result is Result.Success) {
val channel: Channel = result.value
} else {
// Handle Result.Failure
}
}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
// Android SDK
ChannelClient channelClient = client.channel("messaging", "general");
List<String> memberIds = Arrays.asList("thierry", "tommaso");
Map<String, Object> data = new HashMap<>();
data.put("invites", Arrays.asList("nick"));
channelClient.create(memberIds, data).enqueue(result -> {
if (result.isSuccess()) {
Channel channel = result.data();
} else {
// Handle result.error()
}
});
// Backend SDK
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!").
// Android SDK
channelClient.acceptInvite("Nick joined this channel!").enqueue(result -> {
if (result.isSuccess()) {
Channel channel = result.data();
} else {
// Handle result.error()
}
});
// Backend SDK
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.
// Android SDK
channelClient.rejectInvite().enqueue(result -> {
if (result.isSuccess()) {
// Invite rejected
} else {
// Handle result.error()
}
});
// Backend SDK
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
// Android SDK
FilterObject filter = Filters.eq("invite", "accepted");
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.data();
} else {
// Handle result.error()
}
});
// Backend SDK
chat.queryChannels(QueryChannelsRequest.builder()
.filterConditions(Map.of("invite", "accepted"))
.build()).execute();Query Rejected Invites
// Android SDK
FilterObject filter = Filters.eq("invite", "rejected");
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.data();
} else {
// Handle result.error()
}
});
// Backend SDK
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.data();
} else {
// Handle result.error()
}
});