isCoHostButtonEnable method

bool isCoHostButtonEnable()

Implementation

bool isCoHostButtonEnable() {
  final String? myMetadata = widget.viewModel.room.localParticipant?.metadata;
  final String? targetMetadata = widget.participant.metadata;

  final bool amIHost = Utils.isHost(myMetadata);
  final bool amICoHost = Utils.isCoHost(myMetadata);

  final bool isTargetHost = Utils.isHost(targetMetadata);
  final bool isTargetCoHost = Utils.isCoHost(targetMetadata);
  final bool isTargetGuest = !isTargetHost && !isTargetCoHost;

  // ❌ Cannot modify the Host
  if (isTargetHost) return false;

  // ✅ Host or Co-Host can demote a Co-Host
  if ((amIHost || amICoHost) && isTargetCoHost) return true;

  // ✅ Host or Co-Host can promote a Guest to Co-Host
  if ((amIHost || amICoHost) && isTargetGuest) {
    final allowMultiple = widget.viewModel.meetingDetails.features?.isAllowMultipleCoHost() == true;
    if (allowMultiple) {
      return true;
    } else {
      return widget.viewModel.coHostCount < 1;
    }
  }

  // ❌ In all other cases
  return false;
}