Skip to content

Commit

Permalink
ATProto: rename original* custom fields to bridgyOriginal*
Browse files Browse the repository at this point in the history
for #1092
  • Loading branch information
snarfed committed Jun 12, 2024
1 parent 417a88a commit 387d316
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,19 @@ def _convert(cls, obj, fetch_blobs=False, from_user=None):
client = DatastoreClient(f'https://{os.environ["APPVIEW_HOST"]}')
try:
ret = bluesky.from_as1(cls.translate_ids(obj.as1), blobs=blobs,
client=client)
client=client, original_fields_prefix='bridgy')
except (ValueError, RequestException):
logger.error(f"Couldn't convert to ATProto", exc_info=True)
return {}

if from_proto != ATProto:
if ret['$type'] == 'app.bsky.actor.profile':
# populated by Protocol.convert
if orig_summary := obj.as1.get('originalSummary'):
ret['originalDescription'] = orig_summary
if orig_summary := obj.as1.get('bridgyOriginalSummary'):
ret['bridgyOriginalDescription'] = orig_summary
else:
# don't use granary's since it will include source links
ret.pop('originalDescription', None)
ret.pop('bridgyOriginalDescription', None)

# bridged actors get a self label
label_val = 'bridged-from-bridgy-fed'
Expand All @@ -653,7 +653,7 @@ def _convert(cls, obj, fetch_blobs=False, from_user=None):

if (ret['$type'] in ('app.bsky.actor.profile', 'app.bsky.feed.post')
and orig_url):
ret['originalUrl'] = orig_url
ret['bridgyOriginalUrl'] = orig_url

return ret

Expand Down Expand Up @@ -681,7 +681,7 @@ def add_source_links(cls, actor, obj, from_user):
return

# consumed by _convert above
actor.setdefault('originalSummary', orig_summary)
actor.setdefault('bridgyOriginalSummary', orig_summary)

id = obj.key.id() if obj.key else obj.our_as1.get('id')

Expand Down
44 changes: 22 additions & 22 deletions tests/test_atproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
NOTE_BSKY = {
'$type': 'app.bsky.feed.post',
'text': 'My original post',
'originalText': 'My original post',
'originalUrl': 'fake:post',
'bridgyOriginalText': 'My original post',
'bridgyOriginalUrl': 'fake:post',
'createdAt': '2007-07-07T03:04:05.000Z',
}

