채널 목록 조회

1. 전체 Public 채널 목록 조회

참여중이 아니더라도 전체 public 채널 목록을 조회할 수 있습니다. Pagination 처리가 되어 있어 다음 페이지 조회를 위해서는 이전 조회 시에 리턴받은 channel 객체 중 마지막 객체의 id를 전달하면 그 다음 페이지를 조회할 수 있습니다.

const numOfRows = 20;

const resp = await client.getPublicChannels({
    limit: numOfRows,
    category: 'important_channels', // optional
    subcategory: 'important_subcategory', // optional
});

// fetch more channels
if (resp.hasNext) {
    const lastChannelId = resp.channels[resp.channels.length - 1].id;
    const moreChannelsResp = await client.getPublicChannels({
                                        lastChannelId,
                                        limit: numOfRows,
                                    });
}

// same query but using callback
client.getPublicChannels({}, function(err, resp) {
   if (resp.hasNext) {
        const lastChannelId = resp.channels[resp.channels.length - 1].id;
    } 
});

Response

{
  "channels": [
    {
      "id": "channel123",
      "name": "MyFirstChannel",
      "ownerId": "user123",
      "pushNotificationDisabled": false,
      "imageUrl": "image url",
      "data": {
        "someMetaKey1": "someMetaValue1",
        "someMetaKey2": "someMetaValue2"
      },
      "type": "public",
      "isFrozen": false,
      "memberCount": 1,
      "maxMemberCount": 10,
      "hideMessagesBeforeJoin": true,
      "category": "",
      "subcategory": "",
      "privateTag": "",
      "privateData": "",
      "mutedUsers": [],
      "members": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "pushNotificationDisabled": false,
      "pushNotificationSoundAOS": "",
      "pushNotificationSoundIOS": "",
      "updatedAt": 1583924400,
      "createdAt": 1583921400,
      "unreadCount": 1,
      "lastReadAt": 1583914400,
      "lastMessage": {
        "id": "sdf2l5s9j",
        "channelId": "channel123",
        "userId": "user456",
        "username": "myUsername",
        "profileImageUrl": "http://cdn.test.com/123.jpg",
        "type": "message",
        "text": "Hello world",
        "data": {
          "customField": "customData"
        },
        "parentMessage": {},
        "parentMessageId": "",
        "reactions": {"happy": ["user1"]},
        "createdAt": 1583921400
      }
    }
  ],
  "hasNext": false
}

2. 현재 참여 중인 채널 목록 조회

현재 참여 중인 채널 목록을 조회할 수 있습니다. Pagination 처리가 되어 있어 다음 페이지 조회를 위해서는 이전 조회 시에 리턴받은 channel 객체 중 마지막 객체의 id를 전달하면 그 다음 페이지를 조회할 수 있습니다.

const numOfRows = 20;

const resp = await client.getChannels({
    limit: numOfRows,
    category: 'important_channels', // optional
    subcategory: 'important_subcategory', // optional
    isFrozen: true, // optional. isFrozen 상태가 일치하는 채널만 조회
    privateTag: 'tag1', // optional. see: https://docs.talkplus.io/javascript/channel/member-settings
});

if (resp.hasNext) {
    const lastChannelId = resp.channels[resp.channels.length - 1].id;
    const moreChannelsResp = await client.getChannels({lastChannelId, limit: numOfRows});
}

// same query but using callback
client.getChannels({}, function(err, resp) {
   if (resp.hasNext) {
        const lastChannelId = resp.channels[resp.channels.length - 1].id;
    } 
});

3. 현재 참여 중인 채널 목록 검색

참여 중인 채널 목록을 1) 채널명이나, 2)특정 사용자가 참여하고 있는 지 여부로 필터링 해서 열람할 수 있습니다. Pagination 파라미터 (limit, lastChannelId) 사용법은 동일합니다. (해당 기능은 JS SDK v0.2.13 이상부터 지원됩니다)

const resp = await client.searchChannels({
    query: '검색하고자 하는 채널명',
    members: ['someUserId1', 'someUserId2'], // 그 중에 특정 사용자가 참여하고 있는 채널만
    isFrozen: true, // optional. isFrozen 상태가 일치하는 채널만 조회
    limit: 10,
});

// 그 다음 페이지 조회 시
if (resp.hasNext) {
    const lastChannelId = resp.channels[resp.channels.length - 1].id;
    const moreChannelsResp = await client.searchChannels({
        query: '검색하고자 하는 채널명',
        members: ['someUserId1', 'someUserId2'], // 그 중에 특정 사용자가 참여하고 있는 채널만
        limit: 10,
    });
}

