Mercurial > silorider
changeset 74:08ee3ffbe508
Fix Bluesky formatting for posts too long, or with a link
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 10 Aug 2024 21:19:23 -0700 |
parents | 63bb8d716204 |
children | 2e57d0fd8ceb |
files | silorider/format.py tests/test_silos_bluesky.py |
diffstat | 2 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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( + """<p class="p-name">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</p> + <a class="u-url" href="/01234.html">permalink</a>""")) + + 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)],