diff --git a/atproto_firehose.py b/atproto_firehose.py index 4dab7b7..9f7dc16 100644 --- a/atproto_firehose.py +++ b/atproto_firehose.py @@ -89,6 +89,8 @@ def subscribe(): match = AT_URI_PATTERN.match(did_or_ref['uri']) if match: did = match.group('repo') + else: + return else: did = did_or_ref @@ -110,7 +112,7 @@ def subscribe(): # mentions for facet in record.get('facets', []): for feature in facet['features']: - if feature['$type'] == '#mention': + if feature['$type'] == 'app.bsky.richtext.facet#mention': maybe_add(feature['did']) # TODO: quote posts diff --git a/tests/test_atproto_firehose.py b/tests/test_atproto_firehose.py index 5b2a8bc..3ebf91a 100644 --- a/tests/test_atproto_firehose.py +++ b/tests/test_atproto_firehose.py @@ -135,6 +135,65 @@ class ATProtoFirehoseSubscribeTest(TestCase): self.make_user('did:plc:bob', cls=ATProto, enabled_protocols=['eefake']) self.assert_doesnt_enqueue(POST_BSKY) + def test_reply_direct_to_our_user(self): + self.assert_enqueues({ + '$type': 'app.bsky.feed.post', + 'text': 'I hereby reply', + 'reply': { + '$type': 'app.bsky.feed.post#replyRef', + 'parent': {'uri': 'at://did:alice/app.bsky.feed.post/parent-tid'}, + 'root': {'uri': '-'}, + }, + }) + + def test_reply_indirect_to_our_user(self): + self.assert_enqueues({ + '$type': 'app.bsky.feed.post', + 'text': 'I hereby reply', + 'reply': { + '$type': 'app.bsky.feed.post#replyRef', + 'root': {'uri': 'at://did:alice/app.bsky.feed.post/parent-tid'}, + 'parent': {'uri': '-'}, + }, + }) + + def test_reply_indirect_to_other(self): + self.assert_doesnt_enqueue({ + '$type': 'app.bsky.feed.post', + 'text': 'I hereby reply', + 'reply': { + '$type': 'app.bsky.feed.post#replyRef', + 'parent': {'uri': 'at://did:bob/app.bsky.feed.post/parent-tid'}, + 'root': {'uri': '-'}, + }, + }) + + def test_mention_our_user(self): + self.assert_enqueues({ + '$type': 'app.bsky.feed.post', + 'text': 'foo @alice bar', + 'facets': [{ + '$type': 'app.bsky.richtext.facet', + 'features': [{ + '$type': 'app.bsky.richtext.facet#mention', + 'did': 'did:alice', + }], + }], + }) + + def test_mention_other(self): + self.assert_doesnt_enqueue({ + '$type': 'app.bsky.feed.post', + 'text': 'foo @bob bar', + 'facets': [{ + '$type': 'app.bsky.richtext.facet', + 'features': [{ + '$type': 'app.bsky.richtext.facet#mention', + 'did': 'did:bob', + }], + }], + }) + def test_like_of_our_user(self): self.assert_enqueues({ '$type': 'app.bsky.feed.like',