From eaa0227c1ab5c594d5d2008abca6a56253de4229 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 27 Mar 2020 09:58:25 -0700 Subject: [PATCH] Adds avatars to activitypub actor Fixes #45 --- fedireads/activitypub/actor.py | 15 +++++++++++++++ fedireads/urls.py | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/fedireads/activitypub/actor.py b/fedireads/activitypub/actor.py index cdafa9946..7dec3bbc4 100644 --- a/fedireads/activitypub/actor.py +++ b/fedireads/activitypub/actor.py @@ -1,7 +1,17 @@ ''' actor serializer ''' +from fedireads.settings import DOMAIN def get_actor(user): ''' activitypub actor from db User ''' + avatar = user.avatar + + icon_path = '/static/images/default_avi.jpg' + icon_type = 'image/jpeg' + if avatar: + icon_path = avatar.url + icon_type = 'image/%s' % icon_path.split('.')[-1] + + icon_url = 'https://%s%s' % (DOMAIN, icon_path) return { '@context': [ 'https://www.w3.org/ns/activitystreams', @@ -33,5 +43,10 @@ def get_actor(user): }, 'fedireadsUser': True, 'manuallyApprovesFollowers': user.manually_approves_followers, + "icon": { + "type": "Image", + "mediaType": icon_type, + "url": icon_url, + }, } diff --git a/fedireads/urls.py b/fedireads/urls.py index 677b86823..10761e866 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -6,7 +6,7 @@ from django.urls import path, re_path from fedireads import incoming, outgoing, views, settings, wellknown from fedireads import view_actions as actions -username_regex = r'(?P[\w@\-_\.]+)' +username_regex = r'(?P[\w\-_]+@[\w\-\_\.]+)' localname_regex = r'(?P[\w\-_]+)' user_path = r'^user/%s' % username_regex local_user_path = r'^user/%s' % localname_regex @@ -39,6 +39,7 @@ urlpatterns = [ # should return a ui view or activitypub json blob as requested # users re_path(r'%s/?$' % user_path, views.user_page), + re_path(r'%s/?$' % local_user_path, views.user_page), re_path(r'%s\.json$' % local_user_path, views.user_page), re_path(r'user-edit/?$', views.edit_profile_page), re_path(r'%s/shelves/?$' % local_user_path, views.user_shelves_page), @@ -60,6 +61,7 @@ urlpatterns = [ re_path(r'^author/(?P\w+)/?$', views.author_page), re_path(r'^tag/(?P.+)/?$', views.tag_page), re_path(r'^shelf/%s/(?P[\w-]+)/?$' % username_regex, views.shelf_page), + re_path(r'^shelf/%s/(?P[\w-]+)/?$' % localname_regex, views.shelf_page), # internal action endpoints re_path(r'^logout/?$', actions.user_logout),