Unify concept of absolute_id and remote_id
This commit is contained in:
@ -24,18 +24,18 @@ def get_actor(user):
|
||||
},
|
||||
],
|
||||
|
||||
'id': user.actor,
|
||||
'id': user.remote_id,
|
||||
'type': 'Person',
|
||||
'preferredUsername': user.localname,
|
||||
'name': user.name,
|
||||
'inbox': user.inbox,
|
||||
'outbox': '%s/outbox' % user.actor,
|
||||
'followers': '%s/followers' % user.actor,
|
||||
'following': '%s/following' % user.actor,
|
||||
'outbox': '%s/outbox' % user.remote_id,
|
||||
'followers': '%s/followers' % user.remote_id,
|
||||
'following': '%s/following' % user.remote_id,
|
||||
'summary': user.summary,
|
||||
'publicKey': {
|
||||
'id': '%s/#main-key' % user.actor,
|
||||
'owner': user.actor,
|
||||
'id': '%s/#main-key' % user.remote_id,
|
||||
'owner': user.remote_id,
|
||||
'publicKeyPem': user.public_key,
|
||||
},
|
||||
'endpoints': {
|
||||
|
@ -34,9 +34,9 @@ def get_book(book, recursive=True):
|
||||
'type': 'Document',
|
||||
'book_type': book_type,
|
||||
'name': book.title,
|
||||
'url': book.absolute_id,
|
||||
'url': book.local_id,
|
||||
|
||||
'authors': [a.absolute_id for a in book.authors.all()],
|
||||
'authors': [a.local_id for a in book.authors.all()],
|
||||
'first_published_date': book.first_published_date.isoformat() if \
|
||||
book.first_published_date else None,
|
||||
'published_date': book.published_date.isoformat() if \
|
||||
@ -79,7 +79,7 @@ def get_author(author):
|
||||
]
|
||||
activity = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'url': author.absolute_id,
|
||||
'url': author.local_id,
|
||||
'type': 'Person',
|
||||
}
|
||||
for field in fields:
|
||||
@ -90,7 +90,7 @@ def get_author(author):
|
||||
|
||||
def get_shelf(shelf, page=None):
|
||||
''' serialize shelf object '''
|
||||
id_slug = shelf.absolute_id
|
||||
id_slug = shelf.remote_id
|
||||
if page:
|
||||
return get_shelf_page(shelf, page)
|
||||
count = shelf.books.count()
|
||||
@ -110,7 +110,7 @@ def get_shelf_page(shelf, page):
|
||||
start = (page - 1) * page_length
|
||||
end = start + page_length
|
||||
shelf_page = shelf.books.all()[start:end]
|
||||
id_slug = shelf.absolute_id
|
||||
id_slug = shelf.local_id
|
||||
data = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s?page=%d' % (id_slug, page),
|
||||
|
@ -14,16 +14,16 @@ def get_create(user, status_json):
|
||||
|
||||
'id': '%s/activity' % status_json['id'],
|
||||
'type': 'Create',
|
||||
'actor': user.actor,
|
||||
'actor': user.remote_id,
|
||||
'published': status_json['published'],
|
||||
|
||||
'to': ['%s/followers' % user.actor],
|
||||
'to': ['%s/followers' % user.remote_id],
|
||||
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
|
||||
'object': status_json,
|
||||
'signature': {
|
||||
'type': 'RsaSignature2017',
|
||||
'creator': '%s#main-key' % user.absolute_id,
|
||||
'creator': '%s#main-key' % user.remote_id,
|
||||
'created': status_json['published'],
|
||||
'signatureValue': b64encode(signed_message).decode('utf8'),
|
||||
}
|
||||
@ -37,7 +37,7 @@ def get_update(user, activity_json):
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': 'https://friend.camp/users/tripofmice#updates/1585446332',
|
||||
'type': 'Update',
|
||||
'actor': user.actor,
|
||||
'actor': user.remote_id,
|
||||
'to': [
|
||||
'https://www.w3.org/ns/activitystreams#Public'
|
||||
],
|
||||
|
@ -12,22 +12,22 @@ def get_follow_request(user, to_follow):
|
||||
'id': 'https://%s/%s' % (DOMAIN, str(uuid)),
|
||||
'summary': '',
|
||||
'type': 'Follow',
|
||||
'actor': user.actor,
|
||||
'object': to_follow.actor,
|
||||
'actor': user.remote_id,
|
||||
'object': to_follow.remote_id,
|
||||
}
|
||||
|
||||
def get_unfollow(relationship):
|
||||
''' undo that precious bond of friendship '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s/undo' % relationship.absolute_id,
|
||||
'id': '%s/undo' % relationship.remote_id,
|
||||
'type': 'Undo',
|
||||
'actor': relationship.user_subject.actor,
|
||||
'actor': relationship.user_subject.remote_id,
|
||||
'object': {
|
||||
'id': relationship.relationship_id,
|
||||
'type': 'Follow',
|
||||
'actor': relationship.user_subject.actor,
|
||||
'object': relationship.user_object.actor,
|
||||
'actor': relationship.user_subject.remote_id,
|
||||
'object': relationship.user_object.remote_id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,14 +36,14 @@ def get_accept(user, relationship):
|
||||
''' accept a follow request '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s#accepts/follows/' % user.absolute_id,
|
||||
'id': '%s#accepts/follows/' % user.remote_id,
|
||||
'type': 'Accept',
|
||||
'actor': user.actor,
|
||||
'actor': user.remote_id,
|
||||
'object': {
|
||||
'id': relationship.relationship_id,
|
||||
'type': 'Follow',
|
||||
'actor': relationship.user_subject.actor,
|
||||
'object': relationship.user_object.actor,
|
||||
'actor': relationship.user_subject.remote_id,
|
||||
'object': relationship.user_object.remote_id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,27 +52,27 @@ def get_reject(user, relationship):
|
||||
''' reject a follow request '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s#rejects/follows/' % user.absolute_id,
|
||||
'id': '%s#rejects/follows/' % user.remote_id,
|
||||
'type': 'Reject',
|
||||
'actor': user.actor,
|
||||
'actor': user.remote_id,
|
||||
'object': {
|
||||
'id': relationship.relationship_id,
|
||||
'type': 'Follow',
|
||||
'actor': relationship.user_subject.actor,
|
||||
'object': relationship.user_object.actor,
|
||||
'actor': relationship.user_subject.remote_id,
|
||||
'object': relationship.user_object.remote_id,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_followers(user, page, follow_queryset):
|
||||
''' list of people who follow a user '''
|
||||
id_slug = '%s/followers' % user.actor
|
||||
id_slug = '%s/followers' % user.remote_id
|
||||
return get_follow_info(id_slug, page, follow_queryset)
|
||||
|
||||
|
||||
def get_following(user, page, follow_queryset):
|
||||
''' list of people who follow a user '''
|
||||
id_slug = '%s/following' % user.actor
|
||||
id_slug = '%s/following' % user.remote_id
|
||||
return get_follow_info(id_slug, page, follow_queryset)
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ def get_follow_page(user_list, id_slug, page):
|
||||
'type': 'OrderedCollectionPage',
|
||||
'totalItems': user_list.count(),
|
||||
'partOf': id_slug,
|
||||
'orderedItems': [u.actor for u in follower_page],
|
||||
'orderedItems': [u.remote_id for u in follower_page],
|
||||
}
|
||||
if end <= user_list.count():
|
||||
# there are still more pages
|
||||
|
@ -18,16 +18,15 @@ def get_add_remove(user, book, shelf, action='Add'):
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': str(uuid),
|
||||
'type': action,
|
||||
'actor': user.actor,
|
||||
'actor': user.remote_id,
|
||||
'object': {
|
||||
# TODO: document??
|
||||
'type': 'Document',
|
||||
'name': book.title,
|
||||
'url': book.absolute_id,
|
||||
'url': book.local_id,
|
||||
},
|
||||
'target': {
|
||||
'type': 'Collection',
|
||||
'name': shelf.name,
|
||||
'id': shelf.absolute_id,
|
||||
'id': shelf.remote_id,
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ from fedireads.settings import DOMAIN
|
||||
def get_rating(review):
|
||||
''' activitypub serialize rating activity '''
|
||||
status = get_status(review)
|
||||
status['inReplyToBook'] = review.book.absolute_id
|
||||
status['inReplyToBook'] = review.book.local_id
|
||||
status['fedireadsType'] = review.status_type
|
||||
status['rating'] = review.rating
|
||||
status['content'] = '%d star rating of "%s"' % (
|
||||
@ -18,7 +18,7 @@ def get_rating(review):
|
||||
def get_quotation(quotation):
|
||||
''' fedireads json for quotations '''
|
||||
status = get_status(quotation)
|
||||
status['inReplyToBook'] = quotation.book.absolute_id
|
||||
status['inReplyToBook'] = quotation.book.local_id
|
||||
status['fedireadsType'] = quotation.status_type
|
||||
status['quote'] = quotation.quote
|
||||
return status
|
||||
@ -29,7 +29,7 @@ def get_quotation_article(quotation):
|
||||
status = get_status(quotation)
|
||||
content = '"%s"<br>-- <a href="%s">"%s"</a>)<br><br>%s' % (
|
||||
quotation.quote,
|
||||
quotation.book.absolute_id,
|
||||
quotation.book.local_id,
|
||||
quotation.book.title,
|
||||
quotation.content,
|
||||
)
|
||||
@ -40,7 +40,7 @@ def get_quotation_article(quotation):
|
||||
def get_review(review):
|
||||
''' fedireads json for book reviews '''
|
||||
status = get_status(review)
|
||||
status['inReplyToBook'] = review.book.absolute_id
|
||||
status['inReplyToBook'] = review.book.local_id
|
||||
status['fedireadsType'] = review.status_type
|
||||
status['name'] = review.name
|
||||
status['rating'] = review.rating
|
||||
@ -50,7 +50,7 @@ def get_review(review):
|
||||
def get_comment(comment):
|
||||
''' fedireads json for book reviews '''
|
||||
status = get_status(comment)
|
||||
status['inReplyToBook'] = comment.book.absolute_id
|
||||
status['inReplyToBook'] = comment.book.local_id
|
||||
status['fedireadsType'] = comment.status_type
|
||||
return status
|
||||
|
||||
@ -87,15 +87,15 @@ def get_comment_article(comment):
|
||||
''' a book comment formatted for a non-fedireads isntance (mastodon) '''
|
||||
status = get_status(comment)
|
||||
status['content'] += '<br><br>(comment on <a href="%s">"%s"</a>)' % \
|
||||
(comment.book.absolute_id, comment.book.title)
|
||||
(comment.book.local_id, comment.book.title)
|
||||
return status
|
||||
|
||||
|
||||
def get_status(status):
|
||||
''' create activitypub json for a status '''
|
||||
user = status.user
|
||||
uri = status.absolute_id
|
||||
reply_parent_id = status.reply_parent.absolute_id \
|
||||
uri = status.remote_id
|
||||
reply_parent_id = status.reply_parent.remote_id \
|
||||
if status.reply_parent else None
|
||||
|
||||
image_attachments = []
|
||||
@ -117,10 +117,10 @@ def get_status(status):
|
||||
'url': uri,
|
||||
'inReplyTo': reply_parent_id,
|
||||
'published': status.published_date.isoformat(),
|
||||
'attributedTo': user.actor,
|
||||
'attributedTo': user.remote_id,
|
||||
# TODO: assuming all posts are public -- should check privacy db field
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'cc': ['%s/followers' % user.absolute_id],
|
||||
'cc': ['%s/followers' % user.remote_id],
|
||||
'sensitive': status.sensitive,
|
||||
'content': status.content,
|
||||
'type': status.activity_type,
|
||||
@ -142,7 +142,7 @@ def get_status(status):
|
||||
|
||||
def get_replies(status, replies):
|
||||
''' collection of replies '''
|
||||
id_slug = status.absolute_id + '/replies'
|
||||
id_slug = status.remote_id + '/replies'
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': id_slug,
|
||||
@ -159,7 +159,7 @@ def get_replies(status, replies):
|
||||
|
||||
def get_replies_page(status, replies):
|
||||
''' actual reply list content '''
|
||||
id_slug = status.absolute_id + '/replies?page=true&only_other_accounts=true'
|
||||
id_slug = status.remote_id + '/replies?page=true&only_other_accounts=true'
|
||||
items = []
|
||||
for reply in replies:
|
||||
if reply.user.local:
|
||||
@ -171,7 +171,7 @@ def get_replies_page(status, replies):
|
||||
'id': id_slug,
|
||||
'type': 'CollectionPage',
|
||||
'next': '%s&min_id=%d' % (id_slug, replies[len(replies) - 1].id),
|
||||
'partOf': status.absolute_id + '/replies',
|
||||
'partOf': status.remote_id + '/replies',
|
||||
'items': [items]
|
||||
}
|
||||
|
||||
@ -180,10 +180,10 @@ def get_favorite(favorite):
|
||||
''' like a post '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': favorite.absolute_id,
|
||||
'id': favorite.remote_id,
|
||||
'type': 'Like',
|
||||
'actor': favorite.user.actor,
|
||||
'object': favorite.status.absolute_id,
|
||||
'actor': favorite.user.remote_id,
|
||||
'object': favorite.status.remote_id,
|
||||
}
|
||||
|
||||
|
||||
@ -191,14 +191,14 @@ def get_unfavorite(favorite):
|
||||
''' like a post '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': '%s/undo' % favorite.absolute_id,
|
||||
'id': '%s/undo' % favorite.remote_id,
|
||||
'type': 'Undo',
|
||||
'actor': favorite.user.actor,
|
||||
'actor': favorite.user.remote_id,
|
||||
'object': {
|
||||
'id': favorite.absolute_id,
|
||||
'id': favorite.remote_id,
|
||||
'type': 'Like',
|
||||
'actor': favorite.user.actor,
|
||||
'object': favorite.status.absolute_id,
|
||||
'actor': favorite.user.remote_id,
|
||||
'object': favorite.status.remote_id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,10 +207,10 @@ def get_boost(boost):
|
||||
''' boost/announce a post '''
|
||||
return {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': boost.absolute_id,
|
||||
'id': boost.remote_id,
|
||||
'type': 'Announce',
|
||||
'actor': boost.user.actor,
|
||||
'object': boost.boosted_status.absolute_id,
|
||||
'actor': boost.user.remote_id,
|
||||
'object': boost.boosted_status.remote_id,
|
||||
}
|
||||
|
||||
|
||||
@ -221,15 +221,15 @@ def get_add_tag(tag):
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': str(uuid),
|
||||
'type': 'Add',
|
||||
'actor': tag.user.actor,
|
||||
'actor': tag.user.remote_id,
|
||||
'object': {
|
||||
'type': 'Tag',
|
||||
'id': tag.absolute_id,
|
||||
'id': tag.remote_id,
|
||||
'name': tag.name,
|
||||
},
|
||||
'target': {
|
||||
'type': 'Book',
|
||||
'id': tag.book.absolute_id,
|
||||
'id': tag.book.local_id,
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,14 +241,14 @@ def get_remove_tag(tag):
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': str(uuid),
|
||||
'type': 'Remove',
|
||||
'actor': tag.user.actor,
|
||||
'actor': tag.user.remote_id,
|
||||
'object': {
|
||||
'type': 'Tag',
|
||||
'id': tag.absolute_id,
|
||||
'id': tag.remote_id,
|
||||
'name': tag.name,
|
||||
},
|
||||
'target': {
|
||||
'type': 'Book',
|
||||
'id': tag.book.absolute_id,
|
||||
'id': tag.book.local_id,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user