Skip to main content

Channel draft

Save and retrieve draft text for a channel. Saving a draft updates the channel's operationTime, which can move it to the top of the list.

Save a draft

Call saveDraft(_:completion:) on a channel instance:

swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.saveDraft("This is the draft content") { isSaved, error in
if isSaved {
print("Draft saved.")
}
}

Get a draft

The draft is available as the draft property on the channel object. Reload the channel to get the latest value:

swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.reload { updatedChannel, error in
let draft = updatedChannel?.draft
print("Draft: \(draft ?? "")")
}

Clear a draft

swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.clearDraft { isCleared, error in
if isCleared {
print("Draft cleared.")
}
}