Skip to main content

Manage membership requests

This guide covers joining a group, inviting users, and handling join requests and invitations.

Join a group

Join directly

Call joinWithCompletion: on a NCGroupChannel instance. The result depends on the group's joinPermission:

  • Approval required: processCode returns 25424. The user and the owner/admins receive onGroupApplicationEvent.
  • No approval required: processCode returns 0. All members receive onGroupOperation with type NCGroupOperationTypeJoin.
objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel joinWithCompletion:^(NSInteger processCode, NCError * _Nullable error) {
if (!error) {
// Joined or pending approval (check processCode)
}
}];

Invite users

Call inviteUsersWithUserIds:completion: to invite users. The invitePermission setting controls who can invite.

objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel inviteUsersWithUserIds:@[@"userId1", @"userId2"] completion:^(NSInteger processCode, NCError * _Nullable error) {
if (!error) {
// Invited or pending approval (check processCode)
// processCode 25424: requires owner/admin approval
// processCode 25427: requires invitee acceptance
// processCode 0: user joined directly
}
}];

The invitation flow depends on three factors:

  1. Join permission (joinPermission): Whether owner/admin approval is required.
  2. Inviter role: Whether the inviter is an owner/admin or a regular member.
  3. Invitee handling (inviteHandlePermission): Whether the invitee must accept.

Handle an invitation (invitee)

Accept:

objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel acceptInviteWithInviterId:@"inviterId" completion:^(NCError * _Nullable error) {
if (!error) {
// Accepted
}
}];

Decline:

objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
NCRefuseGroupInviteParams *params = [[NCRefuseGroupInviteParams alloc] init];
params.inviterId = @"inviterId";
params.reason = @"reason";
[channel refuseInviteWithParams:params completion:^(NCError * _Nullable error) {
if (!error) {
// Declined
}
}];

Handle a join request (owner/admin)

Join requests expire after 7 days.

Approve:

objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
NCAcceptGroupApplicationParams *params = [[NCAcceptGroupApplicationParams alloc] init];
params.applicantId = @"applicantId";
params.inviterId = nil; // nil for direct join requests; set for invitation requests

[channel acceptApplicationWithParams:params completion:^(NSInteger processCode, NCError * _Nullable error) {
if (!error) {
// Approved
}
}];

Reject:

objc
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
NCRefuseGroupApplicationParams *params = [[NCRefuseGroupApplicationParams alloc] init];
params.applicantId = @"applicantId";
params.inviterId = nil;
params.reason = @"reason";

[channel refuseApplicationWithParams:params completion:^(NCError * _Nullable error) {
if (!error) {
// Rejected
}
}];

Get membership request list (paginated)

Use createGroupApplicationsQueryWithParams: to retrieve pending requests via a paginated query. Requests expire after 7 days.

objc
NCGroupApplicationsQueryParams *params = [[NCGroupApplicationsQueryParams alloc] init];
params.pageSize = 20;
params.directions = @[@(NCGroupApplicationDirectionInvitationReceived)];
params.status = @[@(NCGroupApplicationStatusManagerUnHandled)];

NCGroupApplicationsQuery *query = [NCGroupChannel createGroupApplicationsQueryWithParams:params];
[query loadNextPageWithCompletion:^(NCGroupApplicationsPageResult * _Nullable page, NCError * _Nullable error) {
if (!error) {
// page.data: current page of applications
}
}];