Class Mentions

java.lang.Object
su.onno.ui.comments.Mentions

public final class Mentions extends Object
The on-the-wire syntax for a comment link: @[Display](kind/name/id) for a mention and #[Display](kind/name/id) for a reference. Keeping the link in the text (rather than in a side table) means Comment.body stays a single string. The Display carried in the token is only a snapshot for fallback; the live display, avatar and read access are resolved at render time by MentionResolver.

This class is a pure, side-effect-free parser/serializer (round-trip tested). The name segment is the URL-safe route name (snake_case), so the same token body is also a navigable onno:// route on the client.

  • Method Details

    • token

      public static String token(String label, MentionRef ref)
      Serialize a mention to its token form. The label is sanitized so it can't break the syntax.
    • token

      public static String token(char marker, String label, MentionRef ref)
      Serialize a mention or reference to its token form.
    • sanitizeLabel

      public static String sanitizeLabel(String label)
      A label safe to embed between [ and ]: collapse newlines and drop ].
    • occurrences

      public static List<Mentions.Occurrence> occurrences(String body)
      Every mention occurrence in body order (duplicates included), or empty when there are none.
    • parse

      public static List<MentionRef> parse(String body)
      The distinct mention refs in a body, first-seen order preserved.
    • parse

      public static List<MentionRef> parse(String body, char marker)
      The distinct refs for one marker (@ mentions or # references), first-seen.
    • degrade

      public static String degrade(String body, Predicate<MentionRef> degrade)
      Rewrite a body, degrading every mention whose ref satisfies degrade to its plain label text (the token's display snapshot). Used on POST to strip mentions the author can't read, so a stored comment never smuggles a clickable link to a hidden record.
    • routeName

      public static String routeName(String logicalName)
      The URL-safe route segment for a logical name: snake_case, mirroring the client's toSnakeCase (and SurfaceDivBuilder.routeNameOf) so a mention token's route is the same one a list-row tap or ref link produces.