setGroupInfo static method

Future<V2TimCallback> setGroupInfo({
  1. required V2TimGroupInfo info,
})

Implementation

static Future<V2TimCallback> setGroupInfo({
  required V2TimGroupInfo info,
}) async {
  List<Map<String, dynamic>> custom_arr = List.empty(growable: true);
  int flag = 0x00;

  Map<String, dynamic> param = Map<String, dynamic>.from({
    "group_modify_info_param_group_id": info.groupID,
  });
  if (info.approveOpt != null) {
    flag = flag | 0x01 << 12;

    param["group_modify_info_param_approve_option"] = info.approveOpt;
  }

  if (info.customInfo != null) {
    flag = flag | 0x01 << 11;
    info.customInfo!.forEach((key, value) {
      custom_arr.add({
        "group_info_custom_string_info_key": key,
        "group_info_custom_string_info_value": value,
      });
    });
  }
  if (info.groupName != null) {
    flag = flag | 0x01;

    param["group_modify_info_param_group_name"] = info.groupName;
  }
  if (info.notification != null) {
    flag = flag | (0x01 << 1);

    param["group_modify_info_param_notification"] = info.notification;
  }
  if (info.introduction != null) {
    flag = flag | 0x01 << 2;

    param["group_modify_info_param_introduction"] = info.introduction;
  }
  if (info.faceUrl != null) {
    flag = flag | 0x01 << 3;

    param["group_modify_info_param_face_url"] = info.faceUrl;
  }
  if (info.groupAddOpt != null) {
    flag = flag | 0x01 << 4;

    param["group_modify_info_param_add_option"] = info.groupAddOpt;
  }
  // if (info.memberCount != null) {
  //   flag = flag | 0x01 << 5;

  //   param["group_modify_info_param_max_member_num"] = info.memberCount;
  // }
  if (info.isAllMuted != null) {
    flag = flag | 0x01 << 8;

    param["group_modify_info_param_is_shutup_all"] = info.isAllMuted;
  }
  if (info.customInfo != null && info.customInfo!.isNotEmpty) {
    flag = flag | 0x01 << 9;

    param["group_modify_info_param_custom_info"] = custom_arr;
  }
  // if (info.owner != null) {
  //   flag = flag | 0x01 << 31;
  //   param["group_modify_info_param_owner"] = info.owner;
  // }
  param["group_modify_info_param_modify_flag"] = flag;

  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> json_group_modifyinfo_param = Tools.string2PointerInt8(json.encode(param));
  int res = desktopSDK.D_TIMGroupModifyGroupInfo(json_group_modifyinfo_param, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimCallback.fromJson({
      "code": res,
      "desc": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    return V2TimCallback.fromJson({
      "code": data["code"],
      "desc": data["desc"],
    });
  }
}