Team Feature

Update time: 2021/12/14 08:23:54

Teams

Overview

CommsEase provides two types of team chat, namely ordinary team (kNIMTeamTypeNormal) and advanced team (kNIMTeamTypeAdvanced). The advanced team has more operation permissions, and the interfaces are kept consistent under ordinary operations. In team chat, the ID of the current session is the ID of the team.

  • Ordinary team

Similar to a discussion team or quick group session in the current IM chat application, an ordinary team does not have full team privileges. Each ordinary team can only have one administrator. The administrator can add members to and remove members from a team. Members can add members without the consent of the team members.

  • Advanced team

Advanced team is subject to more limitations on permission which is granted to the owner, the administrator and, team members. To add a new member, his/her acceptance of invitation is required The information about an advanced team members can be synced in real time, and team switch setting field and third-party extension field (for storage and pass-through only) and the third-party server extension field (set only using the server interface, and read only to the client) are made available.

  • Comparison of team operation permissions
Team operation ordinary team Advanced team
Invite member Anyone Team owner, the administrator
Kick out member Team owner Team owner, the administrator (an administrator cannot kick any other administrator out)
Dismiss team Team owner Team owner
Leave Anyone administrator, ordinary members
Process join application / Team owner, the administrator
Modify your own display name in the team / Anyone
Modify others' profile names in the team / Team owner, the administrator
Modify team name Anyone Team owner, the administrator
Modify team announcement / Team owner, the administrator
Modify team introduction / Team owner, the administrator
Update verification method / Team owner, the administrator
Add (remove) administrator / Team owner
Change the team owner / Team owner
Mute member / Team owner, the administrator
Update team profile picture / Team owner, the administrator

Team chat messages

Except for the message type (kNIMMsgKeyToType), team chat and double chat are the same in terms of sending, receiving and managing messages.

Get a team

SDK synchronizes local Team profile when the program is started, so team can be acquired just by calling the local cache interface. SDK provides interfaces to get all teams and to get team by ID. SDK also provides interfaces for remote access to team messages.

  • Get team ID list locally

      void nim_team_query_all_my_teams_async(const char *json_extension, nim_team_query_all_my_teams_cb_func cb, const void *user_data);
    
  • Get local team list (information)

      void nim_team_query_all_my_teams_info_async(const char *json_extension, nim_team_query_all_my_teams_info_cb_func cb, const void *user_data);
    

    After V2.7.0, the information about invalid teams (you are not in the team or the team has been dismissed) cached locally can be obtained through this interface:

      Json::Value values;
      Json::FastWriter fw;
      values[kNIMTeamSearchKeyIncludeInvalid] = true;
      exten = values.toStyledString();
      nim_team_query_all_my_teams_info_async(exten.c_str(), &QueryAllMyTeamsInfoCallback, nullptr);
    

    After parsing the Team profile json in the callback feature, the developer judges whether the team still exists based on thekNIMTeamInfoKeyValidFlag field, and if so, judges whether he/she is still in the team based on field kNIMSuperteamInfoKeyMemberValid.

  • Get Team profile from the server

      void nim_team_query_team_info_online_async(const char *tid, const char *json_extension, nim_team_opt_cb_func cb, const void *user_data);
    

Create a team

CommsEase has two team types: ordinary team and advanced team. The two types are the same in terms of message features, but different in terms of management.

In an ordinary team, all users can invite new members to the team, but only the owner can kick members out.

Fixed team has a complete member permission system and management features. Both teams are created using the same interface by inputting different types of parameters.

void nim_team_create_team_async(
const char *team_info, // team profile
const char *jsonlist_uids, // member invitation
const char *invitation_postscript, // invitation postscript
const char *json_extension, // additional data
nim_team_opt_cb_func cb,
const void *user_data);

For example:

C++

void OnTeamEventCallback(const nim::TeamEvent& result)
{
	...
}

void foo()
{
	std::list<std::string> id_list;
	id_list.push_back("test1");
	id_list.push_back("test2");

	nim::TeamInfo tinfo;
	tinfo.SetName("test");
	tinfo.SetType(nim::kNIMTeamTypeNormal);
	nim::Team::CreateTeamAsync(tinfo, id_list, "", &OnTeamEventCallback);
}

C#

