Getting a List of Topics

Getting a list of application-scope topics

You can get a list of all application scope topic. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all application scope topics.

  • function listAll(userProc) {
      var listRecurr = function(params) {
        var topicList = params[0];
        var nextPaginationKey = params[1];
        userProc(topicList);
        if (nextPaginationKey == null) {
          return Promise.resolve();
        }
        // Get the next page of the topic list.
        return Kii.listTopics(null, nextPaginationKey);
      };
      // Get the first page of the topic list.
      return Kii.listTopics().then(listRecurr);
    }
    
    // Get a topic list.
    listAll(function(topicList) {
      for (var i = 0; i < topicList.length; i++) {
        // Do something.
        var topic = topicList[i];
      }
    }).catch(
      function(error) {
        // Handle the error.
        var errorString = error.message;
      }
    );
  • var listCallbacks = {
      success: function(topicList, nextPaginationKey) {
        for (var i = 0; i < topicList.length; i++) {
          // Do something.
          var topic = topicList[i];
        }
        if (nextPaginationKey != null) {
         // Get the next page of the topic list.
         Kii.listTopics(listCallbacks, nextPaginationKey);
        }
      },
      failure: function(errorString) {
        // Handle the error.
      }
    }
    
    // Get the first page of the topic list.
    Kii.listTopics(listCallbacks);

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Check the nextPaginationKey to determine if there exist more topics to get. If there are ones, execute the listTopics method again with the nextPaginationKey set as a parameter.

Getting a list of group-scope topics

You can get a list of all topics in the specified group scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a group scope.

  • function listAll(group, userProc) {
      var listRecurr = function(params) {
        var topicList = params[0];
        var nextPaginationKey = params[1];
        userProc(topicList);
        if (nextPaginationKey == null) {
          return Promise.resolve();
        }
        // Get the next page of the topic list.
        return group.listTopics(null, nextPaginationKey).then(listRecurr);
      };
      // Get the first page of the topic list.
      return group.listTopics().then(listRecurr);
    }
    
    // Instantiate an existing group.
    var group = KiiGroup.groupWithURI("Set the URI of an existing group here");
    
    // Get a topic list.
    listAll(group, function(topicList) {
        for (var i = 0; i < topicList.length; i++) {
        // Do something.
          var topic = topicList[i];
        }
    }).catch(
      function(error) {
        // Handle the error.
        var theGroup = error.target;
        var errorString = error.message;
      }
    );
  • // Instantiate an existing group.
    var group = KiiGroup.groupWithURI("Set the URI of an existing group here");
    
    var listCallbacks = {
      success: function(topicList, nextPaginationKey) {
        for (var i = 0; i < topicList.length; i++) {
          // Do something.
          var topic = topicList[i];
        }
        if (nextPaginationKey != null) {
           // Get the next page of the topic list.
           group.listTopics(listCallbacks, nextPaginationKey);
        }
      },
      failure: function(errorString) {
        // Handle the error.
      }
    }
    
    // Get the first page of the topic list.
    group.listTopics(listCallbacks);

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Check the nextPaginationKey to determine if there exist more topics to get. If there are ones, execute the listTopics method again with the nextPaginationKey set as a parameter.

Getting a list of user-scope topics

You can get a list of all topics in the specified user scope. If there are more than 50 topics, you need to get the topic list in multiple pages with the pagination.

The following is the sample code for getting a list of all topics in a user scope.

  • function listAll(user, userProc) {
      var listRecurr = function(params) {
        var topicList = params[0];
        var nextPaginationKey = params[1];
        userProc(topicList);
        if (nextPaginationKey == null) {
          return Promise.resolve();
        }
        // Get the next page of the topic list.
        return user.listTopics(null, nextPaginationKey).then(listRecurr);
      };
      // Get the first page of the topic list.
      return user.listTopics().then(listRecurr);
    }
    
    // Get the currently logged-in user.
    var user = KiiUser.getCurrentUser();
    
    // Get a topic list.
    listAll(user, function(topicList) {
        for (var i = 0; i < topicList.length; i++) {
        // Do something.
          var topic = topicList[i];
        }
    }).catch(
      function(error) {
        // Handle the error.
        var theUser = error.target;
        var errorString = error.message;
      }
    );
  • // Get the currently logged-in user.
    var user = KiiUser.getCurrentUser();
    
    var listCallbacks = {
      success: function(topicList, nextPaginationKey) {
        for (var i = 0; i < topicList.length; i++) {
          // Do something.
          var topic = topicList[i];
        }
        if (nextPaginationKey != null) {
          // Get the next page of the topic list.
          user.listTopics(listCallbacks, nextPaginationKey);
        }
      },
      failure: function(errorString) {
        // Handle the error.
      }
    }
    
    // Get the first page of the topic list.
    user.listTopics(listCallbacks);

This is the brief explanation of the sample code:

  • Execute the listTopics method to get a list of topics.
  • Check the nextPaginationKey to determine if there exist more topics to get. If there are ones, execute the listTopics method again with the nextPaginationKey set as a parameter.