Skip to main content

current-chat-user-controller-properties

currentUserChangePublisher

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

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

unreadCountPublisher

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

public var unreadCountPublisher: AnyPublisher<UnreadCount, Never> 

observableObject

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

public var observableObject: ObservableObject 

client

The ChatClient instance this controller belongs to.

public let client: ChatClient

currentUser

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? 

unreadCount

The unread messages and channels count for the current user.

public var unreadCount: UnreadCount 

Returns noUnread if currentUser doesn't exist yet.

delegate

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

var delegate: CurrentChatUserControllerDelegate? 

Methods

synchronize(_:)

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) 

Parameters

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

reloadUserIfNeeded(completion:)

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.

Parameters

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

updateUserData(name:imageURL:userExtraData:completion:)

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.

Parameters

  • 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.

synchronizeDevices(completion:)

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

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

Parameters

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

addDevice(token:completion:)

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

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

Parameters

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

removeDevice(id:completion:)

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

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

Parameters

  • 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.

setDelegate(_:)

Sets the provided object as a delegate of this controller.

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

Parameters

Did you find this page helpful?