void foo()
{
	NIM.Team.NIMTeamInfo tinfo = new NIM.Team.NIMTeamInfo();
	tinfo.Name = teamNameBox.Text;
	tinfo.Introduce = teamIntroBox.Text;
	tinfo.TeamType = NIM.Team.NIMTeamType.kNIMTeamTypeAdvanced;
	string[] uids = { "test1", "test2"};
	if (uids.Any())
	{
	    NIM.Team.TeamAPI.CreateTeam(tinfo, uids, textBox1.Text, (a) =>
	    {
	       
	    });
	}
}

C

void CallbackCreateTeam(int error, int team_event, const char *tid, const char* str, const char *json_exten, const void *user_data)
{
	...
}	

typedef void(*nim_team_create_team_async)(const char *team_info, const char *jsonlist_uids, const char *invitation_postscript, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);

void foo()
{
	Json::Value team_info;
	team_info[kNIMTeamInfoKeyName] = ; // team name
	team_info[kNIMTeamInfoKeyType] = ; // team type
	team_info[kNIMTeamInfoKeyIntro] = ; // team introduction
	team_info[kNIMTeamInfoKeyJoinMode] = ; // team authentication method
	team_info[kNIMTeamInfoKeyAnnouncement] = ; // team announcement

	Json::Value team_member;
	team_member.append("litianyi01");	
	team_member.append("litianyi02");

	nim_team_create_team_async func = (nim_team_create_team_async) GetProcAddress(hInst, "nim_team_create_team_async");
	func(team_info.toStyledString().c_str(), team_member.toStyledString().c_str(), "welcome to new team", nullptr, &CallbackCreateTeam, nullptr);
}

Join a team

