Manage Groups

Update time: 2023/03/24 02:44:32

NIM SDK allows you to manage advanced groups, such as creating, joining, and leaving groups, transferring the ownership of a group, querying group information, and dismissing a group.

How it works

Group APIs in NIM SDK are included in the nim::Team module. nim::Team provides interfaces to handle group operations.

The previous module are implemented in C++. For the implementation in C language, see nim_team.

Listeners for group events

You can register listeners for group events before group operations. If listeners are registered, you can receive notifications for corresponding group operations.

C++

Use a callback template (OnTeamEventCallback) and call the RegTeamEventCb method to listen for group event notifications.

For information about group events, see TeamEvent.

Sample code:

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

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

For some query interfaces, separate callback templates are avaiable. For more information, see nim::Team.

C

Use the callback function (nim_team_event_cb_func) and call the nim_team_reg_team_event_cb method to listen for group event notifications.

For the enumeration of group notification events, see NIMNotificationId.

Sample code:

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);
}

For some query interfaces, separate callback function definitions are available. For more information, see nim_team_def.

  • Since obtaining group profile and group member information requires cross-process asynchronous calls, your app can store the group member information in the cache and access the group member information from the local cache when querying group member information. When the group or group member information changes, the SDK will notify the registered observers. At this time, your app can update the cache and refresh the interface.
  • After receiving group notifications, the SDK will modify the locally cached group information, and trigger the callback for the listener of the edit event.
  • Group notifications are sent or received automatically. You cannot manually create and send group notifications.

Workflow

This document introduces the implementation process of group management by taking the interaction among group owners, administrators, and regular members.

GroupManage.png

Create a group

  • Users invited when a group is created will receive a system notification (NIMSysMsgType) of type kNIMSysMsgTypeTeamInvite.
  • If the invitation mode(NIMTeamBeInviteMode) is set to kNIMTeamBeInviteModeNeedAgree, the invited user can join the group after accepting the invitation.
C++

Create a group by calling the CreateTeamAsync method. The creator becomes the group owner.

Parameters:

Parameter Description
team_info Group information, see TeamInfo
invitation_postscript Additional message for an invitation.
ids The list of invited users.
json_extension Extension parameter in JSON
This parameter can be used to configure the moderation settings.
Format: {"anti_spam_business_id":"{"textbid":"xxxx","picbid":"xxxx"}"}
cb The callback function for group notifications, see TeamEventCallback

** Sample code:**

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);
}

Error codes

Code Description
200 The operation was successful.
810 Inviting users succeeded with tinfo.
414 Not enough members
801 The user limit is reached
404 Illegal users was invited.
C

Create a group by calling the nim_team_create_team_async method, The creator becomes the group owner.

** Sample code:**

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] = ; // Group name
	team_info[kNIMTeamInfoKeyType] = ; // Group type
	team_info[kNIMTeamInfoKeyIntro] = ; // Introduction
	team_info[kNIMTeamInfoKeyJoinMode] = ; // Verification type
	team_info[kNIMTeamInfoKeyAnnouncement] = ; // 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 group

You can join a group using the following methods:

  • Accepts the invitation to join a group.
  • Request to join a group

Invite users to join a group

You can specify the verification type in NIMTeamInviteMode. If you set the value to kNIMTeamInviteModeManager, only the group owner and administrator can invite people to join a group. The kNIMTeamInviteModeEveryone allows all members in the group can invite people to join the group.

C++

