Skip to content

Commit

Permalink
facebook: support threaded comments (parent field) in comment_to_obje…
Browse files Browse the repository at this point in the history
…ct()

for snarfed/bridgy#435
  • Loading branch information
snarfed committed Aug 4, 2015
1 parent 29315ec commit f6f8e25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions granary/facebook.py
Expand Up @@ -932,6 +932,10 @@ def comment_to_object(self, comment, post_id=None, post_author_id=None):
'inReplyTo': [{'id': self.tag_uri(post_id)}],
})

parent_id = comment.get('parent', {}).get('id')
if parent_id:
obj.setdefault('inReplyTo', []).append({'id': self.tag_uri(parent_id)})

return self.postprocess_object(obj)

def share_to_object(self, share):
Expand Down
21 changes: 21 additions & 0 deletions granary/test/test_facebook.py
Expand Up @@ -1073,6 +1073,27 @@ def test_comment_to_object_unknown_id_format(self):
"""See https://github.com/snarfed/bridgy/issues/305"""
self.assert_equals({}, self.facebook.comment_to_object({'id': '123 456^789'}))

def test_comment_to_object_with_parent_comment(self):
"""See https://github.com/snarfed/bridgy/issues/435"""
self.assert_equals({
'objectType': 'comment',
'id': tag_uri('34_78'),
'fb_id': '34_78',
'content': "now you're giving me all sorts of ideas!",
'url': 'https://www.facebook.com/34?comment_id=78',
'inReplyTo': [
{'id': tag_uri('34')},
{'id': tag_uri('34_56')},
],
}, self.facebook.comment_to_object({
'id': '34_78',
'message': "now you're giving me all sorts of ideas!",
'parent': {
'message': 'You put coffee on tortilla chips?',
'id': '34_56'
},
}))

def test_share_to_object_empty(self):
self.assert_equals({}, self.facebook.share_to_object({}))

Expand Down

0 comments on commit f6f8e25

Please sign in to comment.