sendAction method

Future<TCICActionRepModel?> sendAction(
  1. String userId,
  2. MemberActionType actionType
)

Implementation

Future<TCICActionRepModel?> sendAction(
  String userId,
  MemberActionType actionType,
) async {
  final key = "${_config.userId}_${actionType.name}";
  final lastSendTimestamp = _uiInfoObs.getUserActionSendMap(key);
  final now = DateTime.now().millisecondsSinceEpoch;
  if (lastSendTimestamp > 0 && now - lastSendTimestamp < 2000) {
    TCICLog.error(
      "sendAction failed: actionType is $actionType, lastSendTimestamp is $lastSendTimestamp",
      actionModule: ActionModule.tcicController.name,
      actionName: ActionName.sendAction.name,
    );
    TCICToast.show(StringEnum.sendActionTooFast);
    return null;
  }
  _uiInfoObs.setUserActionSendMap(key, now);
  final body = ActionBody(
    classId: _config.classId,
    userId: userId,
    actionType: actionType,
  );
  final data = await networkService.sendAction(body);
  if (data?.errorCode == 0) {
    _uiInfoObs.setUserActionSendMap(key, 0);
    final member = _membersInfoObs.getMemberInfoByUserId(userId);
    final name = member?.userName ?? "";
    TCICToast.show(
      StringEnum.sendActionSuccess,
      params: [_getActionSendToast(actionType, name)],
    );
    return data;
  } else {
    TCICLog.error(
      "sendAction failed: errorCode is ${data?.errorCode}, errorMsg is ${data?.errorMsg}",
      actionModule: ActionModule.tcicController.name,
      actionName: ActionName.sendAction.name,
    );
    if (actionType == MemberActionType.cameraOpen ||
        actionType == MemberActionType.micOpen) {
      final member = _membersInfoObs.getMemberInfoByUserId(userId);
      final name = member?.userName ?? "";
      TCICToast.show(
        StringEnum.sendActionSuccess,
        params: [_getActionSendToast(actionType, name)],
      );
    } else {
      TCICToast.showString(data?.errorMsg ?? '');
    }
    return null;
  }
}