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
- Objective-C
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.")
}
}
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel saveDraft:@"This is the draft content"
completion:^(BOOL isSaved, NCError *error) {
if (isSaved) {
NSLog(@"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
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.reload { updatedChannel, error in
let draft = updatedChannel?.draft
print("Draft: \(draft ?? "")")
}
Objective C
[channel reloadWithCompletion:^(NCBaseChannel *updatedChannel, NSError *error) {
NSString *draft = updatedChannel.draft;
NSLog(@"Draft: %@", draft);
}];
Clear a draft
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.clearDraft { isCleared, error in
if isCleared {
print("Draft cleared.")
}
}
Objective C
[channel clearDraftWithCompletion:^(BOOL isCleared, NCError *error) {
if (isCleared) {
NSLog(@"Draft cleared.");
}
}];