Skip to main content



A publisher emitting a new value every time the current user changes.

public var currentUserChangePublisher: AnyPublisher<EntityChange<CurrentChatUser>, Never> 


A publisher emitting a new value every time the unread count changes..

public var unreadCountPublisher: AnyPublisher<UnreadCount, Never> 


A wrapper object that exposes the controller variables in the form of ObservableObject to be used in SwiftUI.

public var observableObject: ObservableObject 


The ChatClient instance this controller belongs to.

public let client: ChatClient


The currently logged-in user. nil if the connection hasn't been fully established yet, or the connection wasn't successful.

public var currentUser: CurrentChatUser? 


The unread messages and channels count for the current user.

public var unreadCount: UnreadCount 

Returns noUnread if currentUser doesn't exist yet.


Set the delegate of CurrentUserController to observe the changes in the system.

var delegate: CurrentChatUserControllerDelegate? 



Synchronize local data with remote. Waits for the client to connect but doesn’t initiate the connection itself. This is to make sure the fetched local data is up-to-date, since the current user data is updated through WebSocket events.

override public func synchronize(_ completion: ((_ error: Error?) -> Void)? = nil) 


  • completion: Called when the controller has finished fetching the local data and the client connection is established.


Fetches the token from tokenProvider and prepares the current ChatClient variables for the new user.

func reloadUserIfNeeded(completion: ((Error?) -> Void)? = nil) 

If the a token obtained from tokenProvider is for another user the database will be flushed.


  • completion: The completion to be called when the operation is completed.


Updates the current user data.

func updateUserData(
name: String? = nil,
imageURL: URL? = nil,
userExtraData: [String: RawJSON] = [:],
completion: ((Error?) -> Void)? = nil

By default all data is nil, and it won't be updated unless a value is provided.


  • name: Optionally provide a new name to be updated.
  • imageURL: Optionally provide a new image to be updated.
  • userExtraData: Optionally provide new user extra data to be updated.
  • completion: Called when user is successfully updated, or with error.


Fetches the most updated devices and syncs with the local database.

func synchronizeDevices(completion: ((Error?) -> Void)? = nil) 


  • completion: Called when the devices are synced successfully, or with error.


Registers a device to the current user. setUser must be called before calling this.

func addDevice(token: Data, completion: ((Error?) -> Void)? = nil) 


  • token: Device token, obtained via didRegisterForRemoteNotificationsWithDeviceToken function in AppDelegate.
  • completion: Called when device is successfully registered, or with error.


Removes a registered device from the current user. setUser must be called before calling this.

func removeDevice(id: String, completion: ((Error?) -> Void)? = nil) 


  • id: Device id to be removed. You can obtain registered devices via currentUser.devices. If currentUser.devices is not up-to-date, please make an synchronize call.
  • completion: Called when device is successfully deregistered, or with error.


Sets the provided object as a delegate of this controller.

func setDelegate<Delegate: CurrentChatUserControllerDelegate>(_ delegate: Delegate?) 


Did you find this page helpful?