채널 내 메시지 목록을 조회할 수 있습니다. 마지막 수신 시간을 기준으로 정렬되어 있습니다.
const resp = await client.getMessages({ channelId:'my_channel', order:'latest',// default: 'latest'. Use 'oldest' to order by oldest messages first limit:10,// how many messages to fetch, default: 20, max: 50});if (resp.hasNext) {const lastMessageId =resp.messages[resp.messages.length-1].id;const moreResp = await client.getMessages({ channelId:'my_channel', lastMessageId: lastMessageId, limit:10, });}
채널 내 파일 메시지 목록만 따로 조회가 가능합니다. 마지막 수신 시간을 기준으로 정렬되어 있습니다.
Pagination 파라미터 (limit, lastMessageId) 용법은 "1. 채널 내 메시지 목록 조회" 사용법과 동일합니다.
(JS SDK v0.2.11 이상부터 지원됩니다)
// previously known prior to JS SDK v0.2.1awaitclient.markRead({channelId:'my_channel'}); // available starting from JS SDK v0.2.1awaitclient.markAsRead({channelId:'my_channel'});
10. 특정 메시지 안 읽은 사용자 수 확인
특정 메시지를 읽지 않은 사용자 수를 확인할 수 있는 기능을 제공합니다.
constchannelGetResp=awaitclient.getChannel({channelId:'demo channel'});constchannelObject=channelGetResp.channel;constmsgResp=awaitclient.getMessages({channelId:'my channel'});constmessageObject=msgResp.messages[0]; // assume that message array is not empty in this exampleconstmsgUnreadCount=client.getMessageUnreadCount({channel: channelObject, message: messageObject});console.log(`msgUnreadCount: ${msgUnreadCount}`); // integer result