Users can join a team voluntarily or passively by accepting invitations.

  • Invite users to team:

    In an ordinary team, after the request, the invitee will be added to the team. In an advanced team, CommsEase server will send a system message to the invited user who can either accept or reject to join the team.

    C++

      void OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	···
      }
    
      void foo()
      {
      	const std::list<std::string> friend_list;
      	friend_list.push_back("test1");
      	friend_list.push_back("test2");
      	nim::Team::InviteAsync("123445", friend_list, "", &OnTeamEventCallback);
      }
    

    C#

      void foo()
      {
      	string[] friend_list = { "test1", "test2" };
      	NIM.Team.TeamAPI.Invite("12345", friend_list, "", (r) =>
      	{
      	    if (r.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResTeamInviteSuccess)
      	    {
      	        foreach (var ID in r.TeamEvent.IdCollection)
      	        {
      	            ···
      	        }
      	    }
      	    else
      	    {
      	        MessageBox.Show("failed:" + r.TeamEvent.ResponseCode.ToString());
      	    }
      	});
      }
    

    C

      void CallbackTeamChange(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	//
      }
    
      typedef void(*nim_team_invite_async)(const char *tid, const char *jsonlist_uids, const char *invitation_postscript, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	Json::Value friend_list;
      	friend_list.append("litianyi01");	
      	friend_list.append("litianyi02");
    
      	nim_team_invite_async func = (nim_team_invite_async) GetProcAddress(hInst, "nim_team_invite_async");
      	func("12345", friend_list.toStyledString().c_str(), "welcome to new team", "", &CallbackCreateTeam, nullptr);
      }	
    
  • Accept invitation (only for advanced team)

    C++

      void TeamEventCb(const nim::TeamEvent& team_event)
      {
      	···
      }
    
      void foo()
      {
      	nim::Team::AcceptInvitationAsync("12345", "my_id", &TeamEventCb);
      }
    

    C#

      NIM.Team.TeamAPI.AcceptTeamInvitation("12345", "my_id", (x) =>
      {
    
      });
    

    C

      void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	···
      }
    
      typedef void(*nim_team_accept_invitation_async)(const char *tid, const char *invitor, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_accept_invitation_async func = (nim_team_accept_invitation_async) GetProcAddress(hInst, "nim_team_accept_invitation_async");
      	func("12345", "my_id", "", &TeamEventCb, nullptr);
      }
    
  • Reject invitation (only for advanced team)

    C++

      void TeamEventCb(const nim::TeamEvent& team_event)
      {
      	···
      }
    
      void foo()
      {
      	nim::Team::RejectInvitationAsync("12345", "my_id", "", &TeamEventCb);
      }
    

    C#

      NIM.Team.TeamAPI.RejectTeamInvitation(string tid, string invitor, string reason, TeamChangedNotificationDelegate action);
    

    C

      void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	···
      }
    
      typedef void(*nim_team_reject_invitation_async)(const char *tid, const char *invitor, const char *reason, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_reject_invitation_async func = (nim_team_reject_invitation_async) GetProcAddress(hInst, "nim_team_reject_invitation_async");
      	func("12345", "my_id", "", "", &TeamEventCb, nullptr);
      }
    
  • Voluntarily apply for joining (only for advanced team):

    After the request, CommsEase server will send a system message to the team administrator who can either accept or reject the application.

    C++

      void OnApplyJoinCb(const nim::TeamEvent& team_event)
      {
      	QLOG_APP(L"apply join: {0}") << team_event.res_code_;
    
      	switch (team_event.res_code_)
      	{
      	case nim::kNIMResTeamAlreadyIn:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResSuccess:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResTeamApplySuccess:
      		···
      		break;
      	default:
      	{
      		···
      	}
      	break;
      	}
      }
    
      void foo()
      {
      	nim::Team::ApplyJoinAsync("12345", "", &OnApplyJoinCb);
      }
    

    C#

      NIM.Team.TeamAPI.ApplyForJoiningTeam("12345", "", (x) =>
      {
    
      });
    

    C

      void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	···
      }
    
      typedef void(*nim_team_apply_join_async)(const char *tid, const char *reason, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_apply_join_async func = (nim_team_apply_join_async) GetProcAddress(hInst, "nim_team_apply_join_async");
      	func("12345", "", "", &TeamEventCb, nullptr);
      }
    
  • Accept application (only for advanced team)

    C++

      void TeamEventCb(const nim::TeamEvent& team_event)
      {
      	switch (team_event.res_code_)
      	{
      	case nim::kNIMResTeamAlreadyIn:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResSuccess:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResTeamApplySuccess:
      		···
      		break;
      	default:
      	{
      		···
      	}
      	break;
      	}
      }
    
      void foo()
      {
      	nim::Team::PassJoinApplyAsync("12345", "my_id", &TeamEventCb);
      }
    

    C#

      NIM.Team.TeamAPI.AgreeJoinTeamApplication("12345", "my_id", (x) =>
      {
    
      });
    

    C

      void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	···
      }
    
      typedef void(*nim_team_pass_join_apply_async)(const char *tid, const char *applicant_id, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_pass_join_apply_async func = (nim_team_pass_join_apply_async) GetProcAddress(hInst, "nim_team_pass_join_apply_async");
      	func("12345", "my_id", "", &TeamEventCb, nullptr);
      }
    
  • Reject application (only for advanced team)

    C++

      void TeamEventCb(const nim::TeamEvent& team_event)
      {
      	switch (team_event.res_code_)
      	{
      	case nim::kNIMResTeamAlreadyIn:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResSuccess:
      	{
      		···
      	}
      	break;
      	case nim::kNIMResTeamApplySuccess:
      		···
      		break;
      	default:
      	{
      		···
      	}
      	break;
      	}
      }
    
      void foo()
      {
      	nim::Team::RejectJoinApplyAsync("12345", "sender_id", "", &TeamEventCb);
      }
    

    C#

      NIM.Team.TeamAPI.RejectJoinTeamApplication("12345", "sender_id", "", (x) =>
      {
    
      });
    

    C

      void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	···
      }
    
      typedef void(*nim_team_reject_join_apply_async)(const char *tid, const char *applicant_id, const char *reason, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_reject_join_apply_async func = (nim_team_reject_join_apply_async) GetProcAddress(hInst, "nim_team_reject_join_apply_async");
      	func("12345", "sender_id", "", &TeamEventCb, nullptr);
      }
    

Remove a member from a team

In an ordinary team, only the owner can kick members out. In an advanced team, the owner and administrators can kick members out, but the administrators cannot kick the owner and other administrators out.

C++

void TeamEventCb(const nim::TeamEvent& team_event)
{
	···
}

void foo()
{
	std::list<std::string> uids_list;
	uids_list.push_back("test_user");
	nim::Team::RejectJoinApplyAsync("12345", uids_list, &TeamEventCb);
}

C#

