Skip to content

Commit

Permalink
bluesky.from_as1: skip standalone hashtags beyond the first 8
Browse files Browse the repository at this point in the history
...to stay under the app.bsky.feed.post#tags lexicon maxLength. fixes snarfed/bridgy-fed#1770
  • Loading branch information
snarfed committed Feb 12, 2025
1 parent 3a14cd4 commit 7bba0b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,12 @@ def from_as1(obj, out_type=None, blobs=None, aspects=None, client=None,
index = facet.get('index')

if not index:
max = LEXRPC_TRUNCATE.defs['app.bsky.feed.post']['record']['properties']['tags']['maxLength']
if tag_type == 'hashtag':
standalone_tags.append(name)
if len(standalone_tags) < max:
standalone_tags.append(name)
else:
logger.warning(f'More than {max} standalone hashtags, omitting "{name}"')
continue

if index.get('byteStart', 0) >= text_byte_end:
Expand Down
24 changes: 24 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,30 @@ def test_from_as1_tag_hashtag_not_in_content(self):
}],
}))

def test_from_as1_too_many_hashtags(self):
self.assert_equals({
'$type': 'app.bsky.feed.post',
'text': 'foo bar',
'tags': ['1', '2', '3', '4', '5', '6', '7', '8'],
'createdAt': '2022-01-02T03:04:05.000Z',
'fooOriginalText': 'foo bar',
}, self.from_as1({
'objectType': 'note',
'content': 'foo bar',
'tags': [
{'objectType': 'hashtag', 'displayName': '1'},
{'objectType': 'hashtag', 'displayName': '2'},
{'objectType': 'hashtag', 'displayName': '3'},
{'objectType': 'hashtag', 'displayName': '4'},
{'objectType': 'hashtag', 'displayName': '5'},
{'objectType': 'hashtag', 'displayName': '6'},
{'objectType': 'hashtag', 'displayName': '7'},
{'objectType': 'hashtag', 'displayName': '8'},
{'objectType': 'hashtag', 'displayName': '9'},
{'objectType': 'hashtag', 'displayName': '10'},
],
}))

def test_from_as1_tag_mention_guess_index(self):
self.assert_equals(POST_BSKY_FACET_MENTION, self.from_as1({
'objectType': 'note',
Expand Down

0 comments on commit 7bba0b8

Please sign in to comment.