forked from mirrors/bookwyrm
Support users with no shared inbox
This commit is contained in:
parent
9360f4512c
commit
ef2209e77b
6 changed files with 12 additions and 8 deletions
|
@ -27,13 +27,15 @@ def get_or_create_remote_user(actor):
|
|||
data = response.json()
|
||||
|
||||
username = '%s@%s' % (actor.split('/')[-1], actor.split('/')[2])
|
||||
shared_inbox = data.get('endpoints').get('sharedInbox') if \
|
||||
data.get('endpoints') else None
|
||||
user = models.User.objects.create_user(
|
||||
username, '', '',
|
||||
name=data.get('name'),
|
||||
summary=data.get('summary'),
|
||||
inbox=data['inbox'],
|
||||
outbox=data['outbox'],
|
||||
shared_inbox=data.get('endpoints').get('sharedInbox'),
|
||||
shared_inbox=shared_inbox,
|
||||
public_key=data.get('publicKey').get('publicKeyPem'),
|
||||
actor=actor,
|
||||
local=False
|
||||
|
@ -50,6 +52,7 @@ def get_recipients(user, post_privacy, direct_recipients=None):
|
|||
# post to public shared inboxes
|
||||
shared_inboxes = set(u.shared_inbox for u in followers)
|
||||
recipients += list(shared_inboxes)
|
||||
# TODO: not every user has a shared inbox
|
||||
# TODO: direct to anyone who's mentioned
|
||||
if post_privacy == 'followers':
|
||||
# don't send it to the shared inboxes
|
||||
|
@ -103,6 +106,7 @@ def sign_and_send(sender, action, destination):
|
|||
'Date': now,
|
||||
'Signature': signature,
|
||||
'Host': 'https://%s' % DOMAIN,
|
||||
'Content-Type': 'application/activity+json; charset=utf-8',
|
||||
},
|
||||
)
|
||||
if not response.ok:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.2 on 2020-01-30 02:26
|
||||
# Generated by Django 3.0.2 on 2020-02-01 00:22
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
|
@ -37,7 +37,7 @@ class Migration(migrations.Migration):
|
|||
('api_key', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('actor', models.CharField(max_length=255, unique=True)),
|
||||
('inbox', models.CharField(max_length=255, unique=True)),
|
||||
('shared_inbox', models.CharField(max_length=255)),
|
||||
('shared_inbox', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('outbox', models.CharField(max_length=255, unique=True)),
|
||||
('summary', models.TextField(blank=True, null=True)),
|
||||
('local', models.BooleanField(default=True)),
|
||||
|
|
|
@ -18,7 +18,7 @@ class User(AbstractUser):
|
|||
api_key = models.CharField(max_length=255, blank=True, null=True)
|
||||
actor = models.CharField(max_length=255, unique=True)
|
||||
inbox = models.CharField(max_length=255, unique=True)
|
||||
shared_inbox = models.CharField(max_length=255)
|
||||
shared_inbox = models.CharField(max_length=255, blank=True, null=True)
|
||||
federated_server = models.ForeignKey(
|
||||
'FederatedServer',
|
||||
on_delete=models.PROTECT,
|
||||
|
|
|
@ -15,10 +15,9 @@ def book_search(query):
|
|||
data = response.json()
|
||||
results = []
|
||||
for doc in data['docs'][:5]:
|
||||
key = doc['key'].split('/')[-1]
|
||||
results.append({
|
||||
'title': doc['title'],
|
||||
'olkey': key,
|
||||
'olkey': doc['key'],
|
||||
'year': doc['first_publish_year'],
|
||||
'author': doc['author_name'][0],
|
||||
})
|
||||
|
|
|
@ -8,6 +8,7 @@ from uuid import uuid4
|
|||
from fedireads import models
|
||||
from fedireads.api import get_or_create_remote_user, get_recipients, \
|
||||
broadcast
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
@ -55,7 +56,7 @@ def handle_outgoing_follow(user, to_follow):
|
|||
uuid = uuid4()
|
||||
activity = {
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
'id': str(uuid),
|
||||
'id': 'https://%s/%s' % (DOMAIN, str(uuid)),
|
||||
'summary': '',
|
||||
'type': 'Follow',
|
||||
'actor': user.actor,
|
||||
|
|
|
@ -15,7 +15,7 @@ SECRET_KEY = '7(2w1sedok=aznpq)ta1mc4i%4h=xx@hxwx*o57ctsuml0x%fr'
|
|||
DEBUG = True
|
||||
|
||||
# TODO: this hsould be populated at runtime at least for debug mode
|
||||
DOMAIN = 'bd352ee8.ngrok.io'
|
||||
DOMAIN = 'a4522b16.ngrok.io'
|
||||
ALLOWED_HOSTS = ['*']
|
||||
OL_URL = 'https://openlibrary.org'
|
||||
|
||||
|
|
Loading…
Reference in a new issue