NIM.Team.TeamAPI.KickMemberOutFromTeam("12345", new string[] {"test_user"}, (a) =>
{
    if (a.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
    {
        ···
    }
});

C

void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
{
	···
}

typedef void(*nim_team_kick_async)(const char *tid, const char *jsonlist_uids, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);

void foo()
{
	nim_team_kick_async func = (nim_team_kick_async) GetProcAddress(hInst, "nim_team_kick_async");

	Json::Value json_value;
	json_value.append("litianyi01");	
	json_value.append("litianyi02");

	func("12345", json_value.toStyledString().c_str(), "", &TeamEventCb, nullptr);
}

Voluntary leave the team

Voluntary leave the team is allowed for all users other than the owner.

C++

void TeamEventCb(const nim::TeamEvent& team_event)
{
	···
}

void foo()
{
	nim::Team::LeaveAsync("12345", &TeamEventCb);
}

C#

NIM.Team.TeamAPI.LeaveTeam("12345", (ret) =>
{
    if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
    {
        ···
    }
});

C

void TeamEventCb(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
{
	···
}

typedef void(*nim_team_leave_async)(const char *tid, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);

void foo()
{
	nim_team_leave_async func = (nim_team_leave_async) GetProcAddress(hInst, "nim_team_leave_async");

	func("12345", "", &TeamEventCb, nullptr);
}

Edit the team profile

In an ordinary team, all users can update the team name. In an advanced team, only the owner and administrators can update the team name and other team profile.

void nim_team_update_team_info_async(const char *tid, const char *json_info, const char *json_extension, nim_team_opt_cb_func cb, const void *user_data);

For example:

C++

void OnUpdateBroadCb(const nim::TeamEvent& team_event)
{
	if (team_event.res_code_ == 200)
	{
		···
	}
}

void foo()
{
	Json::Value broad;
	broad["title"] = "title";
	broad["content"] = "content";
	broad["creator"] = "test_user";

	Json::Value broads;
	broads.append(broad);

	Json::FastWriter writer;
	nim::TeamInfo param;
	param.SetAnnouncement(writer.write(broads));
	param.SetTeamID("tid_");

	nim::Team::UpdateTeamInfoAsync("tid_", param, &OnUpdateBroadCb);
}

C#

void foo()
{
	NIM.Team.NIMTeamInfo tinfo = new NIM.Team.NIMTeamInfo();
	tinfo.Announcement = "announcement";
	tinfo.TeamId = "tid";
	
	NIM.Team.TeamAPI.UpdateTeamInfo("tid", tinfo, (ret) =>
	{
	    if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
	    {
	        ···
	    }
	});
}

C

void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
{
	if (error == kNIMResSuccess)
	{
		...
	}
	else
	{
		...
	}
}

typedef void(*nim_team_update_team_info_async)(const char *tid, const char *json_info, const char *json_extension, nim_team_event_cb_func cb_func, const void* user_data);

void foo()
{
	Json::Value values;
	values[kNIMTeamInfoKeyID] = "tid";	
	values[kNIMTeamInfoKeyAnnouncement] = "123"; //Modify announcement. Similarly, you can change team name. See the api documentation for team profile

	nim_team_update_team_info_async func = (nim_team_update_team_info_async) GetProcAddress(hInst, "nim_team_update_team_info_async");
	func("tid", values.toStyledString().c_str(), nullptr, &CallbackTeamOperate, nullptr);
}

Manage team permissions

Owner of an advanced team can manage team permissions, including:

  • Promote administrator (only for advanced team):

    C++

      void OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	···
      }
    
      foo()
      {
      	std::list<std::string> uids_list;
      	uids_list.push_back("user_id");
      	nim::Team::AddadministratorsAsync("tid_", uids_list, &OnTeamEventCallback);
      }
    

    C#

      NIM.Team.TeamAPI.AddTeamadministrators("_teamId", new string[] {"uid"}, (ret) =>
      {
          ···
      });
    

    C

      void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
      {
      	if (error == kNIMResSuccess)
      	{
      		...
      	}
      	else
      	{
      		...
      	}
      }
    
      typedef void(*nim_team_add_administrators_async)(const char *tid, const char *jsonlist_admin_ids, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	Json::Value values;
      	values.append("user_id");
    
      	nim_team_add_administrators_async func = (nim_team_add_administrators_async) GetProcAddress(hInst, "nim_team_add_administrators_async");
      	func("tid", values.toStyledString().c_str(), nullptr, &CallbackTeamOperate, nullptr);
      }
    
  • Remove administrator (only for advanced team):

    C++

      void OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	···
      }
    
      foo()
      {
      	std::list<std::string> uids_list;
      	uids_list.push_back("user_id");
      	nim::Team::RemoveadministratorsAsync("tid_", uids_list, &OnTeamEventCallback);
      }
    

    C#

      NIM.Team.TeamAPI.RemoveTeamadministrators("_teamId", new string[] {"uid"}, (ret) =>
      {
          ···
      });
    

    C

      void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
      {
      	if (error == kNIMResSuccess)
      	{
      		...
      	}
      	else
      	{
      		...
      	}
      }
    
      typedef void(*nim_team_remove_administrators_async)(const char *tid, const char *jsonlist_admin_ids, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	Json::Value values;
      	values.append("user_id");
    
      	nim_team_remove_administrators_async func = (nim_team_remove_administrators_async) GetProcAddress(hInst, "nim_team_remove_administrators_async");
      	func("tid", values.toStyledString().c_str(), nullptr, &CallbackTeamOperate, nullptr);
      }
    
  • Transfer team (only for advanced team):

    C++

      void OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	···
      }
    
      foo()
      {
      	nim::Team::TransferTeamAsync("tid_", "user_id", false, &OnTeamEventCallback);
      }
    

    C#

      NIM.Team.TeamAPI.TransferTeamAdmin("_teamId", "user_id", false, (ret) =>
      {
          ···
      });
    

    C

      void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
      {
      	if (error == kNIMResSuccess)
      	{
      		...
      	}
      	else
      	{
      		...
      	}
      }
    
      typedef void(*nim_team_transfer_team_async)(const char *tid, const char *new_owner, bool is_leave, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_transfer_team_async func = (nim_team_transfer_team_async) GetProcAddress(hInst, "nim_team_transfer_team_async");
      	func("tid", "user_id", false, nullptr, &CallbackTeamOperate, nullptr);
      }
    

