Superteam

Update time: 2024/03/14 18:45:31

Overview

In v6.5.5 and subsequent versions, SDK provides a feature of SuperTeam (superTeam), which is applicable to large-scale team chat.

Supergroup has the similar feature with ordinary team. Supergroup can accommodate more members, get team members by paging, and has the session types and message types. But the supergroup has a relatively weaker feature in team management, and only configures team owner and ordinary team member. The team owner can add or kick out team members, edit team profile and user profile in team. The ordinary team member can edit his user profile in team or voluntarily leave the team. Both have different lower-layer protocols and provide different API.Therefore, the developer shall not confuse them in the application process.

Notes:

  • No DMEO for SuperTeam is available now, so that the developer shall implement this feature independently as needed.
  • For the sake of security, Client SDK cannot create and dismiss a SuperTeam. If needed, please use corresponding server api.
  • To enable the Supergroup feature, please contact the commercial manager.

Initialization parameters

Not all initialization parameters are listed here. Please visit Initialize SDK API to refer to all initialization parameters.

Sample codes

javascriptvar nim = NIM.getInstance({
  syncSuperTeams: true, // It determines to synchronize the list of super teams. The value is "true" by default.
  onSuperTeams: onSuperTeams, // A callback for synchronizing the list of super teams. The array of super teams will be input.
  onSyncCreateSuperTeam: onSyncCreateSuperTeam, // Callback returned after creating a super team by current login user
  onDismissSuperTeam: onDismissSuperTeam, // A callback for dismissing a super team. All team members will receive the callback.
  onUpdateSuperTeamMember: onUpdateSuperTeamMember, // Callback returned after updating information of team members. The object of super team members will be input. But the information is not complete and only contains updated fields. If the current login user updates his nickname in the team at other clients, the callback will also be returned.
  onUpdateSuperTeam: onUpdateSuperTeam, // A callback for updating super teams
  onAddSuperTeamMembers: onAddSuperTeamMembers, // A callback for adding new members to a super team
  onRemoveSuperTeamMembers: onRemoveSuperTeamMembers // A callback for a super team where a member leaves (kicked out or leave voluntarily)
})

function onSuperTeams (superTeams) {
  console.log('Receive the list of super teams', superTeams)
  data.superTeams = nim.mergeTeams(data.superTeams, superTeams)
  onInvalidSuperTeams(superTeams.invalid)
}
function onInvalidSuperTeams (teams) {
  data.superTeams = nim.cutTeams(data.superTeams, teams)
  data.invalidSuperTeams = nim.mergeTeams(data.invalidSuperTeams, teams)
  refreshSuperTeamsUI()
}

function onSyncCreateSuperTeam (team, owner) {
  console.log('Create a super team onSyncCreateSuperTeam ', team, owner)
  data.superTeams = nim.mergeTeams(data.superTeams, team)
  refreshSuperTeamsUI()
  onSuperTeamMembers({
    teamId: team.teamId,
    members: owner
  })
}

