Skip to content

Commit

Permalink
mastodon: use /web/statuses/... when we have status id but not username
Browse files Browse the repository at this point in the history
eg inReplyTo URLs
  • Loading branch information
snarfed committed Oct 17, 2019
1 parent 2d4f85e commit c3c6655
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions granary/mastodon.py
Expand Up @@ -5,7 +5,7 @@
independent of AP. API docs: https://docs.joinmastodon.org/api/
TODO:
* username in inReplyTo URLs
* get_activities(): start_index, count, min_id
* de-dupe media attachments
* caching
* block lists
Expand Down Expand Up @@ -327,9 +327,7 @@ def status_to_object(self, status):
if reply_to_id:
obj['inReplyTo'] = [{
'id': self.tag_uri(reply_to_id),
# XXX TODO need to generate URL for in-reply-to status, but we don't
# have its author's username, just their account id
'url': urllib.parse.urljoin(self.instance, '/TODO/status/' + reply_to_id),
'url': urllib.parse.urljoin(self.instance, '/web/statuses/' + reply_to_id),
}]

# to (ie visibility)
Expand Down
9 changes: 7 additions & 2 deletions granary/tests/test_mastodon.py
Expand Up @@ -139,7 +139,7 @@ def tag_uri(name):
})
REPLY_OBJECT = copy.deepcopy(OBJECT) # ActivityStreams
REPLY_OBJECT['inReplyTo'] = [{
'url': 'http://foo.com/TODO/status/456',
'url': 'http://foo.com/web/statuses/456',
'id': tag_uri('456'),
}]
REPLY_ACTIVITY = copy.deepcopy(ACTIVITY) # ActivityStreams
Expand Down Expand Up @@ -341,12 +341,17 @@ def test_get_activities_activity_id(self):
self.mox.ReplayAll()
self.assert_equals([ACTIVITY], self.mastodon.get_activities(activity_id=123))

def test_get_activities_user_id(self):
def test_get_activities_self_user_id(self):
self.expect_get(API_ACCOUNT_STATUSES % '456', [STATUS])
self.mox.ReplayAll()
self.assert_equals([ACTIVITY], self.mastodon.get_activities(
group_id=source.SELF, user_id=456))

def test_get_activities_self_default_user(self):
self.expect_get(API_ACCOUNT_STATUSES % ACCOUNT['id'], [STATUS])
self.mox.ReplayAll()
self.assert_equals([ACTIVITY], self.mastodon.get_activities(group_id=source.SELF))

def test_get_activities_search(self):
self.expect_get(API_SEARCH, params={'q': 'indieweb'},
response={'statuses': [STATUS, MEDIA_STATUS]})
Expand Down

0 comments on commit c3c6655

Please sign in to comment.