inviteActions function

FutureOr<List<(String, FutureOr<void> Function()?)>> inviteActions(
  1. BuildContext context,
  2. Notification notification
)

Actions builder for NotificationType.invite.

Implementation

FutureOr<List<(String, FutureOr<void> Function()?)>> inviteActions(BuildContext context, Notification notification) async {
  final plan = context.watch<CalendarPlanRepository>();

  final invite = await plan.getInvites(inviteeId: notification.context).then((value) => value.firstOrNull);

  if (invite == null) return [];

  if (invite.status != PlanInviteStatus.pending) {
    return [
      (
        invite.status == PlanInviteStatus.accepted ? 'Accepted' : 'Declined',
        null,
      ),
    ];
  }

  return [
    (
      'Accept',
      () async => plan.acceptInvite(notification.context!),
    ),
    (
      'Decline',
      () async => plan.declineInvite(notification.context!),
    ),
  ];
}