Skip to content

Commit

Permalink
mastodon: convert cards to article tags
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Oct 24, 2019
1 parent 05a30d4 commit 6d3bade
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions granary/mastodon.py
Expand Up @@ -363,6 +363,16 @@ def status_to_object(self, status):
'displayName': t.get('name'),
} for t in status.get('tags', [])]

card = status.get('card')
if card:
obj['tags'].append({
'objectType': 'article',
'url': card.get('url'),
'displayName': card.get('title'),
'content': card.get('description'),
'image': {'url': card.get('image')},
})

# content: insert images for custom emoji
# https://docs.joinmastodon.org/api/entities/#emoji
content = base_status.get('content') or ''
Expand Down
12 changes: 12 additions & 0 deletions granary/tests/test_mastodon.py
Expand Up @@ -101,6 +101,12 @@ def tag_uri(name):
'name': 'my app',
'website': 'http://app',
},
'card': {
'url': 'https://an/article',
'title': 'my title',
'description': 'my description',
'image': 'https://an/image',
},
}
OBJECT = { # ActivityStreams
'objectType': 'note',
Expand All @@ -119,6 +125,12 @@ def tag_uri(name):
'objectType': 'hashtag',
'url': 'http://foo.com/tags/indieweb',
'displayName': 'indieweb',
}, {
'objectType': 'article',
'url': 'https://an/article',
'displayName': 'my title',
'content': 'my description',
'image': {'url': 'https://an/image'},
}],
}
ACTIVITY = { # ActivityStreams
Expand Down

0 comments on commit 6d3bade

Please sign in to comment.