getUI method

Implementation

ModerationUI getUI(final ModerationBehaviorContext context) {
  bool noOverride = false;
  final filters = <ModerationCause>[];
  final blurs = <ModerationCause>[];
  final alerts = <ModerationCause>[];
  final informs = <ModerationCause>[];

  for (final cause in causes) {
    if (cause is UModerationCauseBlocking ||
        cause is UModerationCauseBlockedBy ||
        cause is UModerationCauseBlockOther) {
      if (me) continue;

      if (context.isProfileList || context.isContentList) {
        filters.add(cause);
      }

      if (!cause.downgraded) {
        if (kBlockBehavior[context.name] == ModerationBehavior.blur) {
          noOverride = true;
          blurs.add(cause);
        } else if (kBlockBehavior[context.name] == ModerationBehavior.alert) {
          alerts.add(cause);
        } else if (kBlockBehavior[context.name] ==
            ModerationBehavior.inform) {
          informs.add(cause);
        }
      }
    } else if (cause is UModerationCauseMuted) {
      if (me) continue;

      if (context.isProfileList || context.isContentList) {
        filters.add(cause);
      }

      if (!cause.downgraded) {
        if (kMuteBehavior[context.name] == ModerationBehavior.blur) {
          blurs.add(cause);
        } else if (kMuteBehavior[context.name] == ModerationBehavior.alert) {
          alerts.add(cause);
        } else if (kMuteBehavior[context.name] == ModerationBehavior.inform) {
          informs.add(cause);
        }
      }
    } else if (cause is UModerationCauseMuteWord) {
      if (me) continue;

      if (context.isContentList) {
        filters.add(cause);
      }

      if (!cause.downgraded) {
        if (kMuteWordBehavior[context.name] == ModerationBehavior.blur) {
          blurs.add(cause);
        } else if (kMuteWordBehavior[context.name] ==
            ModerationBehavior.alert) {
          alerts.add(cause);
        } else if (kMuteWordBehavior[context.name] ==
            ModerationBehavior.inform) {
          informs.add(cause);
        }
      }
    } else if (cause is UModerationCauseHidden) {
      if (context.isProfileList || context.isContentList) {
        filters.add(cause);
      }

      if (!cause.downgraded) {
        if (kHideBehavior[context.name] == ModerationBehavior.blur) {
          blurs.add(cause);
        } else if (kHideBehavior[context.name] == ModerationBehavior.alert) {
          alerts.add(cause);
        } else if (kHideBehavior[context.name] == ModerationBehavior.inform) {
          informs.add(cause);
        }
      }
    } else if (cause is UModerationCauseLabel) {
      final labelCause = cause.whenOrNull(label: (data) => data)!;

      if (context.isProfileList && labelCause.target == LabelTarget.account) {
        if (labelCause.setting == LabelPreference.hide && !me) {
          filters.add(cause);
        }
      } else if (context.isContentList &&
          (labelCause.target == LabelTarget.account ||
              labelCause.target == LabelTarget.content)) {
        if (labelCause.setting == LabelPreference.hide && !me) {
          filters.add(cause);
        }
      }

      if (!labelCause.downgraded) {
        if (labelCause.behavior[context] == ModerationBehavior.blur) {
          blurs.add(cause);
          if (labelCause.noOverride && !me) {
            noOverride = true;
          }
        } else if (labelCause.behavior[context] == ModerationBehavior.alert) {
          alerts.add(cause);
        } else if (labelCause.behavior[context] ==
            ModerationBehavior.inform) {
          informs.add(cause);
        }
      }
    }
  }

  return ModerationUI(
    noOverride: noOverride,
    filters: filters..sort(_sortByCausePriority),
    blurs: blurs..sort(_sortByCausePriority),
    alerts: alerts,
    informs: informs,
  );
}