Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tag to store item link in activitypub message #378

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion takahe/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FediverseHtmlParser(HTMLParser):
r"(^|[^\w\d\-_/])@([\w\d\-_]+(?:@[\w\d\-_\.]+[\w\d\-_]+)?)"
)

HASHTAG_REGEX = re.compile(r"\B#([a-zA-Z0-9(_)]+\b)(?!;)")
HASHTAG_REGEX = re.compile(r"\B#([\w()]+\b)(?!;)")

EMOJI_REGEX = re.compile(r"\B:([a-zA-Z0-9(_)-]+):\B")

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