Draft messages
Save and retrieve draft messages for channels.
Save a draft
Call channel.saveDraft with the draft content string:
TypeScript
import { DirectChannel } from '@nexconn/chat';
const channel = new DirectChannel('<target-user-id>');
const { code } = await channel.saveDraft('This is a draft message');
if (code === 0) {
console.log('Draft saved');
}
Clear a draft
TypeScript
import { DirectChannel } from '@nexconn/chat';
const channel = new DirectChannel('<target-user-id>');
const { code } = await channel.clearDraft();
if (code === 0) {
console.log('Draft cleared');
}
Get a channel's draft
The draft is stored on the BaseChannel instance. After fetching the channel list, access the draft through the draft property:
TypeScript
import { BaseChannel, DirectChannel } from '@nexconn/chat';
const query = BaseChannel.createChannelsQuery({ pageSize: 20 });
const { code, data: channels } = await query.loadNextPage();
if (code === 0 && channels) {
for (const ch of channels) {
if (ch.draft) {
console.log('Channel has draft:', ch.identifier, ch.draft);
}
}
}