Invite users to join a group by calling the InviteAsync method.

  • If the invitation mode NIMTeamBeInviteMode of the group is kNIMTeamBeInviteModeNotNeedAgree, users can join the group without verification.
  • If the invitation mode NIMTeamBeInviteMode of the group is set to ``kNIMTeamBeInviteModeNeedAgree`, the invited user must accpets the invitation before joining the group.

If an invited member has reached the upper limit of joined groups, the accounts failing to join the group are returned.

Parameters:

Parameter Description
tid Group ID
ids User accounts to be invited.
json_extension Custom extension field.
invitation_postscript Additional message for invitation. Leave it empty if unnecessary.
cb Callback function for the invitation.
  • After the invitation is sent, the invited user will receive a NIMSysMsgTypesystem notification of kNIMSysMsgTypeTeamInvite type.
  • The invited user can join the group by call the AcceptInvitationAsync method to accept the invitation. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamInviteAccept.
  • The invited user can also reject the invitation by calling the RejectInvitationAsync method. If rejecting the invitation, the invited user receives a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamInviteReject.

** Sample code:**

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);
}

//Accept an invitation
void TeamEventCb(const nim::TeamEvent& team_event)
{
	···
}

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

//Reject the invitation
void TeamEventCb(const nim::TeamEvent& team_event)
{
	···
}

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

Error codes

Code Description
200 The operation was successful.
810 Invite requests with timetag are sent successfully.
801 The user limit is reached
802 No permissions
803 Group does not exist
404 Illegal users
C

Invite users to join a group by calling the nim_team_invite_async method.

  • If the invitation mode NIMTeamBeInviteMode of the group is kNIMTeamBeInviteModeNotNeedAgree, users can join the group without verification.

  • If the invitation mode NIMTeamBeInviteMode of the group is set to ``kNIMTeamBeInviteModeNeedAgree`, the invited user must accpets the invitation before joining the group.

  • After the invitation is sent, the invited user will receive a NIMSysMsgTypesystem notification of kNIMSysMsgTypeTeamInvite type.

  • The invited user can join the group by call the nim_team_accept_invitation_async method. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamInviteAccept.

  • The invited user can also reject the invitation by calling the nim_team_reject_invitation_async method. If rejecting the invitation, the invited user receives a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamInviteReject.

** Sample code:**

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 an invitation
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 the invitation
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);
}

Request to join a group

C++

You can request to join a group by calling the ApplyJoinAsync method.

  • If the option for NIMTeamJoinMode is kNIMTeamJoinModeNoAuth, users can join the group without verification.
  • If the option for NIMTeamJoinMode is set to kNIMTeamJoinModeNeedAuth, the group owner or administrators must approve requests to join the group.
  • If the option for NIMTeamJoinMode is kNIMTeamJoinModeRejectAll, the group does not accept requests. Users can only join the group by invitation.

Parameters:

Parameter Description
tid Group ID
reason Additional message for a request
json_extension Custom extension field.
cb Callback function for join requests.
  • If a user sends a join request, the group owner and administrators receive a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamApply .
  • The group owner and administrators can approve the request by calling the PassJoinApplyAsync method. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamApplyPass.
  • The group owner and group administrators can also reject the request by calling the RejectJoinApplyAsync method. If a request is rejected, the requester receives a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamReject .

** Sample code:**

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);
}

// Approve a request

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);
}

//Reject a request

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);
}

Error codes

Code Description
200 The operation was successful.
801 The user limit is reached
802 The verification setting rejects all requests.
803 Group does not exist
805 Invalid group type.
808 Request is accepted.
809 Already in the group.
C

You can request to join a group by calling the nim_team_apply_join_async method.

  • If the option for NIMTeamJoinMode is kNIMTeamJoinModeNoAuth, users can join the group without verification.

  • If the option for NIMTeamJoinMode is set to kNIMTeamJoinModeNeedAuth, the group owner or administrators must approve requests to join the group.

  • If the option for NIMTeamJoinMode is kNIMTeamJoinModeRejectAll, the group does not accept requests. Users can only join the group by invitation.

  • If a user sends a join request, the group owner and administrators receive a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamApply .

  • The group owner and administrators can approve the request by calling the nim_team_pass_join_apply_async method. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamApplyPass.

  • The group owner and group administrators can also reject the request by calling the nim_team_reject_join_apply_async method. If a request is rejected, the requester receives a system notification NIMSysMsgType of type kNIMSysMsgTypeTeamReject .

** Sample code:**

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);
}

// Approve the request
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 the request
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);
}

Transfer the ownership of a group

Only the group owner has the permission to transfer the ownership of a group.

C++

The group owner can transfer the ownership of a group by calling TransferTeamAsync method.

  • After the ownership of the group is transferred, all group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamOwnerTransfer.
  • If you leave the group while transferring the ownership, call [quitTeam](https://doc.yunxin.163.com/docs/interface/IM_Android/com/netease/nimlib/sdk /team/TeamService.html#quitTeam-java.lang.String-) to leave the group. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamLeave.

Parameters:

Parameter Description
tid Group ID
new_owner_id Account of the new owner.
is_leave Whether to leave the group while transferring the group
true: leave the group.
false: do not leave the group and the role becomes a regular group member
json_extension Custom extension field.
cb Callback function for transferring the ownership of a group.

** Sample code:**

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

foo()
{
	nim::Team::TransferTeamAsync("tid_", "user_id", false, &OnTeamEventCallback);
}

Error codes

Code Description
200 The operation was successful.
802 No permissions
803 Group does not exist
805 Invalid group type.
806 The number of group a user has joined reaches the upper limit.
C

The group owner can transfer the ownership of a group by calling nim_team_transfer_team_async method.

  • After the ownership of the group is transferred, all group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamOwnerTransfer.
  • If the group owner leaves the group while transferring the ownership, call the nim_team_leave_async method. All group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamLeave.

** Sample code:**

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);
}