Team member

  • Get team member list. The list only contains team related data which is maintained by the CommsEase server, developers can combine the data with their own data and display it.

      void nim_team_query_team_members_async(const char *tid, bool include_user_info, const char *json_extension, nim_team_query_team_members_cb_func cb, const void *user_data);
    

    For example:

    C++

      void OnGetTeamMembers(const std::string& team_id, int count, const std::list<nim::TeamMemberProperty>& team_member_list)
      {
      	for (const auto& member : team_member_list)
      	{
      		···
      	}
      }
    
      foo()
      {
      	nim::Team::QueryTeamMembersAsync("tid_", &OnGetTeamMembers);
      }
    

    C#

      NIM.Team.TeamAPI.QueryTeamMembersInfo("_teamId", (info) =>
      {
          if (info != null)
          {
              foreach (var i in info)
              {
                  ···
              }
          }
      });
    

    C

      void CallbackQueryTeamMembersCb(const char * tid, int count, bool include_user_info, const char* str, const char *json_exten, const void *user_data)
      {
      	// parse str
      }
    
      typedef void(*nim_team_query_team_members_async)(const char *tid, bool include_user_info, const char *json_extension, nim_team_query_team_members_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_query_team_members_async func = (nim_team_query_team_members_async) GetProcAddress(hInst, "nim_team_query_team_members_async");
      	func("tid", include_user_info ? true : false, nullptr, &CallbackQueryTeamMembersCb, nullptr);
      }
    

    Following V2.8.0, developers can get information about invalid team members (not in the team) in the local cache by calling this interface:

      Json::Value values;
      Json::FastWriter fw;
      values[kNIMTeamSearchKeyIncludeInvalid] = true;
      exten = values.toStyledString();
      //include_user_info must be true
      func("tid", true, exten.c_str(), &CallbackQueryTeamMembersCb, nullptr);
    

    By parsing the member's json in the callback feature, the developer can determine whether the member is still in the team based on the field kNIMTeamUserKeyValidFlag.

  • Query (single) member profile (If there is data in the cache, valid or invalid members are supported)

      void nim_team_query_team_member_async(const char *tid,const char *accid, const char *json_extension, nim_team_query_team_member_cb_func cb, const void *user_data);
    

    For example:

    C++

      void OnQueryMyTeamMemberInfo(const std::string& tid, const nim::TeamMemberProperty& team_member_info)
      {
      	...
      }
    
      foo()
      {
      	nim::Team::QueryTeamMemberAsync("tid_","accid_", OnQueryMyTeamMemberInfo);
      }
    

    C#

      NIM.Team.TeamAPI.QuerySingleMemberInfo("_teamId", "_accid",(info) =>
      {
         ...
      });
    

    C

      void CallbackQueryTeamMember(const char *tid, const char *accid, const char *result, const char *json_extension, const void *user_data)
      {
      	// parse result
      }
    
      typedef void(*nim_team_query_team_member_async)(const char *tid, 	const char *accid, const char *json_extension, nim_team_query_team_member_cb_func cb, const void *user_data);
    
      void foo()
      {
      	nim_team_query_team_member_async func = (nim_team_query_team_member_async) GetProcAddress(hInst, "nim_team_query_team_member_async");
      	func("tid", "accid", nullptr, &CallbackQueryTeamMember, nullptr);
      }
    
  • User leaves team

    C++ void OnTeamEventCallback(const nim::TeamEvent& result) { ··· }

      foo()
      {
      	nim::Team::LeaveAsync("tid_", &OnTeamEventCallback);
      }
    

    C#

      NIM.Team.TeamAPI.LeaveTeam("tid", (ret) =>
      {
          if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
          {
              ···
          }
          else
          {
              ···
          }
      });
    

    C

      void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
      {
      	if (error == kNIMResSuccess)
      	{
      		...
      	}
      	else
      	{
      		...
      	}
      }
    
      typedef void(*nim_team_leave_async)(const char *tid, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	nim_team_leave_async func = (nim_team_leave_async) GetProcAddress(hInst, "nim_team_leave_async");
      	func("tid", nullptr, &CallbackTeamOperate, nullptr);
      }
    
  • Kick users out

    C++

      void OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	···
      }
    
      foo()
      {
      	std::list<std::string> uids_list;
      	uids_list.push_back("user_id");
      	nim::Team::KickAsync("tid_", uids_list, &OnTeamEventCallback);
      }
    

    C#

      NIM.Team.TeamAPI.KickMemberOutFromTeam("_teamId", new string[] {"uid"}, (ret) =>
      {
          ···
      });
    

    C

      void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
      {
      	if (error == kNIMResSuccess)
      	{
      		...
      	}
      	else
      	{
      		...
      	}
      }
    
      typedef void(*nim_team_kick_async)(const char *tid, const char *jsonlist_uids, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);
    
      void foo()
      {
      	Json::Value values;
      	values.append("user_id");
    
      	nim_team_kick_async func = (nim_team_kick_async) GetProcAddress(hInst, "nim_team_kick_async");
      	func("tid", values.toStyledString().c_str(), nullptr, &CallbackTeamOperate, nullptr);
      }
    

