Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <meta name="description" content="Moderation">
    <title>Circuit JS SDK</title>
    <script src="https://unpkg.com/circuit-sdk@beta"></script>
    <script src="https://rawgit.com/circuit/js-sdk/master/jsbin-template.js"></script>
    <link rel="stylesheet" href="https://rawgit.com/circuit/js-sdk/master/jsbin-template.css">
  </head>
  <body>
    <div id="template"></div>
    <section id="main" style="display:none">
      <input id="email" type="text" placeholder="email of user to add">
      <button id="start">Start</button>
    </section>
</body>
</html>
 
/*jshint esnext: true */
/*jshint expr: true */
// Create client instance
const client = new Circuit.Client({
  domain: jsBinTpl.domain,       // read domain from url
  client_id: jsBinTpl.client_id, // get client_id for domain
  scope: 'ALL'
});
// Template for Circuit JSBin examples. Builds generic part of page incl. login button.
const {logonButton, logoutButton, print} = jsBinTpl.init(client, template, {
  title: 'Circuit JS SDK: Moderation',
  description: 'Creates a conversation, turns on moderation and grants other user moderator rights.',
  apiMethods: ['moderate', 'grantModeratorRights'],
  prerequisites: []
});
// Local variables
let _callId;
logonButton.addEventListener('click', () => {
  client.logon()
  .then(user => print(`Successfully authenticated as ${user.displayName}`))
  .catch(print);
});
logoutButton.addEventListener('click', () => {
  client.logout().catch(print);
});
// Create group conversation with user as other participant, then turns on moderation
// on the conversation and grants the other participant moderation rights
start.addEventListener('click', () => {
  let userPromise = client.getUserByEmail(email.value);
  let convPromise = userPromise.then(user => client.createGroupConversation([user.userId], 'Test Conv'));
  let moderatePromise = convPromise.then(conv => client.moderateConversation(conv.convId));
  
  let finalPromise = Promise.all([userPromise, convPromise, moderatePromise])
  .then(([user, conv, mod]) => client.grantModeratorRights(conv.convId, user.userId));
  
  Promise.all([userPromise, convPromise, finalPromise])
  .then(([user, conv]) => {
    print(`Granted '${user.displayName}' moderator rights on '${conv.topic}'`);
    return client.getConversationById(conv.convId);
  })
  .then(conv => {
    print(`Conv. is moderated: ${conv.isModerated}`);
    print(`Am I a moderator  : ${conv.additionalUserData.moderator}`);
    print(`Moderator userIds : ${conv.moderators.join(', ')}`);
  })
  .catch(print);
});
/*
Circuit.supportedEvents && Circuit.supportedEvents.forEach(e => {
    client.addEventListener(e, evt => print(`Received ${e} event:`, evt));
});
*/
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
rogerupro
0viewers