messageParticipants function

void messageParticipants(
  1. MessageParticipantsOptions options
)

Sends a direct message to a participant if the current member has the necessary permissions.

This function checks if the current member has the required permissions based on their level and co-host responsibilities. If authorized, it initiates a direct message.

Example:

final options = MessageParticipantsOptions(
  coHostResponsibility: [CoHostResponsibility(name: 'chat', value: true)],
  participant: Participant(name: 'John Doe', islevel: '1'),
  member: 'currentMember',
  islevel: '2',
  showAlert: (alert) => print(alert.message),
  coHost: 'coHostMember',
  updateIsMessagesModalVisible: (isVisible) => print('Modal visibility: $isVisible'),
  updateDirectMessageDetails: (participant) => print('Direct message details: $participant'),
  updateStartDirectMessage: (start) => print('Start direct message: $start'),
);

messageParticipants(options);

Implementation

void messageParticipants(MessageParticipantsOptions options) {
  bool chatValue = false;

  try {
    chatValue = options.coHostResponsibility
        .firstWhere((item) => item.name == 'chat',
            orElse: () => CoHostResponsibility(
                name: 'chat', value: false, dedicated: false))
        .value;
  } catch (_) {
    chatValue = false;
  }

  if (options.islevel == '2' ||
      (options.coHost == options.member && chatValue)) {
    if (options.participant.islevel != '2') {
      options.updateDirectMessageDetails(options.participant);
      options.updateStartDirectMessage(true);
      options.updateIsMessagesModalVisible(true);
    }
  } else {
    options.showAlert?.call(
      message: 'You are not allowed to send this message',
      type: 'danger',
      duration: 3000,
    );
  }
}