Dismiss team

Owner can dismiss his/her team by calling the interface:

C++

void OnTeamEventCallback(const nim::TeamEvent& result)
{
	···
}

foo()
{
	nim::Team::DismissAsync("tid_", &OnTeamEventCallback);
}

C#

NIM.Team.TeamAPI.DismissTeam("_teamId", (ret) =>
{
    ···
});

C

void CallbackTeamOperate(int error, int team_operate, const char *tid, const char* str, const char *json_exten, const void *user_data)
{
	if (error == kNIMResSuccess)
	{
		...
	}
	else
	{
		...
	}
}

typedef void(*nim_team_dismiss_async)(const char *tid, const char *json_extension, nim_team_event_cb_func cb, const void* user_data);

void foo()
{
	nim_team_dismiss_async func = (nim_team_dismiss_async) GetProcAddress(hInst, "nim_team_dismiss_async");
	func("tid", nullptr, &CallbackTeamOperate, nullptr);
}

Team notification

If there is any change to the team (including change to team profile, team member.) after the user successfully creates or joins a team, the CommsEase server will send a corresponding team notification message. The app can receive team notifications by registering the global callback feature.

void nim_team_reg_team_event_cb(const char *json_extension, nim_team_event_cb_func cb, const void *user_data);

For example:

C++

void OnTeamEventCallback(const nim::TeamEvent& result)
{
	···
}

foo()
{
	nim::Team::RegTeamEventCb(&OnTeamEventCallback);
}

C#

void OnTeamEventNotify(object sender, NIMTeamEventArgs e)
{
    if (e.Data.TeamEvent.NotificationType == NIMNotificationType.kNIMNotificationIdLocalGetTeamList)
    {
        ···
    }
}

void foo()
{
	NIM.Team.TeamAPI.TeamEventNotificationHandler += OnTeamEventNotify;
}

C

void CallbackTeamEvent(int error, int team_event, const char *tid, const char* str, const char *json_exten, const void *user_data)
{
	switch (team_event)
	{
	case kNIMNotificationIdLocalCreateTeam:
		...
	...	
	}
}