function onAddSuperTeamMembers (team, accounts, members) {
  console.log('Add team members onAddSuperTeamMembers ', team, accounts, members)
  if (!accounts && !members) {
    accounts = team.accounts || []
    members = team.members || []
    team = team.team || {}
  }
  var teamId = team.teamId
  /*
   * If other users are added to the team, the list of team members shall be spliced.
   * If you are added to the team, the list of team members shall be synchronized.
   */
  if (accounts.indexOf(data.account) === -1) {
    onSuperTeamMembers({
      teamId: teamId,
      members: members
    })
  } else {
    //
  }
  onSuperTeams(team)
}
function onDismissSuperTeam(obj) {
  console.log('Dismiss a super team onDismissSuperTeam', obj);
  var teamId = obj.teamId
  removeAllSuperTeamMembers(teamId)
  data.superTeams = nim.cutTeams(data.superTeams, obj)
  refreshSuperTeamsUI()
  refreshSuperTeamMembersUI()
}
function onRemoveSuperTeamMembers (obj) {
  console.log('Team members are removed onRemoveSuperTeamMembers ', obj.accounts, obj)
  var teamId = obj.team.teamId
  var accounts = obj.accounts
  var team
  if (!teamId && !accounts) {
    accounts = obj.accounts || []
    team = obj.team || {}
  }
  /*
   * If someone else is kicked out, then remove the team members.
   * If it is yourself who is kicked out, then leave the team.
   */
  if (accounts.indexOf(data.account) === -1) {
    if (team) {
      onSuperTeams(team)
    }
    if (!data.superTeamMembers) {
      data.superTeamMembers = {}
    }
    data.superTeamMembers[teamId] = nim.cutTeamMembersByAccounts(
      data.superTeamMembers[teamId],
      teamId,
      accounts
    )
    refreshSuperTeamMembersUI()
  } else {
    leaveSuperTeam(teamId)
  }
}
function onUpdateSuperTeam(err, msg) {
  console.log('The super team is updated teamId', err, msg)
}
function onUpdateSuperTeamMember (member) {
  console.log('The information of a team member is updated', member) 
}
function leaveSuperTeam (teamId) {
  onInvalidSuperTeams({
    teamId: teamId
  })
  removeAllSuperTeamMembers(teamId)
}

function refreshSuperTeamsUI () {
  
}
function refreshSuperTeamMembersUI () {

}
function removeAllSuperTeamMembers () {

}

Object of Supergroup

The team object contains fields shown as below:

  • teamId: Team ID
  • name: Team name
  • avatar: Team avatar
  • intro: Team introduction
  • announcement: Team announcement
  • owner: Team owner
  • memberNum: The number of team members
  • level: Team member size limit
  • memberUpdateTime: Last update time of team members
  • updateTime: Last update time of team
  • createTime: Creation time of team
  • valid: valid or not
  • validToCurrentUser: valid or not to current team members.

Object of Supergroup member

The object of Supergroup member contains fields as below:

  • teamId: Team ID
  • account: Account
  • type: It means type of SuperTeam member. It has two values, i.e. 'owner' owner and 'ordinary' ordinary members.
  • nickInTeam: Nickname in team
  • active: When a user is invited to an ordinary team, the user cannot see the team because the status is not activated. When a member sends a message, the user can see the team because the status is activated automatically.
  • joinTime: Join time
  • updateTime: Update time
  • custom: It is the third-party extension field, developers can extend it themselves. We recommend packing it into JSON format string.
  • custom: It is the third-party extension field, developers can extend it themselves. We recommend packing it into JSON format string.

Method of joining in Supergroup

A user can be invited to a Supergroup by team owner only, without approval of the user.

Send message in Supergroup

When sending messages in a Supergroup, you only need to replace scene at each "Send message" API with 'superTeam' and replace to with SuperTeam id.

Receive message in Supergroup

Refer to "Receive messages".

Update team

  • The Supergroup only supports update of team name, team avatar, team introduction, team announcement, and custom field.
  • If the Supergroup is updated, all members will receive a team notification message of updateSuperTeam type. For such team notification messages, the from field is account of the user who updates SuperTeam; the to field is corresponding team ID; the team field of attach is updated Supergroup information.
javascriptnim.updateSuperTeam({
  teamId: 123,
  name: 'Team name',
  avatar: 'avatar.png',
  intro: 'Team introduction',
  announcement: 'Team announcement',
  joinMode: 'noVerify',
  beInviteMode: 'needVerify',
  custom: 'Custom field',
  done: updateSuperTeamDone
});
function updateSuperTeamDone(error, team) {
  console.log(error);
  console.log(team);
  console.log('update team' + (!error?'succeeded':'failed'));
}

Invite a user to team

After the operation "Invite a user to team", all Team members will receive a Team notification messages of 'addSuperTeamMembers' type. For such team notification message, the from field is account of the team inviter; the to field is corresponding team ID; the team field under attach is corresponding Object of SuperTeam; theaccounts field under attach is the list of invited accounts; the members field under attach is the list of information of invited team members.

