On this page

Presence

Track which users are online and active in your chat app. Display user status (online, offline, active, away) and show when users were last active.

The Chat SDK provides two types of presence tracking:

TypeDescriptionData source
Channel presence
Real-time tracking of users subscribed to specific channels
Presence API
Global presence
App-wide activity tracking based on timestamps
lastActiveTimestamp property

Channel presence provides real-time updates through the Presence API. Use streamPresence() to track who connects or disconnects.

Global presence uses the lastActiveTimestamp property on User objects. Configure the update interval (default: 10 minutes, minimum: 1 minute) during initialization with storeUserActivityTimestamps.

Channel presence

These methods let you monitor who is subscribed to a given channel ("present" on that channel).

Requires Presence

All channel presence methods in this section require that Presence is enabled for your app's keyset in the Admin Portal.

You can retrieve similar information for presence with different methods by calling them on the User, Channel, or Chat object. Depending on the chosen method, you must provide a different input information set.

Return channels where user is present

Return a list of channels where a given user is present:

  • wherePresent() on the User object
  • wherePresent() on the Chat object

Method signature

These methods take the following parameters:

  • wherePresent() (on the User object)

    1user.wherePresent() async throws -> [String]
  • wherePresent() (on the Chat object)

    1chat.wherePresent(
    2 userId: String
    3) async throws -> [String]
Input
ParameterRequired in the User object methodRequired in the Chat object methodDescription
userId
Type: String
Default:
n/a
No
Yes
Unique identifier (up to 92 UTF-8 characters) of the user whose presence you want to check.
Output
ParameterDescription
[String]
List of all channel IDs on which the given user is present.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Get a list of channels on which the support_agent_15 user is present.

  • wherePresent() (on the User object)

    1
    
  • wherePresent() (on the Chat object)

    1
    

Check user's channel presence

Check if a user is present on a specified channel:

  • isPresentOn() on the User object
  • isPresent() on the Channel object
  • isPresent() on the Chat object

Method signature

These methods take the following parameters:

  • isPresentOn() (on the User object)

    1user.isPresentOn(
    2 channelId: String
    3) async throws -> Bool
  • isPresent() (on the Channel object)

    1channel.isPresent(
    2 userId: String
    3) async throws -> Bool
  • isPresent() (on the Chat object)

    1chat.isPresent(
    2 userId: String,
    3 channelId: String
    4) async throws -> Bool
Input
ParameterRequired in the User object methodRequired in the Channel object methodRequired in the Chat object methodDescription
userId
Type: String
Default:
n/a
No
Yes
Yes
Unique ID (up to 92 UTF-8 characters) of the user whose presence you want to check.
channelId
Type: String
Default:
n/a
Yes
No
Yes
Unique identifier of the channel where you want to check the user's presence.
Output
ParameterDescription
Bool
Returns information on whether a given user is present on a specified channel (true) or not (false) or an error.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Find out if the support_agent_15 user is present on the support channel.

  • isPresentOn() (on the User object)

    1
    
  • isPresent() (on the Channel object)

    1
    
  • isPresent() (on the Chat object)

    1
    

Return all users present on channel

Return a list of users present on a given channel:

  • whoIsPresent() on the Channel object
  • whoIsPresent() on the Chat object

Method signature

These methods take the following parameters:

  • whoIsPresent() (on the Channel object)

    1channel.whoIsPresent(
    2 limit: Int = 1000,
    3 offset: Int? = 0
    4) async throws -> [String]
  • whoIsPresent() (on the Chat object)

    1chat.whoIsPresent(
    2 channelId: String,
    3 limit: Int = 1000,
    4 offset: Int? = 0
    5) async throws -> [String]
Input
ParameterRequired in the Channel object methodRequired in the Chat object methodDescription
channelId
Type: String
Default:
n/a
No
Yes
Unique identifier of the channel where you want to check all present users.
limit
Type: Int
Default:
1000
No
No
Maximum number of occupants to return per channel. Valid range: 0-1000. Use 0 to get occupancy counts without user details.
offset
Type: Int?
Default:
0
No
No
Zero-based starting index for pagination. Returns occupants starting from this position in the list. Must be >= 0.
Output
ParameterDescription
[String]
List of all user IDs that are present on the given channel.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Get a list of users that are present on the support channel.

  • whoIsPresent() (on the Channel object)

    1
    
  • whoIsPresent() (on the Chat object)

    1
    

Get presence updates

Get real-time presence updates by subscribing to Presence events. The streamPresence() method tracks who connects to or disconnects from the channel.

Method signature

This method takes the following parameters:

1channel.streamPresence() -> AsyncStream<[String]>
Input

This method doesn't take any parameters.

Output
ParameterDescription
AutoCloseable
An asynchronous stream that emits a value whenever users connect to or disconnect from the channel.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Get user presence updates on support channel.

1

Global presence

Track users' last online activity to display availability status (offline, online, active, away) next to user profiles.

This feature relies on the lastActiveTimestamp property on the User object. To enable tracking, configure during Chat SDK initialization:

  • Set storeUserActivityTimestamps to true
  • Configure storeUserActivityInterval for update frequency (default: 600 seconds/10 minutes, minimum: 60 seconds/1 minute)

Use the active property to check if a user showed activity within the configured interval.

Check user's app presence

active is a getter property on the User object that checks whether a user has recently been active based on their last activity timestamp and the configured interval.

Required configuration

To track the user's online activity, you must first configure the storeUserActivityTimestamps and storeUserActivityInterval parameters when initializing the Chat SDK.

Method signature

This method has the following signature:

1user.active
Input

This method doesn't take any parameters.

Output
ParameterDescription
Bool
Returned info on whether the user is active (true) or not active (false) on the channel. The returned value depends strictly on how you configure your chat app during initialization - if you set the storeUserActivityInterval parameter to the default 600 seconds (10 minutes) and the user has been active in the app within the last 10 minutes (based on their lastActiveTimestamp property), the active method returns true.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Check if the user support_agent_15 has been recently active (assuming you configured the chat app to use the default activity interval value).

1

Check user's last online activity

Required configuration

To track the user's online activity, you must first configure the storeUserActivityTimestamps and storeUserActivityInterval parameters when initializing the Chat SDK.

Retrieve the lastActiveTimestamp from the User object and convert it to a human-readable date to display when a user was last online.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Show the Unix timestamp when support_agent_15 was last time active in an app.

1

Last updated on