Expand Down Expand Up @@ -440,7 +440,7 @@ def test_convert_populate_cid(self):
self.assertEqual({
'$type': 'app.bsky.feed.post',
'text': 'foo',
'originalText': 'foo',
'bridgyOriginalText': 'foo',
'createdAt': '2022-01-02T03:04:05.000Z',
'reply': {
'$type': 'app.bsky.feed.post#replyRef',
Expand Down Expand Up @@ -475,7 +475,7 @@ def test_convert_populate_cid(self):
self.assertEqual({
'$type': 'app.bsky.feed.post',
'text': 'foo',
'originalText': 'foo',
'bridgyOriginalText': 'foo',
'createdAt': '2022-01-02T03:04:05.000Z',
'reply': {
'$type': 'app.bsky.feed.post#replyRef',
Expand Down Expand Up @@ -568,7 +568,7 @@ def test_convert_blobs_false(self):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed'}],
},
'originalUrl': 'did:web:alice.com',
'bridgyOriginalUrl': 'did:web:alice.com',
}, ATProto.convert(Object(our_as1={
'objectType': 'person',
'id': 'did:web:alice.com',
Expand All @@ -593,7 +593,7 @@ def test_convert_fetch_blobs_true(self, mock_get):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed'}],
},
'originalUrl': 'did:web:alice.com',
'bridgyOriginalUrl': 'did:web:alice.com',
}, ATProto.convert(Object(our_as1={
'objectType': 'person',
'id': 'did:web:alice.com',
Expand All @@ -620,7 +620,7 @@ def test_convert_fetch_blobs_true_existing_atp_remote_blob(self):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed'}],
},
'originalUrl': 'did:web:alice.com',
'bridgyOriginalUrl': 'did:web:alice.com',
}, ATProto.convert(Object(our_as1={
'objectType': 'person',
'id': 'did:web:alice.com',
Expand All @@ -638,7 +638,7 @@ def test_convert_resolve_mention_handle(self, mock_get):
'$type': 'app.bsky.feed.post',
'createdAt': '2022-01-02T03:04:05.000Z',
'text': 'hi @han.dull hows it going',
'originalText': content,
'bridgyOriginalText': content,
'facets': [{
'$type': 'app.bsky.richtext.facet',
'features': [{
Expand Down Expand Up @@ -673,7 +673,7 @@ def test_convert_resolve_mention_handle_drop_server(self, mock_get):
'$type': 'app.bsky.feed.post',
'createdAt': '2022-01-02T03:04:05.000Z',
'text': 'hi @han.dull hows it going',
'originalText': content,
'bridgyOriginalText': content,
'facets': [{
'$type': 'app.bsky.richtext.facet',
'features': [{
Expand Down Expand Up @@ -715,7 +715,7 @@ def test_convert_non_atproto_actor_adds_self_label(self):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed-fake'}],
},
'originalUrl': 'fake:alice',
'bridgyOriginalUrl': 'fake:alice',
}, ATProto.convert(Object(source_protocol='fake', our_as1={
'objectType': 'person',
'id': 'fake:alice',
Expand All @@ -733,7 +733,7 @@ def test_convert_non_atproto_actor_adds_source_links(self):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed-fake'}],
},
'originalUrl': 'fake:user',
'bridgyOriginalUrl': 'fake:user',
}, ATProto.convert(Object(source_protocol='fake', our_as1={
'objectType': 'person',
'id': 'fake:user',
Expand Down Expand Up @@ -762,8 +762,8 @@ def test_convert_non_atproto_update_actor_truncates_before_source_links(self):
Sed tortor neque, aliquet quis posuere aliquam […]
[bridged from web:fake:user on fake-phrase by https://fed.brid.gy/ ]""",
'originalDescription': summary,
'originalUrl': 'fake:user',
'bridgyOriginalDescription': summary,
'bridgyOriginalUrl': 'fake:user',
'labels': {
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed-fake'}],
Expand All @@ -788,8 +788,8 @@ def test_convert_non_atproto_actor_link_in_summary(self):
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val': 'bridged-from-bridgy-fed-fake'}],
},
'originalDescription': '<a href="http://foo">bar</a>',
'originalUrl': 'fake:user',
'bridgyOriginalDescription': '<a href="http://foo">bar</a>',
'bridgyOriginalUrl': 'fake:user',
}, ATProto.convert(Object(source_protocol='fake', our_as1={
'objectType': 'person',
'id': 'fake:user',
Expand Down Expand Up @@ -862,8 +862,8 @@ def test_create_for(self, mock_post, mock_create_task, mock_zone):
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from web:fake:us_er on fake-phrase by https://fed.brid.gy/ ]',
'originalDescription': 'hi there',
'originalUrl': 'https://alice.com/',
'bridgyOriginalDescription': 'hi there',
'bridgyOriginalUrl': 'https://alice.com/',
'avatar': {
'$type': 'blob',
'mimeType': 'application/octet-stream',
Expand Down Expand Up @@ -921,7 +921,7 @@ def test_send_new_repo(self, mock_post, mock_create_task, _):
record = repo.get_record('app.bsky.feed.post', last_tid)
self.assertEqual({
**NOTE_BSKY,
'originalUrl': 'https://bsky.app/profile/did:alice/post/tid',
'bridgyOriginalUrl': 'https://bsky.app/profile/did:alice/post/tid',
}, record)

at_uri = f'at://{did}/app.bsky.feed.post/{last_tid}'
Expand Down Expand Up @@ -980,8 +980,8 @@ def test_send_new_repo_includes_user_profile(self, mock_post, mock_create_task,
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from web:fake:user on fake-phrase by https://fed.brid.gy/ ]',
'originalDescription': 'hi there',
'originalUrl': 'https://alice.com/',
'bridgyOriginalDescription': 'hi there',
'bridgyOriginalUrl': 'https://alice.com/',
'avatar': {
'$type': 'blob',
'ref': BLOB_CID,
Expand Down Expand Up @@ -1376,8 +1376,8 @@ def test_send_translates_ids(self, mock_create_task):
'$type': 'app.bsky.feed.post',
'createdAt': '2022-01-02T03:04:05.000Z',
'text': 'foo',
'originalText': 'foo',
'originalUrl': 'fake:reply',
'bridgyOriginalText': 'foo',
'bridgyOriginalUrl': 'fake:reply',
'reply': {
'$type': 'app.bsky.feed.post#replyRef',
'root': {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def test_get_or_create_propagate_atproto(self, mock_post, mock_create_task):
'$type': 'app.bsky.actor.profile',
'displayName': 'Alice',
'description': 'hi there\n\n[bridged from web:fake:user on fake-phrase by https://fed.brid.gy/ ]',
'originalDescription': 'hi there',
'originalUrl': 'https://alice.com/',
'bridgyOriginalDescription': 'hi there',
'bridgyOriginalUrl': 'https://alice.com/',
'labels': {
'$type': 'com.atproto.label.defs#selfLabels',
'values': [{'val' : 'bridged-from-bridgy-fed-fake'}],
Expand Down

0 comments on commit 387d316

Please sign in to comment.