javascriptnim.addSuperTeamMembers({
  teamId: 123,
  accounts: ['a3', 'a4'],
  ps: 'Jon our team’,
  done: addSuperTeamMembersDone
});
function addSuperTeamMembersDone(error, obj) {
  console.log(error, obj);
  console.log('Invite other users to a team' + (!error?'Successful':'failed'));
}

Remove a team member

  • After the operation "Kick out team member", all team members will receive a Team notification message of 'removeTeamMembers' type. For such team notification message, the from field is account of the team administrator who kicks members out of the team; the tofield is the corresponding team ID; the team field under attach is corresponding Object of SuperTeam; the accounts field under attach is the list of kicked-out accounts.
javascriptnim.removeSuperTeamMembers({
  teamId: 123,
  accounts: ['a3', 'a4'],
  done: removeSuperTeamMembersDone
});
function removeSuperTeamMembersDone(error, obj) {
  console.log(error, obj);
  console.log('remove members' + (!error?'succeeded':'failed'));
}

Leave a team

javascriptnim.leaveSuperTeam({
  teamId: 123,
  done: leaveSuperTeamDone
});
function leaveSuperTeamDone(error, obj) {
  console.log(error, obj);
  console.log('voluntarily leave team' + (!error?'succeeded':'failed'));
}

Update my team attribute

The attributes that can be updated now include:

  • nickInTeam: It specifies the nickname in a team. If a member updates his nickname in team, other online SuperTeam members will receive the callback onUpdateSuperTeamMember that is input in "Initializing the SDK".
  • muteTeam: It is a message tip whether to close a team. true means close, but the SDK will still receive the team message because SDK just records this setting and specific operations is determined by the third-party App based on this setting.
  • custom: It is the third-party extension field, developers can extend it themselves. We recommend packing it into JSON format string.

If a member updates his team attribute, all team members will receive the callback onUpdateSuperTeamMember that is configured when initializing the SDK.

javascriptnim.updateInfoInTeam({
  teamId: 123,
  // This parameter is optional
  // nickInTeam: 'Team nickname',
  // Team mute, this parameter is optional
  // muteTeam: true,
  // Third-party extension field
  // custom: '{}'
  done: updateInfoInTeamDone
});
function updateInfoInTeamDone(error, obj) {
  console.log(error, obj);
  console.log('modify my team attribute' + (!error?'succeeded':'failed'));
}

Get a list of Supergroup

  • If developers set syncSuperTeams to false in "Initializing the SDK", then they can not receive onSuperTeams callback, but can invoke this API to get the list of Supergroup.
javascriptnim.getSuperTeams({
  done: getSuperTeamsDone
});
function getSuperTeamsDone(error, teams) {
  console.log(error, teams);
  console.log('Get the list of super teams' + (!error?'Successful':'failed'));
  if (!error) {
    onSuperTeams(teams);
  }
}

Get Supergroup information by team ID

javascriptnim.getSuperTeam({
    teamId: '123',
    done: getSuperTeamDone
});
function getSuperTeamDone(error, obj) {
    console.log(error, obj);
    console.log('Get super teams' + (!error?'Successful':'failed'));
}

Get Supergroup members

  • If a Supergroup has a high number of members, in consideration of performance, the SDK will not synchronize the Supergroup members at initialization.
  • The developer is recommended to enable db to accelerate response when enabling the Supergroup feature. If database is enabled, data will be cached to the database and subsequent updates are incremental.

Related API:

Others

Other APIs and related document links of Supergroup:

Was this page helpful?
Yes
No
  • Overview
  • Initialization parameters
  • Object of Supergroup
  • Object of Supergroup member
  • Method of joining in Supergroup
  • Send message in Supergroup
  • Receive message in Supergroup
  • Update team
  • Invite a user to team
  • Remove a team member
  • Leave a team
  • Update my team attribute
  • Get a list of Supergroup
  • Get Supergroup information by team ID
  • Get Supergroup members
  • Others