Fixes federation bugs
This commit is contained in:
parent
6e97592518
commit
a17f54e457
|
@ -204,7 +204,7 @@ def handle_follow_reject(activity):
|
|||
def handle_create(activity):
|
||||
''' someone did something, good on them '''
|
||||
if activity['object'].get('type') not in \
|
||||
['Note', 'Comment', 'Quotation', 'Review']:
|
||||
['Note', 'Comment', 'Quotation', 'Review', 'GeneratedNote']:
|
||||
# if it's an article or unknown type, ignore it
|
||||
return
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 3.0.7 on 2020-10-30 21:57
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bookwyrm', '0060_auto_20201030_2010'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='GeneratedStatus',
|
||||
new_name='GeneratedNote',
|
||||
),
|
||||
]
|
|
@ -6,7 +6,7 @@ from .book import Book, Work, Edition, Author
|
|||
from .connector import Connector
|
||||
from .relationship import UserFollows, UserFollowRequest, UserBlocks
|
||||
from .shelf import Shelf, ShelfBook
|
||||
from .status import Status, GeneratedStatus, Review, Comment, Quotation
|
||||
from .status import Status, GeneratedNote, Review, Comment, Quotation
|
||||
from .status import Favorite, Boost, Notification, ReadThrough
|
||||
from .tag import Tag
|
||||
from .user import User
|
||||
|
@ -16,5 +16,5 @@ from .import_job import ImportJob, ImportItem
|
|||
from .site import SiteSettings, SiteInvite, PasswordReset
|
||||
|
||||
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
|
||||
activity_models = {c[0]: c[1].activity_serializer for c in cls_members \
|
||||
activity_models = {c[0]: c[1] for c in cls_members \
|
||||
if hasattr(c[1], 'activity_serializer')}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
''' base model with default fields '''
|
||||
from datetime import datetime
|
||||
from base64 import b64encode
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable
|
||||
|
@ -69,6 +70,8 @@ class ActivitypubMixin:
|
|||
value = getattr(self, mapping.model_key)
|
||||
if hasattr(value, 'remote_id'):
|
||||
value = value.remote_id
|
||||
if isinstance(value, datetime):
|
||||
value = value.isoformat()
|
||||
fields[mapping.activity_key] = mapping.activity_formatter(value)
|
||||
|
||||
if pure:
|
||||
|
|
|
@ -3,7 +3,6 @@ import re
|
|||
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.http import http_date
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
||||
from bookwyrm import activitypub
|
||||
|
@ -63,16 +62,8 @@ class Book(ActivitypubMixin, BookWyrmModel):
|
|||
ActivityMapping('id', 'remote_id'),
|
||||
|
||||
ActivityMapping('authors', 'ap_authors'),
|
||||
ActivityMapping(
|
||||
'first_published_date',
|
||||
'first_published_date',
|
||||
activity_formatter=lambda d: http_date(d.timestamp()) if d else None
|
||||
),
|
||||
ActivityMapping(
|
||||
'published_date',
|
||||
'published_date',
|
||||
activity_formatter=lambda d: http_date(d.timestamp()) if d else None
|
||||
),
|
||||
ActivityMapping('first_published_date', 'first_published_date'),
|
||||
ActivityMapping('published_date', 'published_date'),
|
||||
|
||||
ActivityMapping('title', 'title'),
|
||||
ActivityMapping('sort_title', 'sort_title'),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
''' models for storing different kinds of Activities '''
|
||||
from django.utils import timezone
|
||||
from django.utils.http import http_date
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
@ -62,11 +61,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
ActivityMapping('id', 'remote_id'),
|
||||
ActivityMapping('url', 'remote_id'),
|
||||
ActivityMapping('inReplyTo', 'reply_parent'),
|
||||
ActivityMapping(
|
||||
'published',
|
||||
'published_date',
|
||||
activity_formatter=lambda d: http_date(d.timestamp())
|
||||
),
|
||||
ActivityMapping('published', 'published_date'),
|
||||
ActivityMapping('attributedTo', 'user'),
|
||||
ActivityMapping('to', 'ap_to'),
|
||||
ActivityMapping('cc', 'ap_cc'),
|
||||
|
@ -116,13 +111,13 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
return activitypub.Tombstone(
|
||||
id=self.remote_id,
|
||||
url=self.remote_id,
|
||||
deleted=http_date(self.deleted_date.timestamp()),
|
||||
published=http_date(self.deleted_date.timestamp()),
|
||||
deleted=self.deleted_date.isoformat(),
|
||||
published=self.deleted_date.isoformat()
|
||||
).serialize()
|
||||
return ActivitypubMixin.to_activity(self, **kwargs)
|
||||
|
||||
|
||||
class GeneratedStatus(Status):
|
||||
class GeneratedNote(Status):
|
||||
''' these are app-generated messages about user activity '''
|
||||
@property
|
||||
def ap_pure_content(self):
|
||||
|
|
|
@ -21,7 +21,7 @@ def create_generated_note(user, content, mention_books=None):
|
|||
parser.feed(content)
|
||||
content = parser.get_output()
|
||||
|
||||
status = models.GeneratedStatus.objects.create(
|
||||
status = models.GeneratedNote.objects.create(
|
||||
user=user,
|
||||
content=content,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue