Skip to content

Commit

Permalink
as1.is_public: add new unlisted kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Feb 23, 2024
1 parent 6c10581 commit fce9d6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ Changelog
* `as1`:
* `get_owner` bug fix for `post`, `update`, `delete` activities.
* `activity_changed`: add new `inReplyTo` kwarg.
* `is_public`: add new `unlisted` kwarg.
* `as2`:
* `to_as1`: bug fix, preserve `objectType: featured` for banner/header images even when `mediaType` is also set.
* `from_as1`:
Expand Down
8 changes: 6 additions & 2 deletions granary/as1.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def merge_by_id(obj, field, new):
obj[field] = sorted(merged.values(), key=itemgetter('id'))


def is_public(obj):
def is_public(obj, unlisted=True):
"""Returns True if the object is public, False if private, None if unknown.
...according to the Audience Targeting extension:
Expand All @@ -213,11 +213,15 @@ def is_public(obj):
that and prunes the to field from stored activities in Response objects (in
``bridgy/util.prune_activity``). If the default here ever changes, be sure to
update Bridgy's code.
Args:
unlisted (bool): whether `@unlisted` counts as public or not
"""
to = obj.get('to') or get_object(obj).get('to') or []
aliases = util.trim_nulls([t.get('alias') for t in to])
object_types = util.trim_nulls([t.get('objectType') for t in to])
return (True if '@public' in aliases or '@unlisted' in aliases
return (True if ('@public' in aliases
or ('@unlisted' in aliases and unlisted))
else None if 'unknown' in object_types
else False if aliases
else True)
Expand Down
5 changes: 5 additions & 0 deletions granary/tests/test_as1.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def test_is_public(self):
self.assertTrue(as1.is_public(obj), repr(obj))
self.assertTrue(as1.is_public({'object': obj}), repr(obj))

self.assertFalse(as1.is_public({
'to': [{'objectType': 'group', 'alias': '@unlisted'}],
}, unlisted=False))


for obj in ({'to': [{'objectType': 'group', 'alias': '@private'}]},
{'to': [{'objectType': 'group', 'alias': 'xyz'}]},
{'to': [{'alias': 'xyz'}]},
Expand Down

0 comments on commit fce9d6f

Please sign in to comment.