buildPostText method

Future<PostText> buildPostText(
  1. String text, {
  2. HandleResolver? handleResolver,
})

Formats text and resolves its facets — mentions, links, hashtags — returning both in the types post.create and ThreadPost take.

Getting a faceted post right by hand takes three steps that are easy to get subtly wrong, and this does all three:

  1. Format first, then resolve. Markdown links only become link facets after formatting, so resolving before formatting silently loses them.
  2. Post the formatted text, not the original. Facet ranges are byte offsets into the formatted string; pairing them with the string that was passed in points every link at the wrong characters. PostText keeps the two together so they cannot be separated by accident.
  3. Resolve mentions through this client. Left to itself bluesky_text opens its own HTTP connection to a default host, so an account on a self-hosted PDS resolved its mentions against the wrong server — and none of the client's configuration (service, timeout, retry policy, custom getClient, proxy headers) applied to that call. Mentions are resolved with com.atproto.identity.resolveHandle on this client instead, so they travel the same path as every other request.

A mention whose handle does not resolve carries no facet and is reported in PostText.unresolvedHandles rather than dropped silently.

Pass handleResolver to answer mention DIDs from a cache of your own instead of one request per mention.

final built = await bluesky.feed.buildPostText(
  'hello @alice.bsky.social, see https://atprotodart.com #dart',
);
if (built.hasUnresolvedHandles) {
  print('could not resolve: ${built.unresolvedHandles}');
}

// Ready for either call, with no conversion at the call site.
await bluesky.feed.post.create(text: built.text, facets: built.facets);
final threadPost = ThreadPost(text: built.text, facets: built.facets);

See postText to build and publish in one call.

Implementation

Future<PostText> buildPostText(
  final String text, {
  final text_api.HandleResolver? handleResolver,
}) async {
  final data = await text_api.BlueskyText(
    text,
  ).toPostData(resolver: handleResolver ?? _resolveHandle);

  return PostText(
    text: data.text,
    facets: data.facets.map(RichtextFacet.fromJson).toList(),
    unresolvedHandles: data.unresolvedHandles,
  );
}