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

let controller = client.channelController(for: .init(type: .messaging, id: "general"))

controller.inviteMembers(userIds: ["thierry"])

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!”).

let controller = client.channelController(for: .init(type: .messaging, id: "general"))


controller.acceptInvite()

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.

let controller = client.channelController(for: .init(type: .messaging, id: "general"))

controller.rejectInvite()

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

import StreamChat

let controller = chatClient.channelListController(
  query: .init(
    filter: .equal(.invite, to: .accepted)
  )
)

controller.synchronize { error in
  if let error = error {
    // handle error
    print(error)
  } else {
    // access channels
    print(controller.channels)

    // load more if needed
    controller.loadNextChannels(limit: 10) { _ in
      // handle error / access channels
    }
  }
}

Query Rejected Invites

import StreamChat

let controller = chatClient.channelListController(
  query: .init(
    filter: .equal(.invite, to: .rejected)
  )
)

controller.synchronize { error in
  if let error = error {
    // handle error
    print(error)
  } else {
    // access channels
    print(controller.channels)

    // load more if needed
    controller.loadNextChannels(limit: 10) { _ in
      // handle error / access channels
    }
  }
}

Query Pending Invites

import StreamChat

let controller = chatClient.channelListController(
  query: .init(
    filter: .equal(.invite, to: .pending)
  )
)

controller.synchronize { error in
  if let error = error {
    // handle error
    print(error)
  } else {
    // access channels
    print(controller.channels)

    // load more if needed
    controller.loadNextChannels(limit: 10) { _ in
      // handle error / access channels
    }
  }
}