typedef void(*nim_team_reg_team_event_cb)(const char *json_extension, nim_team_event_cb_func cb, const void *user_data);

void foo()
{
	nim_team_reg_team_event_cb func = (nim_team_reg_team_event_cb) GetProcAddress(hInst, "nim_team_reg_team_event_cb");
	func(nullptr, &CallbackTeamEvent, nullptr);
}
  • Upon the receipt of team notification, SDK will update the Team profile cached locally, and then trigger and update the callback of delegated events.
  • Team notification is a message to be received, which developers should not create or send.

Custom extension

SDK provides an extension interface for team message, so that developers can customize message content by maintaining two properties of the message.

  • Personalized configuration can be done on the application side by extension of the field kNIMTeamInfoKeyServerCustom (nim_team_def.h), but it can't be updated by the client.

  • Personalized configuration can be done on the application side by extension of the field kNIMTeamInfoKeyCustom (nim_team_def.h), and it can be updated by the client.

Mute team member

  • Mute

    Example:

    C++

      #include "nim_cpp_team.h"
    
      void CallbackMuteMember(const TeamEvent& team_event)
      {
      	//Custom implementation
      	char log[128];
      	sprintf_s(log, "id: %s, rescode: %d, tid: %s", GetTeamEventCommandText((nim::NIMNotificationId)team_event.notification_id_).c_str(), team_event.res_code_, team_event.team_id_.c_str());
      	MessageBoxA(nullptr, log, "team_event", 0);
      }
    
      void foo(const std::string& team_id, const std::string& account_id, bool mute)
      {
      	Team::MuteMemberAsync(team_id, account_id, bool, &CallbackMuteMember);
      }
    

    C#

      NIM.Team.TeamAPI.SetMemberMuted("_teamId", "user_id", true, (ret) =>
      {
          if (ret.TeamEvent.ResponseCode == NIM.ResponseCode.kNIMResSuccess)
          {
              ···
          }
      });
    

    C

      #include "nim_team.h"
    
      nim_team_mute_member_async(const char *tid, const char *member_id, bool set_mute, const char *json_extension, nim_team_opt_cb_func cb, const void *user_data);
    
      Parse result example of nim_team_opt_cb_func callback:
    
      //nim_cpp_team.cpp
      static void CallbackTeamChange(int res_code, int notification_id, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	if (user_data)
      	{
      		Team::TeamEventCallback* cb_pointer = (Team::TeamEventCallback*)user_data;
      		if (*cb_pointer)
      		{
      			TeamEvent team_event;
      			ParseTeamEvent(res_code, PCharToString(tid), (nim::NIMNotificationId)notification_id, PCharToString(result), team_event);
      			(*cb_pointer)(team_event);
      		}
      		delete cb_pointer;
      	}
      }
    
  • Get the list of muted team members

    Example:

    C++

      #include "nim_cpp_team.h"
    
      void CallbackQueryMembersInfoOnline(NIMResCode error_code, const std::string& tid, const std::list<TeamMemberProperty>& team_member_propertys)
      {
      	//Custom implementation
      	std::string ids;
      	for (auto iter = team_member_propertys.begin(); iter != team_member_propertys.end(); ++iter)
      	{
      		ids.append(iter->GetAccountID());
      		ids.append(",");
      	}
      	char log[1024];
      	sprintf_s(log, 1024, "tid: %s, member_count: %d\r\nids: %s", tid.c_str(), team_member_propertys.size(),ids.c_str());
      	MessageBoxA(nullptr, log, "CallbackQueryMembersInfoOnline", 0);
      }
    
      void foo(const std::string& team_id)
      {
      	Team::QueryMuteListOnlineAsync(team_id, &CallbackQueryMembersInfoOnline);
      }
    

    C#

      using NIM.Team;
    
      NIM.Team.TeamAPI.QueryMutedListOnlineAsync(tid, (res, count, id, members) => 
      {
      	//Custom implementation
          DemoTrace.WriteLine("mute list:",res, count, id, members.Dump());
      });
    

    C

      #include "nim_team.h"
    
      nim_team_query_mute_list_online_async(const char *tid, const char *json_extension, nim_team_query_mute_list_cb_func cb, const void *user_data)
    
      Parse result example of nim_team_query_mute_list_cb_func callback:
    
      //nim_team_helper.cpp
      void ParseTeamMemberPropertyJson(const Json::Value& team_member_prop_json, TeamMemberProperty& team_member_property)
      {
      	team_member_property.SetUserType((nim::NIMTeamUserType)team_member_prop_json[nim::kNIMTeamUserKeyType].asInt());
      	if (team_member_property.GetUserType() != nim::kNIMTeamUserTypeApply && team_member_property.GetUserType() != nim::kNIMTeamUserTypeLocalWaitAccept)
      	{
      		team_member_property.SetAccountID(team_member_prop_json[nim::kNIMTeamUserKeyAccID].asString());
      		team_member_property.SetNick(team_member_prop_json[nim::kNIMTeamUserKeyNick].asString());
      		team_member_property.SetBits(team_member_prop_json[nim::kNIMTeamUserKeyBits].asUInt64());
      		team_member_property.SetCreateTimetag(team_member_prop_json[nim::kNIMTeamUserKeyCreateTime].asUInt64());
      		team_member_property.SetUpdateTimetag(team_member_prop_json[nim::kNIMTeamUserKeyUpdateTime].asUInt64());
      		team_member_property.SetTeamID(team_member_prop_json[nim::kNIMTeamUserKeyID].asString());
      		team_member_property.SetValid(team_member_prop_json[nim::kNIMTeamUserKeyValidFlag].asUInt() == 0 ? false : true);
      		team_member_property.SetCustom(team_member_prop_json[nim::kNIMTeamUserKeyCustom].asString());
      		team_member_property.SetMute(team_member_prop_json[nim::kNIMTeamUserKeyMute].asInt() == 1);
      	}
      }
    
      //nim_cpp_team.cpp
      static void CallbackQueryMembersOnline(int res_code, int count, const char *tid, const char *result, const char *json_extension, const void *user_data)
      {
      	if (user_data)
      	{
      		Team::QueryTeamMembersOnlineCallback* cb_pointer = (Team::QueryTeamMembersOnlineCallback*)user_data;
      		if (*cb_pointer)
      		{
      			Json::Value values;
      			Json::Reader reader;
      			std::list<TeamMemberProperty> members;
      			if (reader.parse(PCharToString(result), values) && values.isArray())
      			{
      				auto size = values.size();
      				for (size_t i = 0; i < size; i++)
      				{
      					TeamMemberProperty prop;
      					ParseTeamMemberPropertyJson(values[i], prop);
      					members.push_back(prop);
      				}
      			}
      			(*cb_pointer)((NIMResCode)res_code, PCharToString(tid), members);
      		}
      		delete cb_pointer;
      	}
      }
    

