addAttributes method

Future<Map<String, int>?> addAttributes(
  1. String roomId, {
  2. required Map<String, String> attributes,
  3. bool deleteWhenLeft = false,
  4. bool overwrite = false,
})

~english Sets custom chat room attributes.

Param roomId The chat room ID.

Param attributes The chat room attributes to add. The attributes are in key-value format.

Note: In a key-value pair, the key is the attribute name that can contain 128 characters at most; the value is the attribute value that cannot exceed 4096 characters. A chat room can have a maximum of 100 custom attributes and the total length of custom chat room attributes cannot exceed 10 GB for each app. Attribute keys support the following character sets:

    • 26 lowercase English letters (a-z)
    • 26 uppercase English letters (A-Z)
    • 10 numbers (0-9)
    • "_", "-", "."

Param deleteWhenLeft Whether to delete the chat room attributes set by the member when he or she exits the chat room.

Param overwrite Whether to overwrite the attributes with same key set by others.

Return failureKeys map is returned in key-value format, where the key is the attribute key and the value is the reason for the failure.

Throws A description of the exception. See EMError. ~end

~chinese 设置自定义聊天室属性。

Param roomId 聊天室 ID。

Param attributes 要添加的聊天室属性。属性采用键值格式。

Param deleteWhenLeft 退出聊天室时是否删除该成员设置的聊天室属性。

Param overwrite 是否覆盖其他人设置的相同键的属性。

Return ' failureKeys map '以键值格式返回,其中键是属性键,值是失败的原因。

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 EMError

~end

Implementation

Future<Map<String, int>?> addAttributes(
  String roomId, {
  required Map<String, String> attributes,
  bool deleteWhenLeft = false,
  bool overwrite = false,
}) async {
  Map req = {
    "roomId": roomId,
    "attributes": attributes,
    "autoDelete": deleteWhenLeft,
    "forced": overwrite,
  };

  Map result = await _channel.invokeMethod(
    ChatMethodKeys.setChatRoomAttributes,
    req,
  );
  try {
    EMError.hasErrorFromResult(result);
    return result[ChatMethodKeys.setChatRoomAttributes]?.cast<String, int>();
  } on EMError catch (e) {
    throw e;
  }
}