Skip to content

Commit

Permalink
use tag to store neodb item in AP message
Browse files Browse the repository at this point in the history
  • Loading branch information
Her Email authored and alphatownsman committed Nov 18, 2023
1 parent 278e6f0 commit 67b1e51
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion catalog/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def ap_object_type(self):
def ap_object_ref(self):
o = {
"type": self.get_ap_object_type(),
"url": self.absolute_url,
"href": self.absolute_url,
"name": self.title,
}
if self.has_cover():
Expand Down
2 changes: 1 addition & 1 deletion journal/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def ap_object(self):
"updated": self.edited_time.isoformat(),
"attributedTo": self.owner.actor_uri,
"relatedWith": self.item.absolute_url,
"url": self.absolute_url,
"href": self.absolute_url,
}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion journal/models/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def ap_object(self):
"updated": self.edited_time.isoformat(),
"attributedTo": self.owner.actor_uri,
"relatedWith": self.item.absolute_url,
"url": self.absolute_url,
"href": self.absolute_url,
}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion journal/models/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ap_object(self):
"updated": self.edited_time.isoformat(),
"attributedTo": self.owner.actor_uri,
"relatedWith": self.item.absolute_url,
"url": self.absolute_url,
"href": self.absolute_url,
}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion neodb-takahe
24 changes: 16 additions & 8 deletions takahe/ap_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@
}


def _parse_links(objects):
logger.debug(f"Parsing links from {objects}")
items = []
def _parse_item_links(objects):
logger.debug(f"Parsing item links from {objects}")
items = [
obj["href"]
for obj in objects
if obj["type"] in _supported_ap_catalog_item_types
]
return items


def _parse_piece_objects(objects):
logger.debug(f"Parsing pieces from {objects}")
pieces = []
for obj in objects:
if obj["type"] in _supported_ap_catalog_item_types:
items.append(obj["url"])
elif obj["type"] in _supported_ap_journal_types.keys():
if obj["type"] in _supported_ap_journal_types.keys():
pieces.append(obj)
else:
logger.warning(f'Unknown link type {obj["type"]}')
return items, pieces
return pieces


def _get_or_create_item_by_ap_url(url):
Expand Down Expand Up @@ -70,7 +77,8 @@ def _update_or_create_post(pk, obj):
if not post.type_data:
logger.warning(f"Post {post} has no type_data")
return
items, pieces = _parse_links(post.type_data["object"]["relatedWith"])
items = _parse_item_links(post.type_data["object"]["tag"])
pieces = _parse_piece_objects(post.type_data["object"]["relatedWith"])
logger.info(f"Post {post} has items {items} and pieces {pieces}")
if len(items) == 0:
logger.warning(f"Post {post} has no remote items")
Expand Down
3 changes: 2 additions & 1 deletion takahe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ def post_mark(mark, share_as_new_post: bool) -> Post | None:
content = f"{stars}\n{mark.comment_text or ''}{tags}"
data = {
"object": {
"relatedWith": [mark.item.ap_object_ref, mark.shelfmember.ap_object]
"tag": [mark.item.ap_object_ref],
"relatedWith": [mark.shelfmember.ap_object],
}
}
if mark.comment:
Expand Down

0 comments on commit 67b1e51

Please sign in to comment.