Manage group info
ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of group information management, allowing you to get or modify group info, such as group name, nickname in the group, group avatar, group notice, and more.
- Before you use this feature, you must join a group first. To join a group, refer to the Chapter Join a group of Manage groups.
- All in-group members (group owner included) can use this feature.
Get group info
To know the detailed info of the group you joined, call the queryGroupInfoByGroupID method.
You will receive the group info through the callback ZIMGroupInfoQueriedCallback after the query succeeds.
// Get the group info, such as group name, nicknames, group notice.
zim.queryGroupInfo(group_id, new ZIMGroupInfoQueriedCallback() {
@Override
public void onGroupInfoQueried(ZIMGroupInfo groupInfo, ZIMError errorInfo) {
// Get the result of querying group information through errorInfo.
}
});
1
// Get the group info, such as group name, nicknames, group notice.
[zim queryGroupInfoByGroupID:groupID callback:^(ZIMGroupInfo * _Nonnull groupInfo, ZIMError * _Nonnull errorInfo) {
//Implement the event callback for query the group info, such as group name, nicknames, group notice here.
}];
1
// Get the group info, such as group name, nicknames, group notice.
[zim queryGroupInfoByGroupID:groupID callback:^(ZIMGroupInfo * _Nonnull groupInfo, ZIMError * _Nonnull errorInfo) {
//Implement the event callback for query the group info, such as group name, nicknames, group notice here.
}];
1
// Get the group info, such as group name, nicknames, group notice.
zim_->queryGroupInfo(group_id,
[=](const ZIMGroupInfo &groupInfo, zim::ZIMError errorInfo) {
int code = errorInfo.code;
});
1
// Get the group info, such as group name, nicknames, group notice.
ZIM
.getInstance()
.queryGroupInfo('groupID')
.then((value) {
//This will be triggered when operation successful.
})
.catchError((onError) {
//This will be triggered when operation failed.
});
1
// Get the group info, such as group name, nicknames, group notice, and group avatar URL.
var groupID = '';
zim.queryGroupInfo(groupID)
.then(function ({ groupInfo }) {
// Query successful.
})
.catch(function (err) {
// Query failed.
});
1
// Group members query group information, such as group name, group nickname, group announcement, etc.
ZIM.GetInstance().QueryGroupInfo("groupID", (ZIMGroupFullInfo groupInfo, ZIMError errorInfo) =>
{
// You can get the result of querying group information by accessing errorInfo
});
1
Modify the group name
To modify the group name after joining a group, call the updateGroupName method.
All group members receive a notification through the callback groupNameUpdated after the group name is modified successfully.
// Modify the group name.
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
zim.updateGroupName("new_group_name", group_id, new ZIMGroupNameUpdatedCallback() {
@Override
public void onGroupNameUpdated(ZIMError errorInfo) {
}
});
1
// Modify the group name.
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
[zim updateGroupName:groupName groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for the results of modify the group name here.
}];
1
// Modify the group name.
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
[zim updateGroupName:groupName groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for the results of modify the group name here.
}];
1
// Modify the group name.
zim_->updateGroupName("new_group_name", group_id,
[=](const std::string &groupID, const std::string &groupName, zim::ZIMError errorInfo){
int error_code = errorInfo.code;
});
1
// Modify the group name.
ZIM
.getInstance()
.updateGroupName('groupName', 'groupID')
.then((value) {
//This will be triggered when operation successful.
})
.catchError((onError) {
//This will be triggered when operation failed.
});
1
// Group members modify group name
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
var groupID = '';
var groupName = '';
zim.updateGroupName(groupName, groupID)
.then(function ({ groupID, groupName }) {
// Operation successful.
})
.catch(function (err) {
// Operation failed.
});
// Register and listen for the callback groupNameUpdated
zim.on('groupNameUpdated', function (zim, { groupID, groupName, operatedInfo }) {
console.log('groupNameUpdated', groupID, groupName, operatedInfo);
});
1
// Group members modify group name
// groupName is a string with a maximum of 64 bytes, with no special character restrictions.
ZIM.GetInstance().UpdateGroupName("newGroupName", "groupID", (string groupID, string groupName, ZIMError errorInfo) => { });
1
Modify the group avatar
After logging in and joining a group, if a user wants to modify the avatar of the group they have joined, they can do so by calling the updateGroupAvatarUrl interface to modify the group avatar.
After a successful modification, all group members will receive a notification through groupAvatarUrlUpdated.
// Group members modify the group avatar.
// The URL can be up to 500 bytes long with no special character restrictions.
String groupAvatarUrl = "";
String groupId = "";
zim.updateGroupAvatarUrl(groupAvatarUrl, groupId, new ZIMGroupAvatarUrlUpdatedCallback() {
@Override
public void onGroupAvatarUrlUpdated(String groupID, String groupAvatarUrl, ZIMError errorInfo) {
}
});
1
// Group members modify the group avatar
// The URL can be up to 500 bytes long with no special character restrictions.
[zim updateGroupAvatarUrl:groupAvatarUrl groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
// Write your business code here after calling the interface to modify the group avatar.
}];
1
// Group members modify the group avatar
// The URL can be up to 500 bytes long with no special character restrictions.
[zim updateGroupAvatarUrl:groupAvatarUrl groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
// Write your business code here after calling the interface to modify the group avatar.
}];
1
// Group members modify group avatar
// URL maximum 500 bytes, no special character restrictions
zim_->updateGroupAvatarUrl("new_group_avatar_url", group_id,
[=](const std::string &groupID, const std::string &groupName, zim::ZIMError errorInfo){
int error_code = errorInfo.code;
});
1
// Modify group avatar by group members
// groupAvatarUrl is a string with a maximum of 500 bytes, no special character restrictions.
ZIM.getInstance()
!.updateGroupAvatarUrl('groupAvatarUrl', 'groupID')
.then((value) => {
// Triggered when successful
})
.catchError((onError) {
// Triggered when failed
});
1
// Group members modify group avatar
// The URL can be up to 500 bytes with no special character limitations.
var groupID = '';
var groupAvatarUrl = '';
zim.updateGroupAvatarUrl(groupAvatarUrl, groupID)
.then(function ({ groupID, groupAvatarUrl }) {
// Operation successful.
})
.catch(function (err) {
// Operation failed.
});
// Register and listen for the callback groupAvatarUrlUpdated
zim.on('groupAvatarUrlUpdated', function (zim, { groupID, groupAvatarUrl, operatedInfo }) {
console.log('groupAvatarUrlUpdated', groupID, groupAvatarUrl, operatedInfo);
});
1
// Group members modify group avatar
// URL has a maximum of 500 bytes, with no special character restrictions.
ZIM.GetInstance().UpdateGroupAvatarUrl("groupAvatarUrl", "groupID", (string groupID, string groupAvatarUrl, ZIMError errorInfo) => { });
1
Modify the group notice
To modify the group notice after joining a group, call the updateGroupNotice method.
All group members receive a notification through the callback groupNoticeUpdated when the group notice is modified successfully.
// Modify the group notice.
zim.updateGroupNotice("new_group_notice", group_id, new ZIMGroupNameUpdatedCallback() {
@Override
public void onGroupNoticeUpdated(ZIMError errorInfo) {
// Get the result of querying group information through errorInfo.
}
});
1
// Modify the group notice.
[zim updateGroupNotice:groupNotice groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for modifying the group notice here.
}];
1
// Modify the group notice.
[zim updateGroupNotice:groupNotice groupID:groupID callback:^(ZIMError * _Nonnull errorInfo) {
//Implement the event callback for modifying the group notice here.
}];
1
// Modify the group notice.
zim_->updateGroupNotice("new_group_notice", group_id,
[=](const std::string &groupID, const std::string &groupNotice, ZIMError errorInfo){
int error_code = errorInfo.code;
});
1
// Modify the group notice.
ZIM
.getInstance()
.updateGroupNotice('groupNotice', 'groupID')
.then((value) {
//This will be triggered when operation successful.
})
.catchError((onError) {
//This will be triggered when operation failed.
});
1
// Group members Modify the group notice
var groupID = '';
var groupNotice = '';
zim.updateGroupNotice(groupNotice, groupID)
.then(function ({ groupID, groupNotice }) {
// Operation successful.
})
.catch(function (err) {
// Operation failed.
});
// Register and listen for the callback groupNoticeUpdated
zim.on('groupNoticeUpdated', function (zim, { groupID, groupNotice, operatedInfo }) {
console.log('groupNoticeUpdated', groupID, groupNotice, operatedInfo);
});
1
// Group members modify group notice
ZIM.GetInstance().UpdateGroupNotice("new_group_notice", "group_id", (string groupID, string groupNotice, ZIMError errorInfo) =>
{
// Use errorInfo.code to get the result of modifying group notice
}
);
1
Modify the group alias
Group alias is a personalized nickname set by users for a group chat to distinguish from other group chats. For example, you can set the alias for a work group as "Work Group" and the alias for a family group as "Family Group", which makes it more convenient to identify the group chats.
Group alias is only visible to the user who sets it and does not affect the display of the group name for other group chat members.
After logging in and joining a group, if a user wants to modify the group alias, the user can call the updateGroupAlias interface to modify the group alias. The group alias is only visible to the user themselves, and the alias for the corresponding conversation will be automatically synchronized.
// Modify the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
String group_alias = "NewAlias";
String group_id = "GroupID";
zim.updateGroupAlias(group_alias, group_id, new ZIMGroupAliasUpdatedCallback() {
@Override
public void onGroupAliasUpdated(String groupID, String groupAlias, ZIMError errorInfo) {
// Get the result of modifying the group alias through errorInfo.code
}
});
1
// Modify the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
NSString *groupAlias = @"NewAlias";
NSString *groupID = @"GroupID";
[zim updateGroupAlias:groupAlias groupID:groupID callback:^(NSString *groupID, NSString *groupAlias, ZIMError *errorInfo) {
// Write your business logic after calling the method to modify the group alias here
}];
1
// Modify the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
NSString *groupAlias = @"NewAlias";
NSString *groupID = @"GroupID";
[zim updateGroupAlias:groupAlias groupID:groupID callback:^(NSString *groupID, NSString *groupAlias, ZIMError *errorInfo) {
// Write your business logic after calling the method to modify the group alias here
}];
1
// Modify the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
std::string group_alias = "NewAlias";
std::string group_id = "GroupID";
zim_->updateGroupAlias(group_alias, group_id,
[=](const std::string &groupID, const std::string &groupAlias, zim::ZIMError errorInfo){
int error_code = errorInfo.code;
});
1
// Modify the group alias
try {
const groupAlias = "new_group_alias_example"; // groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
const groupID = "example_group_id";
// Call the updateGroupAlias method
const result = await zim.updateGroupAlias(groupAlias, groupID);
console.log("Update succeeded:", result);
} catch (error) {
console.error("Update failed:", error);
}
1
// Update the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
String groupAlias = 'newAlias';
String groupId = 'groupID';
try{
ZIMGroupAliasUpdatedResult? result = await ZIM.getInstance()?.updateGroupAlias(groupAlias, groupId);
} on PlatformException catch (onError){
onError.code; // Error code
onError.message; // Error message
}
1
After the modification is successful, all devices of the user can receive notifications through groupAliasUpdated.
// Listen for group alias update notifications
public class SelfEventHandler extends ZIMEventHandler {
@Override
public void onGroupAliasUpdated(ZIM zim, String groupAlias, String operatedUserID, String groupID) {
// Business logic
}
}
1
@interface ZIMEventHandlerImpl : NSObject<ZIMEventHandler>
+(ZIMEventHandlerImpl *)getInstance();
@end
@implementation ZIMEventHandlerImpl
// Listen for group alias update notifications
- (void)zim:(ZIM *)zim
groupAliasUpdated:(NSString *)groupAlias
operatedUserID:(NSString *)operatedUserID
groupID:(NSString *)groupID {
// Business logic
}
// Other callback events...
@end
ZIMEventHandlerImpl *eventHandlerImpl = [ZIMEventHandlerImpl getInstance];
[zim setEventHandler: eventHandlerImpl];
1
@interface ZIMEventHandlerImpl : NSObject<ZIMEventHandler>
+(ZIMEventHandlerImpl *)getInstance();
@end
@implementation ZIMEventHandlerImpl
// Listen for group alias update notifications
- (void)zim:(ZIM *)zim
groupAliasUpdated:(NSString *)groupAlias
operatedUserID:(NSString *)operatedUserID
groupID:(NSString *)groupID {
// Business logic
}
// Other callback events...
@end
ZIMEventHandlerImpl *eventHandlerImpl = [ZIMEventHandlerImpl getInstance];
[zim setEventHandler: eventHandlerImpl];
1
// Listen for group alias update notifications
class zim_event_handler : public zim::ZIMEventHandler {
void onGroupAliasUpdated(ZIM * /*zim*/, const std::string & /*groupAlias*/,
const std::string & /*operatedUserID*/,
const std::string & /*groupID*/) override {
// Business logic
}
}
1
// Listen for group alias update notifications
zim.on('groupAliasUpdated', function (zim, { groupID, groupAlias, operatedUserID }) {
// You can handle the logic after the group alias is updated here, such as updating the UI or notifying the user
});
1
// Listen to group alias modification notification
ZIMEventHandler.onGroupAliasUpdated = (ZIM zim, String groupAlias, String operatedUserID, String groupID){
// Your logic
};
1
In addition, the user will also receive the conversationChanged callback to know when the conversationAlias
is updated. For more details, please refer to Get the conversation list - Listen for conversation changes.