Message alert settings

The message alert types can be set for an advanced team , including: Remind all, Remind administrator only, and Remind none, Remind all is chosen by default. Message alert settings are not supported to a ordinary team. Message alert can be set on PC SDK by updating your own team property:

  • API introduction

    C++

    static bool UpdateMyPropertyAsync(const TeamMemberProperty& prop, const TeamEventCallback& cb, const std::string& json_extension = "")

    File:nim_cpp_team.h

    Namespace:NIM

    Class:Team

    C

    **void nim_team_update_my_property_async(const char *info, const char json_extension, nim_team_opt_cb_func cb, const void user_data)

    File:nim_team.h

  • Parameter Description

    C/C++

Parameter Type Required Description
prop(C++) struct Yes Team member profile
cb feature Yes Callback feature
json_extension std::string No extension parameters
  • Sample codes

    C++

      long long new_bits = 0;
      if (all reminded)
      	new_bits &= ~nim::kNIMTeamBitsConfigMaskMuteNotify;
      else if (not reminded)
      	new_bits |= nim::kNIMTeamBitsConfigMaskMuteNotify;
      else// only administrator message
      	new_bits |= nim::kNIMTeamBitsConfigMaskOnlyAdmin;
      nim::TeamMemberProperty values(team id, sender account id, team member type);
      values.SetBits(new_bits);
      nim::Team::UpdateMyPropertyAsync(values, nbase::Bind(&TeamCallback::OnTeamEventCallback, std::placeholders::_1));
    
      void TeamCallback::OnTeamEventCallback(const nim::TeamEvent& result)
      {
      	...
      }
    
Was this page helpful?
Yes
No
  • Teams
  • Overview
  • Team chat messages
  • Get a team
  • Create a team
  • Join a team
  • Remove a member from a team
  • Voluntary leave the team
  • Edit the team profile
  • Manage team permissions
  • Team member
  • Dismiss team
  • Team notification
  • Custom extension
  • Mute team member
  • Message alert settings