Leave a group

A member can leave a group using the following methods:

  • The group owner or administrator removes a user. All group members will receive a notification of ``kNIMMessageTypeNotificationand the trigger event iskNIMNotificationIdTeamKick`.
  • You leave the group. If a member leaves a group. all group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamLeave.

Remove a member from a group

  • Only the owner and moderators can remove members from the group.
  • Administrators cannot remove group owners or other administrators from a group.
C++

Remove a member from a group by calling the KickAsync method.

Parameters:

Parameter Description
tid Group ID
ids The members to be removed.
json_extension Custom extension field.
Cb Callback for removing a member.

** Sample code:**

Team::KickAsync("tid", {123456, 456789}, [this](const TeamEvent& team_event) {
	// process team_event
});

Error codes

Code Description
200 The operation was successful.
403 An administrator or group owner was removed.
404 Illegal user.
801 The number of group members exceeds the upper limit.
802 No permissions
803 Group does not exist
C

Remove a member from a group by calling the nim_team_kick_async method.

** Sample code:**

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);
}

Leave a group

Except the group owner, all other members can leave a group.

C++

Leave a group by calling the LeaveAsync method.

Parameters:

Parameter Description
tid Group ID
json_extension Custom extension field.
cb Callback for leaving a group.

** Sample code:**

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

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

Error codes

Code Description
200 The operation was successful.
803 Group does not exist
804 The user is not a member of a group.
C

Leave a group by calling the nim_team_leave_async method.

** Sample code:**

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);
}

Delete a group

After a group is deleted, all group members will receive a notification of ``kNIMMessageTypeNotificationand the trigger event iskNIMNotificationIdTeamDismiss`.

Only the group owner have the permission to dismiss a group.

C++

Delete a group by calling the DismissAsync method.

Parameters:

Parameter Description
tid Group ID
json_extension Custom extension field.
Cb Callback for deleting a group.

** Sample code:**

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

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

Error codes

Code Description
200 The operation was successful.
802 No permissions.
803 Group does not exist
C

Delete a group by calling the nim_team_dismiss_async method.

** Sample code:**

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);
}

Edit the group profile

If the group profile is updated, all group members will receive a notification of kNIMMessageTypeNotification and the trigger event is kNIMNotificationIdTeamUpdate.

Members must have permissions for editing group profiles. If the edit permission of the group profile (NIMTeamUpdateInfoMode) is set to kNIMTeamUpdateInfoModeManager, only the group owner and administrators can edit the group profile. If the value is set to kNIMTeamUpdateInfoModeEveryone, all group members can edit the group information.

C++

Update the group profile by calling the UpdateTeamInfoAsync method.

Parameters:

Parameter Description
tid Group ID
Team_info The group information to be updated. For more information, see TeamInfo
json_extension Custom extension field.
cb The callback for updating the group profile.

** Sample code:**

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);
}

Error codes

Code Description
200 The operation was successful.
802 No permissions.
803 Group does not exist
C

Update the group profile by calling the nim_team_update_team_info_async method.

** Sample code:**

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"; //Edit the group announcement. Similarly, the group name and introduction can be modified. For details, see the API document.

	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);
}

Query group information

The SDK will synchronize the local group information when the app starts. You can call the local cache interface to get the group information.

The SDK allows a user to get information about all groups the user has joined, and query a group by group ID, and retrieve group profiles from the server.

Query the list of groups the current user has joined from the local database.

Only valid groups are queried. A valid group indicates that the user is a member of the group and the group exists.

C++

Query all groups the current user has joined from the local database by calling the QueryAllMyTeamsAsync method.

Sample code:

Team::QueryAllMyTeamsAsync([this](int count, const std::list<std::string>& team_id_list) {
	std::string ids;
	for (auto&& tid : team_id_list) {
		ids += tid + ";";
	}
	std::cout << "[Team] QueryAllMyTeamsAsync. count: " << count << ", team_ids: " << ids << std::endl;
});
C

Query all groups the current user has joined from the local database by calling the nim_team_query_all_my_teams_async method.

