setGroupCounters static method

Future<V2TimValueCallback<Map<String, int>>> setGroupCounters({
  1. required String groupID,
  2. required Map<String, int> counters,
})

Implementation

static Future<V2TimValueCallback<Map<String, int>>> setGroupCounters({
  required String groupID,
  required Map<String, int> counters,
}) async {
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  List<Map<String, dynamic>> cparam = [];
  counters.forEach((key, value) {
    cparam.add({
      "group_counter_key": key,
      "group_counter_value": value,
    });
  });
  Pointer<Uint8> countersPtr = Tools.string2PointerInt8(json.encode(cparam));
  Pointer<Uint8> groupIDPtr = Tools.string2PointerInt8(groupID);
  int res = desktopSDK.D_TIMGroupSetGroupCounters(groupIDPtr, countersPtr, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<Map<String, int>>.fromJson({
      "code": res,
      "desc": "",
      "data": Map<String, int>.from({}),
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    List<Map<String, dynamic>> dataList = List<Map<String, dynamic>>.from(json.decode(data["json_param"].isEmpty ? json.encode([]) : data["json_param"]));
    Map<String, int> couner = Map.from({});
    for (var i = 0; i < dataList.length; i++) {
      var item = dataList[i];
      couner[item["group_counter_key"]] = item["group_counter_value"];
    }

    return V2TimValueCallback<Map<String, int>>.fromJson({
      "code": data["code"],
      "desc": data["desc"],
      "data": couner,
    });
  }
}