Skip to content

Commit

Permalink
tweak "bridged by Bridgy Fed" links in profile: use handle, add sourc…
Browse files Browse the repository at this point in the history
…e protocol

for #976
  • Loading branch information
snarfed committed Jun 6, 2024
1 parent ad81b18 commit 9e18b7f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
17 changes: 9 additions & 8 deletions protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,18 @@ def add_source_links(cls, obj, from_user):
return

id = obj.key.id() if obj.key else obj.our_as1.get('id')
proto_phrase = (PROTOCOLS[obj.source_protocol].PHRASE
if obj.source_protocol else '')
if proto_phrase:
proto_phrase = f' on {proto_phrase}'

if from_user.key and id == from_user.profile_id():
source_links = f'[<a href="https://{PRIMARY_DOMAIN}{from_user.user_page_path()}">bridged</a> from <a href="{from_user.web_url()}">{from_user.handle_or_id()}</a> by <a href="https://{PRIMARY_DOMAIN}/">Bridgy Fed</a>]'
source_links = f'[<a href="https://{PRIMARY_DOMAIN}{from_user.user_page_path()}">bridged</a> from <a href="{from_user.web_url()}">{from_user.handle}</a>{proto_phrase} by <a href="https://{PRIMARY_DOMAIN}/">Bridgy Fed</a>]'

else:
url = as1.get_url(obj.our_as1) or id
name = obj.our_as1.get('displayName') or obj.our_as1.get('username')
source = (util.pretty_link(url, text=name) if url
else name if name
else '')
if source:
source = ' from ' + source
source_links = f'[bridged{source} by <a href="https://{PRIMARY_DOMAIN}/">Bridgy Fed</a>]'
source = util.pretty_link(url) if url else (proto_phrase or '?')
source_links = f'[bridged from {source}{proto_phrase} by <a href="https://{PRIMARY_DOMAIN}/">Bridgy Fed</a>]'

if summary:
summary += '<br><br>'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_actor_handle_existing_user(self, _, __, ___):
**ACTOR_FAKE,
'name': 'fake:handle:user',
'type': 'Application',
'summary': '[<a href="https://fed.brid.gy/fa/fake:handle:user">bridged</a> from <a href="web:fake:user">fake:handle:user</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'summary': '[<a href="https://fed.brid.gy/fa/fake:handle:user">bridged</a> from <a href="web:fake:user">fake:handle:user</a> on fake-phrase by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
}, got.json, ignore=['attachment'])

def test_actor_handle_new_user(self, _, __, ___):
Expand All @@ -438,7 +438,7 @@ def test_actor_handle_new_user(self, _, __, ___):
**ACTOR_FAKE,
'name': 'fake:handle:user',
'type': 'Application',
'summary': '[<a href="https://fed.brid.gy/fa/fake:handle:user">bridged</a> from <a href="web:fake:user">fake:handle:user</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'summary': '[<a href="https://fed.brid.gy/fa/fake:handle:user">bridged</a> from <a href="web:fake:user">fake:handle:user</a> on fake-phrase by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
}, got.json, ignore=['attachment', 'publicKey'])

def test_actor_atproto_not_enabled(self, *_):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def test_create_for(self, mock_post, mock_create_task, mock_zone):
self.assertEqual({
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from fake:handle:us_er by Bridgy Fed]',
'description': 'hi there\n\n[bridged from fake:handle:us_er on fake-phrase by Bridgy Fed]',
'avatar': {
'$type': 'blob',
'mimeType': 'application/octet-stream',
Expand Down Expand Up @@ -881,7 +881,7 @@ def test_send_new_repo_includes_user_profile(self, mock_post, mock_create_task,
self.assertEqual({
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from fake:handle:user by Bridgy Fed]',
'description': 'hi there\n\n[bridged from fake:handle:user on fake-phrase by Bridgy Fed]',
'avatar': {
'$type': 'blob',
'ref': BLOB_CID,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_get_or_create_propagate_atproto(self, mock_post, mock_create_task):
self.assertEqual({
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from fake:handle:user by Bridgy Fed]',
'description': 'hi there\n\n[bridged from fake:handle:user on fake-phrase by Bridgy Fed]',
'labels': {
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val' : 'bridged-from-bridgy-fed-fake'}],
Expand Down
12 changes: 6 additions & 6 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,13 @@ def test_translate_ids_copies(self):
},
}))

def test_convert_object_is_from_user_adds_bridged_disclaimer(self):
def test_convert_object_is_from_user_adds_source_links(self):
alice = Fake(id='fake:alice')
self.assertEqual({
'objectType': 'application',
'id': 'other:u:fake:alice',
'url': 'http://unused',
'summary': 'something about me<br><br>[<a href="https://fed.brid.gy/fa/fake:handle:alice">bridged</a> from <a href="web:fake:alice">fake:handle:alice</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'summary': 'something about me<br><br>[<a href="https://fed.brid.gy/fa/fake:handle:alice">bridged</a> from <a href="web:fake:alice">fake:handle:alice</a> on fake-phrase by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
}, OtherFake.convert(Object(
id='fake:profile:alice', source_protocol='fake', our_as1={
'objectType': 'application',
Expand All @@ -557,20 +557,20 @@ def test_convert_object_is_from_user_adds_bridged_disclaimer(self):
'summary': 'something about me',
}), from_user=alice))

def test_convert_object_isnt_from_user_adds_bridged_disclaimer(self):
def test_convert_object_isnt_from_user_adds_source_links(self):
bob = Fake(id='fake:bob')
self.assertEqual({
'objectType': 'application',
'id': 'other:u:fake:alice',
'url': 'http://al/ice',
'summary': '[bridged from <a href="http://al/ice">al/ice</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
'summary': '[bridged from <a href="http://al/ice">al/ice</a> on fake-phrase by <a href="https://fed.brid.gy/">Bridgy Fed</a>]',
}, OtherFake.convert(Object(id='fake:alice', source_protocol='fake', our_as1={
'objectType': 'application',
'id': 'fake:alice',
'url': 'http://al/ice',
}), from_user=bob))

def test_convert_actor_without_from_user_doesnt_add_disclaimer(self):
def test_convert_actor_without_from_user_doesnt_add_source_links(self):
self.assertEqual({
'objectType': 'application',
'id': 'other:u:fake:alice',
Expand All @@ -581,7 +581,7 @@ def test_convert_actor_without_from_user_doesnt_add_disclaimer(self):
'url': 'http://al/ice',
})))

def test_convert_doesnt_duplicate_bridged_disclaimer(self):
def test_convert_doesnt_duplicate_source_links(self):
alice = Fake(id='fake:alice')
summary = 'something about me<br><br>[bridged from <a href="http://al/ice">someone else</a> by <a href="https://fed.brid.gy/">Bridgy Fed</a>]'
self.assertEqual({
Expand Down

0 comments on commit 9e18b7f

Please sign in to comment.