trypost/app/Services/Social
Paulo Castellano 6496588bbc
Defuse links in X posts to avoid the link-post fee (#308)
X bills a post containing a URL at a much higher rate than a plain post, and
its algorithm demotes link posts. The X version of a post now rewrites every
URL non-clickable (https://example.com/post becomes example(.)com/post):
scheme and www. dropped, every dot of the host replaced with (.).

Leaving a single dot intact would still leave a resolvable domain for X to
detect, so all of them are broken. A scheme or www. proves a token is a URL on
its own; a bare host only counts when its last label is a delegated TLD, which
is the one thing telling acme.com apart from Node.js. That check runs against
App\Support\LinkTlds, generated from the whole IANA root zone in every form a
TLD can appear in a post -- ASCII, punycode and the Unicode it decodes to --
because whatever X links is what X bills, so a hand-picked subset would leave
us paying for its gaps. If the regex engine bails out on pathological input the
original content is returned instead of crashing the publisher.

The transform lives in the Platform::X arm of ContentSanitizer, so it reaches
publishing and the app/API/MCP previews from one place and cannot touch any
other network. Off by default; opt in with X_DEFUSE_LINKS.

The editor counts characters and renders its preview client-side and cannot ask
the server on every keystroke, so the rewrite is mirrored in TypeScript. PHP
stays the source of truth: a parity test fails if the two TLD sets drift, and a
browser test drives the real editor so the mirror is covered rather than
assumed. Without it the composer promised text the network never receives.

Character limits now measure the text a reader will see: sanitized, then with
markup resolved away. Measuring the raw draft blocked saving posts that publish
fine and let through posts the network rejects, and counted the editor's HTML
toward the limit. Measuring the sanitized form alone would have counted
Telegram's escaped entities, rejecting messages Telegram accepts.

Empty content is handled once inside the sanitizer instead of by a guard
repeated at every call site.
2026-08-29 15:31:05 -03:00
..
Concerns Defuse links in X posts to avoid the link-post fee (#308) 2026-08-29 15:31:05 -03:00
Discord Harden per-image alt text across publishers, validation, and attach paths 2026-07-16 13:55:33 -03:00
LinkCard fix(posts): cache the link card as an array, not the DTO 2026-07-17 16:34:04 -03:00
Meta Connect the Pages a login only reaches through a Business Portfolio (#301) 2026-08-26 10:42:59 -03:00
Telegram Allow multiple social accounts per network via env (#286) 2026-08-25 07:28:14 -03:00
AbstractLinkedInPublisher.php fix: LinkedIn company page post URL missing the post ID (#272) 2026-08-11 12:36:14 -03:00
BlueskyAnalytics.php Centralize AT Protocol NSIDs in BlueskyLexicon 2026-06-13 20:18:39 -03:00
BlueskyLexicon.php feat(bluesky): add link preview cards for posts 2026-07-17 14:32:40 -03:00
BlueskyPublisher.php Resume in-flight Instagram and TikTok publishes without duplicates (#281) 2026-08-16 15:34:53 -03:00
ConnectionVerifier.php Remove the X API reads that buy nothing (#299) 2026-08-20 17:58:16 -03:00
ContentSanitizer.php Defuse links in X posts to avoid the link-post fee (#308) 2026-08-29 15:31:05 -03:00
FacebookAnalytics.php refactor: localize analytics metrics and overhaul UI components and dashboard layouts 2026-05-06 15:39:10 -03:00
FacebookPublisher.php Extract alt-text truncation onto MediaItem and close test gaps 2026-07-11 10:34:57 -03:00
InstagramAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
InstagramPublisher.php Resume in-flight Instagram and TikTok publishes without duplicates (#281) 2026-08-16 15:34:53 -03:00
LinkedInPageAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
LinkedInPagePublisher.php fix: LinkedIn company page post URL missing the post ID (#272) 2026-08-11 12:36:14 -03:00
LinkedInPublisher.php refactor(linkedin): extract shared publisher base and fix multi-image carousel 2026-06-25 10:17:02 -03:00
MastodonAnalytics.php refactor(social): use config for OAuth hosts everywhere 2026-05-19 08:34:35 -03:00
MastodonPublisher.php Harden per-image alt text across publishers, validation, and attach paths 2026-07-16 13:55:33 -03:00
PinterestAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
PinterestPublisher.php fix: Pinterest video processing timeout — longer poll + retry (#246) 2026-08-06 20:49:37 -03:00
ThreadsAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
ThreadsPublisher.php Fix transient Threads media container failures (#280) 2026-08-13 12:18:19 -03:00
TikTokAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
TikTokCreatorInfo.php fix(tiktok): send an empty JSON object to creator_info (#224) 2026-08-05 18:39:32 -03:00
TikTokPublisher.php Resume in-flight Instagram and TikTok publishes without duplicates (#281) 2026-08-16 15:34:53 -03:00
TokenRedactor.php refactor(social): TokenRedactor::redact accepts nullable 2026-05-19 09:25:01 -03:00
TokenRefreshClient.php Stop Meta rate-limit errors from disconnecting Instagram/Threads tokens 2026-07-03 11:07:54 -03:00
XAnalytics.php Remove the X API reads that buy nothing (#299) 2026-08-20 17:58:16 -03:00
XPublisher.php fix(x): poll official media upload STATUS endpoint 2026-07-24 10:43:32 -03:00
YouTubeAnalytics.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00
YouTubePublisher.php Keep Instagram/Threads tokens extended while still valid 2026-07-03 09:18:45 -03:00