Response

{
  "channels": [
    {
      "id": "channel123",
      "name": "MyFirstChannel",
      "ownerId": "user123",
      "pushNotificationDisabled": false,
      "imageUrl": "image url",
      "data": {
        "someMetaKey1": "someMetaValue1",
        "someMetaKey2": "someMetaValue2"
      },
      "type": "private",
      "isFrozen": false,
      "memberCount": 1,
      "maxMemberCount": 10,
      "hideMessagesBeforeJoin": true,
      "category": "",
      "subcategory": "",
      "privateTag": "",
      "privateData": "",
      "mutedUsers": [],
      "members": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "pushNotificationDisabled": false,
      "pushNotificationSoundAOS": "",
      "pushNotificationSoundIOS": "",
      "updatedAt": 1583924400,
      "createdAt": 1583921400,
      "unreadCount": 1,
      "lastReadAt": 1583914400,
      "lastMessage": {
        "id": "sdf2l5s9j",
        "channelId": "channel123",
        "userId": "user456",
        "username": "myUsername",
        "profileImageUrl": "http://cdn.test.com/123.jpg",
        "type": "message",
        "text": "Hello world",
        "data": {
          "customField": "customData"
        },
        "parentMessage": {},
        "parentMessageId": "",
        "reactions": {"happy": ["user1"]},
        "createdAt": 1583921400
      }
    }
  ],
  "hasNext": false
}

4. Hidden 처리한 채널 목록 조회

현재 참여중인 채널 중, 숨김 처리한 목록을 조회할 수 있습니다. Pagination 처리가 되어 있어 다음 페이지 조회를 위해서는 이전 조회 시에 리턴받은 channel 객체 중 마지막 객체의 id를 전달하면 그 다음 페이지를 조회할 수 있습니다.

const numOfRows = 20;

const resp = await client.getHiddenChannels({limit: numOfRows});
if (resp.hasNext) {
    const lastChannelId = resp.channels[resp.channels.length - 1].id;
    const moreChannelsResp = await client.getHiddenChannels({lastChannelId, limit: numOfRows});
}

// same example but using callback
client.getHiddenChannels({}, function(err, resp) {
   if (resp.hasNext) {
        const lastChannelId = resp.channels[resp.channels.length - 1].id;
    } 
});

Response

{
  "channels": [
    {
      "id": "channel123",
      "name": "MyFirstChannel",
      "ownerId": "user123",
      "pushNotificationDisabled": false,
      "imageUrl": "image url",
      "data": {
        "someMetaKey1": "someMetaValue1",
        "someMetaKey2": "someMetaValue2"
      },
      "type": "public",
      "isFrozen": false,
      "memberCount": 1,
      "maxMemberCount": 10,
      "hideMessagesBeforeJoin": true,
      "category": "",
      "subcategory": "",
      "privateTag": "",
      "privateData": "",
      "mutedUsers": [],
      "members": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "data": {},
          "memberInfo": {},
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "pushNotificationDisabled": false,
      "pushNotificationSoundAOS": "",
      "pushNotificationSoundIOS": "",
      "updatedAt": 1583924400,
      "createdAt": 1583921400,
      "unreadCount": 1,
      "lastReadAt": 1583914400,
      "lastMessage": {
        "id": "sdf2l5s9j",
        "channelId": "channel123",
        "userId": "user456",
        "username": "myUsername",
        "profileImageUrl": "http://cdn.test.com/123.jpg",
        "type": "message",
        "text": "Hello world",
        "data": {
          "customField": "customData"
        },
        "parentMessage": {},
        "parentMessageId": "",
        "reactions": {"happy": ["user1"]},
        "createdAt": 1583921400
      }
    }
  ],
  "hasNext": false
}

5. 안 읽은 메시지 수 조회

현재 참여중인 모든 채널의 총 안 읽은 메시지 숫자를 조회할 수 있습니다.

const resp = await client.getUnreadCount();

console.log('unreadCount: ', resp.count);

6. 전체 채널 메시지 읽음 확인

현재 참여중인 모든 채널에 일괄적으로 메시지 읽음 확인 처리를 합니다. (JS SDK v0.2.16 이상부터 지원되는 기능입니다)

await client.markAsReadAllChannel();

Last updated