Klat
  • TalkPlus SDK
  • Android
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • Viewing Channel LIst
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • iOS
    • Getting Started
    • Callback
    • User
      • Create / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
    • What's New
  • Unity
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification
    • Sample Application
  • JavaScript
    • Getting Started
    • Realtime Event
    • Pagination
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete
    • Channel
      • Create / Delete Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
    • Sample Application
    • What's New
  • Flutter
    • Getting Started
    • Callback
    • User
      • Create User / Login
      • Update User Information
      • Block / Unblock
      • Logout
      • Delete User
    • Channel
      • Create Channel
      • View Channel
      • Updating Channel
      • View Channel List
      • Manage Channel Members
      • Join / Leave Channel
      • Messaging
      • Hide / Show Channel
      • Freeze / Unfreeze Channel
      • Transfer Channel Ownership
      • Channel Push Notification Settings
      • Channel Member Data
    • Push Notification (FCM)
  • REST API
    • Getting Started
    • API
      • Users
        • Create User
        • Login (using login token)
        • View User
        • Update User
        • Activate / Deactivate
        • Enable / Disable Push Notification
        • Delete User
        • View Users
        • View Channels
        • Block / Unblock
      • Channel
        • Create Channel
        • View Channel
        • Update Channel
        • Delete Channel
        • View Channel List
        • Manage Channel Members
        • Messaging
        • Hide / Show Channel
        • Channel Freeze / Unfreeze
        • Transfer Channel Ownership
        • Channel Push Notification Settings
      • Bot
        • Create Bot
        • View Bot List
        • View Bot
        • Update Bot
        • Delete Bot
        • View Joined Channel List
        • Messaging
        • Join / Leave Channel
    • Push Notification
    • Rate Limit
  • MISC
    • Webhooks
    • SDK Rate Limit
    • Error Code
    • FAQ
      • Function
      • Spec
Powered by GitBook
On this page
  • 1. Get Public Channels
  • 2. Get Joined Channels
  • 3. Get Hidden Channels
  • 4. Get Total Unread Message Count
  • 5. Mark All Channels As Read
  • 6. Search Joined Channels
  1. JavaScript
  2. Channel

View Channel List

1. Get Public Channels

You can view any public channel even if you are not a member.

The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.

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",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bots": [],
      "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. Get Joined Channels

View currently joined channels.

You can set hasUnread to "true" to see only channels where you have an unread message.

The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.

const numOfRows = 20;

const resp = await client.getChannels({
    limit: numOfRows,
    category: 'important_channels', // optional
    subcategory: 'important_subcategory', // optional
    isFrozen: false, // optional. filter by isFrozen status
    hasUnread: true, // optional. only true is supported. when true, shows only unread channels.
    privateTag: 'tag1', // optional. see: https://en.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. Get Hidden Channels

View currently joined channels that have been marked as hidden.

The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.

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 query 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",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bots": [],
      "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. Get Total Unread Message Count

Get the total number of unread messages from all joined channels.

// get total unread count
const resp = await client.getUnreadCount();
console.log('unreadCount: ', resp.count);

// filter unread message count by channel category, subcategory and privateTag.
// this feature is available starting from v0.5.6.
const filteredResp = await client.getUnreadCount({
    category: 'someCategory', // optional
    subcategory: 'someSubcategory', // optional
    privateTag: 'some personal tag', // optional
});
console.log('filtered unreadCount: ', filteredResp.count);

5. Mark All Channels As Read

Mark as read all unread messages from joined channels.

await client.markAsReadAllChannel();

6. Search Joined Channels

Search joined channels using various filters.

  • You can filter channels by name, category, subcategory, private tag and joined members. You can set hasUnread to "true" to see only channels where you have an unread message.

  • The list is paginated, so to get to the next page, you can pass the ID of the last of the channel objects returned by the previous lookup to get to the next page.

const resp = await client.searchChannels({
    query: 'some channel name',
    members: ['someUserId1', 'someUserId2'], // filter by joined members
    category: 'someCategory', // optional
    subcategory: 'someCategory', // optional
    privateTag: 'myTag',
    isFrozen: false, // optional. filter by isFrozen status
    hasUnread: true, // optional. only true is supported. when true, shows only unread channels.
    lastChannelId: 'someChannelID',
    limit: 10,
});

if (resp.hasNext) {
    // retrieve next page
}

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",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bannedUsers": [
        {
          "id": "user123",
          "username": "john",
          "profileImageUrl": "http://cnd.test.com/123.jpg",
          "lastReadAt": 1583924400,
          "lastSentAt": 1583924400,
          "updatedAt": 1583924400,
          "createdAt": 1583921400
        }
      ],
      "bots": [],
      "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
}
PreviousUpdating ChannelNextManage Channel Members

Last updated 6 months ago