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

import StreamChat

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

// Controllers

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

// State layer (async-await)

try await chat.inviteMembers(["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!").

import StreamChat

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

// Controllers

controller.acceptInvite(message: "Nick joined this channel!")

// State layer (async-await)

try await chat.acceptInvite(with: "Nick joined this channel!")

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.

import StreamChat

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

// Controllers

controller.rejectInvite()

// State layer (async-await)

try await chat.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
    }
  }
}