Sample code:

static void CallbackFunc(int team_count, const char* result, const char* json_extension, const void* user_data){
    printf("team_count: %d\n", team_count);
    printf("result: %s\n", result);
};
nim_team_query_all_my_teams_async("", &CallbackFunc, nullptr);

Query the information about all groups the current user has joined from the local database

  • All valid groups are queried by default. A valid group indicates that the user is a member of the group and the group exists.
  • SDK 2.7.0 allows users to get invalid groups (without membership) from the cache by configuring extension parameters (json_extension), for example, "{"include_invalid": true}".
  • In the JSON data returnd by the callback function, you can use the kNIMTeamInfoKeyValidFlag field to determine whether the group is deleted, and the kNIMTeamInfoKeyMemberValid field to determine whether the current user is a member of the group.
C++

Query all groups the current user has joined from the local database by calling the QueryAllMyTeamsInfoAsync method.

Sample code:

Team::QueryAllMyTeamsInfoAsync([this](int count, const std::list<TeamInfo>& team_info_list) {
	std::cout << "count: " << count << std::endl;
	for (auto& info : team_info_list) {
		// process team_info
	}
});
C

Query all groups the current user has joined from the local database by calling the nim_team_query_all_my_teams_info_async method.

Sample code:

static void CallbackFunc(int team_count, const char* result, const char* json_extension, const void* user_data){
	printf("team_count: %d, result: %s, json_extension: %s\n", team_count, result, json_extension);
};
nim_team_query_all_my_teams_info_async("", &CallbackFunc, nullptr);

Query the information about a specified group

C++

Query the information about a specified group by asynchronous calling the QueryTeamInfoAsync method or synchronous calling the QueryTeamInfoBlock method.

Sample code:

// asynchronous call
Team::QueryTeamInfoAsync(params["tid"].asString(), [this](const std::string& tid, const TeamInfo& result) {
	std::cout << "[Team] QueryTeamInfoAsync. team_id: " << tid << std::endl;
});

//synchronous call
TeamInfo result = Team::QueryTeamInfoBlock("tid");
std::cout << "[Team] QueryTeamInfoAsync. team_id: " << result.GetTeamID() << std::endl;
  • If the group information does not exist in the local database or is outdated when calling QueryTeamInfoAsync, the SDK retrieves the required information from the server.
  • The QueryTeamInfoBlock method only queries the local database, not retrieving the data from the server. If the current user does not belong to the group, the interface returns expired data. To update the group information, call QueryTeamInfoOnlineAsync method.
  • Synchronous interface may block NIM internal threads. Use it with caution.

:::

C

Query the information about a specified group by asynchronous calling the nim_team_query_team_info_async method or synchronous calling the nim_team_query_team_info_block method.

Sample code:

// asynchronous call
static void CallbackFunc(const char* tid, const char* result, const char* json_extension, const void* callback){
	std::cout << "tid:" << tid << std::endl;
};
nim_team_query_team_info_async("tid", "", &CallbackFunc, nullptr);

//synchronous call
const char* team_info = nim_team_query_team_info_block("tid");
prinf("team_info: %s\n", team_info);
  • If the group information does not exist in the local database or is outdated when calling nim_team_query_team_info_async, the SDK retrieves the required information from the server.
  • The nim_team_query_team_info_block method only queries the local database, not retrieving the data from the server. If the current user does not belong to the group, the interface returns expired data. To update the group information, call the nim_team_query_team_info_online_async method.
  • Synchronous interface may block NIM internal threads. Use it with caution.

:::

Query the information about specified groups

C++

Query the information about specified groups by group ID by calling the GetTeaminfoList method.

Sample code:

Team::GetTeaminfoList({"tid1", "tid2", "tid3"}, [](NIMResCode error_code, const std::list<nim::TeamInfo>& team_info_list, const std::list<std::string>& fail_list){
	std::cout << "GetTeaminfoList error_code:" << error_code << std::endl;
});
C

Query the information about specified groups by group ID by calling the nim_team_get_team_info_list method.

Sample code:

static void CallbackFunc(int code, const char* tinfo_list, const char* fail_tid_list, const void* user_data){
	printf("nim_team_get_team_info_list code: %d", code);
};
nim_team_get_team_info_list("[\"tid1\", \"tid2\", \"tid3\"]", &CallbackFunc, NULL);

