- Android
- iOS
- JavaScript
- Flutter
- ReactNative
- HarmonyOS
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
API Definition
/**
* set chatroom attributes
*
* @param chatroomId chatroom ID
* @param attributes Chatroom attributes. Both key and value are strings; up to 100 distinct attributes are supported.
* The client cannot modify a key that was not set by the current user (returns JErrorCode.CHATROOM_KEY_UNAUTHORIZED).
* @param callback completion callback
* JErrorCode.NONE indicates that all attributes were set successfully.
* Other codes indicate that one or more keys failed. Every failed key is returned with its error code; see JErrorCode for the corresponding definition.
*/
void setAttributes(String chatroomId, Map<String, String> attributes, IChatroomAttributesUpdateCallback callback);
Example
Map<String, String> attributes = new HashMap<>();
attributes.put("key1", "value1");
attributes.put("key2", "value2");
JIM.getInstance().getChatroomManager().setAttributes("chatroomId1", attributes, new IChatroomManager.IChatroomAttributesUpdateCallback() {
@Override
public void onComplete(int errorCode, Map<String, Integer> failedKeys) {
}
});
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
API Definition
/// Set chatroom attributes.
/// - Parameters:
/// - attributes: Chatroom attributes. Both key and value are strings; up to 100 distinct attributes are supported. The client cannot modify a key that was not set by the current user (returns JErrorCodeChatroomKeyUnauthorized).
/// - chatroomId: chatroom ID
/// - completeBlock: Completion callback.
/// JErrorCodeNone indicates that all attributes were set successfully.
/// Other codes indicate that one or more keys failed. Every failed key is returned with its error code; see JErrorCode for the corresponding definition.
- (void)setAttributes:(NSDictionary <NSString *, NSString *> *)attributes
forChatroom:(NSString *)chatroomId
complete:(void (^)(JErrorCode code, NSDictionary<NSString *, NSNumber *> *failedKeys))completeBlock;
Example
NSDictionary <NSString *, NSString *> *attr = @{@"key1":@"value1", @"key2":@"value2"};
[JIM.shared.chatroomManager setAttributes:attr
forChatroom:@"chatroomId1"
complete:^(JErrorCode code, NSDictionary<NSString *,NSNumber *> *failedKeys) {
}];
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
Batch attribute updates can fail. For example, an update fails when a key was set by another member and isForce is not true. See the relevant status code.
Parameters
| Name | Type | Required | Default | Description | Version |
|---|---|---|---|---|---|
| chatroom | Object | Yes | None | Chatroom object. | 1.6.0 |
| chatroom.id | String | Yes | None | Chatroom ID. | 1.6.0 |
| chatroom.attributes | Array | Yes | None | Attribute list. | 1.6.0 |
chatroom.attributes item
| Name | Type | Required | Default | Description | Version |
|---|---|---|---|---|---|
| key | String | Yes | None | Attribute key. | 1.6.0 |
| value | String | Yes | None | Attribute value. | 1.6.0 |
| isForce | Boolean | No | false | Whether to force the update. | 1.6.0 |
| isAutoDel | Boolean | No | false | Whether to delete automatically after the user who set the attribute leaves the chatroom. | 1.6.0 |
Example
let chatroom = {
id: 'chatroom1001',
attributes: [
{ key: 'name', value: 'xiaoshan', isForce: true, isAutoDel },
{ key: 'age', value: 18 }
]
};
jim.setChatroomAttributes(chatroom).then((result) => {
console.log('set chatroom attributes successfully');
/*
result => { success: [{ key: 'name' }], fail:[{ key: 'age', code: 14006 }] }
*/
}, (error) => {
console.log('error', error);
});
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
Example
Map<String, String> attributes = {
"key1": "value1",
"key2": "value2"
};
await JuggleIm.instance.getChatroomManager().setAttributes("chatroomId1", attributes);
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
Example
import JuggleIM from 'juggleim-rnsdk';
const attributes: Record<string, string> = {
"key1": "value1",
"key2": "value2"
};
await JuggleIM.setChatroomAttributes("chatroomId1", attributes);
Set chatroom attributes in batches. Updates synchronize automatically to all chatroom members and are returned through the chatroom attribute-change event.
Example
let attributes = {
"key1": "value1",
"key2": "value2"
};
JuggleIm.instance.getChatroomManager().setAttributes("chatroomId1", attributes);