# HG changeset patch # User Ludovic Chabant # Date 1723349963 25200 # Node ID 08ee3ffbe508af0eca114988ee1d2fdb0cb43bad # Parent 63bb8d716204fb31c37427d0819c96b740243db5 Fix Bluesky formatting for posts too long, or with a link diff -r 63bb8d716204 -r 08ee3ffbe508 silorider/format.py --- a/silorider/format.py Fri Feb 02 21:08:10 2024 -0800 +++ b/silorider/format.py Sat Aug 10 21:19:23 2024 -0700 @@ -86,10 +86,11 @@ # stuff with it (for instance the Bluesky silo will remember the # byte offsets to insert a hyperlink). if do_add_url and url: + ctx.reportAddedText(1) # for the space before the URL. url = _process_end_url(url, ctx) + url_len = ctx.url_flattener.measureUrl(url) + ctx.reportAddedText(url_len) card.text += ' ' + url - url_len = ctx.url_flattener.measureUrl(url) - ctx.reportAddedText(1 + url_len) return card @@ -184,10 +185,10 @@ def limit_reached(self): return self._limit_reached - def processText(self, txt, allow_shorten=True): + def processText(self, txt, allow_shorten=True, check_limit=True): added_len = len(txt) next_text_length = self._text_length + added_len - if self.limit <= 0 or next_text_length <= self.limit: + if (not check_limit) or (self.limit <= 0 or next_text_length <= self.limit): self._text_length = next_text_length self._byte_length += len(txt.encode()) return txt diff -r 63bb8d716204 -r 08ee3ffbe508 tests/test_silos_bluesky.py --- a/tests/test_silos_bluesky.py Fri Feb 02 21:08:10 2024 -0800 +++ b/tests/test_silos_bluesky.py Sat Aug 10 21:19:23 2024 -0700 @@ -143,6 +143,19 @@ assert post[2] == [facet] +def test_one_micropost_too_long(cli, feedutil, bskymock): + cli.appendSiloConfig('test', 'bluesky') + bskymock.installCredentials(cli, 'test') + + feed = cli.createTempFeed(feedutil.makeFeed( + """

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum

+ permalink""")) + + cli.setFeedConfig('feed', feed) + ctx, _ = cli.run('process') + post = ctx.silos[0].client.posts[0] + assert post[0] == "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate... /01234.html" + def _make_link_facet(url, start, end): return atprotomodels.AppBskyRichtextFacet.Main( features=[atprotomodels.AppBskyRichtextFacet.Link(uri=url)],