Local storage of group information in the SDK:

  • When you delete or leave a group, or are removed from the group, the local database will continue to retain the group information. Only the invalid flag is applied. At this time, you can still query the group information. If the user manually clears all local data, the server will not synchronize the invalid group data during the next login synchronization, and the information about the group the user has left will not be obtained.

  • After the group is deleted, the result of querying the group information from the server will return a null value.

Query a specified group from the IM server

C++

Query a specified group from the IM server by calling the QueryTeamInfoOnlineAsync method. Sample code:

Team::QueryTeamInfoOnlineAsync("tid", [this](const TeamEvent& team_event) {
	// process team_event
});
C

Query a specified group from the IM server by calling the nim_team_query_team_info_online_async method. Sample code:

static void CallbackTeamChange(int res_code,
    int notification_id,
    const char* tid,
    const char* result,
    const char* json_extension,
    const void* user_data) {
    // process result
}
nim_team_query_team_info_online_async("tid", "", &CallbackTeamChange, NULL);
C++

Query all groups using keywords by calling the QueryTeamInfoByKeywordAsync method. Sample code:

Team::QueryTeamInfoByKeywordAsync("keyword", [this](int count, const std::list<TeamInfo>& team_info_list) {
	std::cout << "QueryTeamInfoByKeywordAsync count: " << count << std::endl;
});
C

Query all groups using keywords by calling the nim_team_query_teams_info_by_keyword method. Sample code:

static void CallbackQueryAllMyTeamsInfo(int team_count, const char* result, const char* json_extension, const void* user_data) {
    // process result
}
nim_team_query_teams_info_by_keyword("keyword", &CallbackQueryAllMyTeamsInfo, "", NULL);

API reference

C++
API
Description
RegTeamEventCb Listen to group event notifications.
CreateTeamAsync Create a group.
InviteAsync Invite a user to join a group.
AcceptInvitationAsync Accept an invitation.
RejectInvitationAsync Reject an invitation.
ApplyJoinAsync Request to join a group.
PassJoinApplyAsync Approve a join request.
RejectJoinApplyAsync Reject a join request.
KickAsync Remove a member from a group.
LeaveAsync Leave a group.
TransferTeamAsync Transfer the ownership of a group.
DismissAsync Delete a group.
UpdateTeamInfoAsync Edit the group profile.
QueryAllMyTeamsAsync Query all groups the current user has joined from the local database.
QueryAllMyTeamsInfoAsync Query the information about all groups the current user has joined from the local database.
QueryTeamInfoAsync Query the specified group information (asynchronous interface)
QueryTeamInfoBlock Query a specified group by asynchronous call.
GetTeaminfoList Query the information about specified groups by group ID.
QueryTeamInfoOnlineAsync Query a specified group from the IM server.
QueryTeamInfoByKeywordAsync Query all groups using keywords.
C
API
Description
nim_team_reg_team_event_cb Listen to group event notifications.
nim_team_create_team_async Create a group.
nim_team_invite_async Invite a user to join a group.
nim_team_accept_invitation_async Accept an invitation.
nim_team_reject_invitation_async Reject an invitation.
nim_team_apply_join_async Request to join a group.
nim_team_pass_join_apply_async Approve a join request.
nim_team_reject_join_apply_async Reject a join request.
nim_team_kick_async Remove a member from a group.
nim_team_leave_async Leave a group.
nim_team_transfer_team_async Transfer the ownership of a group.
nim_team_dismiss_async Delete a group.
nim_team_update_team_info_async Edit the group profile.
nim_team_query_all_my_teams_async Query all groups the current user has joined from the local database.
nim_team_query_all_my_teams_info_async Query all groups the current user has joined from the local database.
nim_team_query_team_info_async Query the specified group information (asynchronous interface).
nim_team_query_team_info_block Query the specified group information (synchronous interface).
nim_team_get_team_info_list Query the information about specified groups by group ID.
nim_team_query_team_info_online_async Query a specified group from the IM server.
nim_team_query_teams_info_by_keyword Query all groups using keywords.
Was this page helpful?
Yes
No
  • How it works
  • Listeners for group events
  • Workflow
  • Create a group
  • Join a group
  • Invite users to join a group
  • Request to join a group
  • Transfer the ownership of a group
  • Leave a group
  • Remove a member from a group
  • Leave a group
  • Delete a group
  • Edit the group profile
  • Query group information
  • Query the list of groups the current user has joined from the local database.
  • Query the information about all groups the current user has joined from the local database
  • Query the information about a specified group
  • Query the information about specified groups
  • Query a specified group from the IM server
  • Group search
  • API reference