Skip to content

Commit

Permalink
Merge branch 'main' into export-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hughrun authored Feb 6, 2024
2 parents 8773caa + d977470 commit 46a158d
Show file tree
Hide file tree
Showing 33 changed files with 454 additions and 184 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.1
0.7.2
54 changes: 0 additions & 54 deletions bookwyrm/management/commands/instance_version.py

This file was deleted.

23 changes: 23 additions & 0 deletions bookwyrm/migrations/0192_make_page_positions_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.23 on 2024-01-04 23:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0191_merge_20240102_0326"),
]

operations = [
migrations.AlterField(
model_name="quotation",
name="endposition",
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name="quotation",
name="position",
field=models.TextField(blank=True, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-01-02 19:36

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0191_merge_20240102_0326"),
]

operations = [
migrations.RenameField(
model_name="sitesettings",
old_name="version",
new_name="available_version",
),
]
13 changes: 13 additions & 0 deletions bookwyrm/migrations/0193_merge_20240203_1539.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.23 on 2024-02-03 15:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0192_make_page_positions_text"),
("bookwyrm", "0192_sitesettings_user_exports_enabled"),
]

operations = []
13 changes: 13 additions & 0 deletions bookwyrm/migrations/0194_merge_20240203_1619.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.2.23 on 2024-02-03 16:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("bookwyrm", "0192_rename_version_sitesettings_available_version"),
("bookwyrm", "0193_merge_20240203_1539"),
]

operations = []
25 changes: 13 additions & 12 deletions bookwyrm/models/activitypub_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ def get_recipients(self, software=None) -> list[str]:
# find anyone who's tagged in a status, for example
mentions = self.recipients if hasattr(self, "recipients") else []

# we always send activities to explicitly mentioned users' inboxes
recipients = [u.inbox for u in mentions or [] if not u.local]
# we always send activities to explicitly mentioned users (using shared inboxes
# where available to avoid duplicate submissions to a given instance)
recipients = {u.shared_inbox or u.inbox for u in mentions if not u.local}

# unless it's a dm, all the followers should receive the activity
if privacy != "direct":
Expand All @@ -173,18 +174,18 @@ def get_recipients(self, software=None) -> list[str]:
if user:
queryset = queryset.filter(following=user)

# ideally, we will send to shared inboxes for efficiency
shared_inboxes = (
queryset.filter(shared_inbox__isnull=False)
.values_list("shared_inbox", flat=True)
.distinct()
# as above, we prefer shared inboxes if available
recipients.update(
queryset.filter(shared_inbox__isnull=False).values_list(
"shared_inbox", flat=True
)
)
# but not everyone has a shared inbox
inboxes = queryset.filter(shared_inbox__isnull=True).values_list(
"inbox", flat=True
recipients.update(
queryset.filter(shared_inbox__isnull=True).values_list(
"inbox", flat=True
)
)
recipients += list(shared_inboxes) + list(inboxes)
return list(set(recipients))
return list(recipients)

def to_activity_dataclass(self):
"""convert from a model to an activity"""
Expand Down
16 changes: 15 additions & 1 deletion bookwyrm/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
from django.utils import timezone
from model_utils import FieldTracker

from bookwyrm.connectors.abstract_connector import get_data
from bookwyrm.preview_images import generate_site_preview_image_task
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, STATIC_FULL_URL
from bookwyrm.settings import RELEASE_API
from bookwyrm.tasks import app, MISC
from .base_model import BookWyrmModel, new_access_code
from .user import User
from .fields import get_absolute_url
Expand Down Expand Up @@ -45,7 +48,7 @@ class SiteSettings(SiteModel):
default_theme = models.ForeignKey(
"Theme", null=True, blank=True, on_delete=models.SET_NULL
)
version = models.CharField(null=True, blank=True, max_length=10)
available_version = models.CharField(null=True, blank=True, max_length=10)

# admin setup options
install_mode = models.BooleanField(default=False)
Expand Down Expand Up @@ -245,3 +248,14 @@ def preview_image(instance, *args, **kwargs):

if len(changed_fields) > 0:
generate_site_preview_image_task.delay()


@app.task(queue=MISC)
def check_for_updates_task():
"""See if git remote knows about a new version"""
site = SiteSettings.objects.get()
release = get_data(RELEASE_API, timeout=3)
available_version = release.get("tag_name", None)
if available_version:
site.available_version = available_version
site.save(update_fields=["available_version"])
73 changes: 66 additions & 7 deletions bookwyrm/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.dispatch import receiver
from django.template.loader import get_template
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.utils.translation import ngettext_lazy
from model_utils import FieldTracker
from model_utils.managers import InheritanceManager

Expand Down Expand Up @@ -107,14 +109,14 @@ def delete(self, *args, **kwargs): # pylint: disable=unused-argument
@property
def recipients(self):
"""tagged users who definitely need to get this status in broadcast"""
mentions = [u for u in self.mention_users.all() if not u.local]
mentions = {u for u in self.mention_users.all() if not u.local}
if (
hasattr(self, "reply_parent")
and self.reply_parent
and not self.reply_parent.user.local
):
mentions.append(self.reply_parent.user)
return list(set(mentions))
mentions.add(self.reply_parent.user)
return list(mentions)

@classmethod
def ignore_activity(
Expand Down Expand Up @@ -178,6 +180,24 @@ def boostable(self):
"""you can't boost dms"""
return self.privacy in ["unlisted", "public"]

@property
def page_title(self):
"""title of the page when only this status is shown"""
return _("%(display_name)s's status") % {"display_name": self.user.display_name}

@property
def page_description(self):
"""description of the page in meta tags when only this status is shown"""
return None

@property
def page_image(self):
"""image to use as preview in meta tags when only this status is shown"""
if self.mention_books.exists():
book = self.mention_books.first()
return book.preview_image or book.cover
return self.user.preview_image

def to_replies(self, **kwargs):
"""helper function for loading AP serialized replies to a status"""
return self.to_ordered_collection(
Expand Down Expand Up @@ -301,6 +321,10 @@ class Meta:

abstract = True

@property
def page_image(self):
return self.book.preview_image or self.book.cover or super().page_image


class Comment(BookStatus):
"""like a review but without a rating and transient"""
Expand Down Expand Up @@ -332,17 +356,26 @@ def pure_content(self):

activity_serializer = activitypub.Comment

@property
def page_title(self):
return _("%(display_name)s's comment on %(book_title)s") % {
"display_name": self.user.display_name,
"book_title": self.book.title,
}


class Quotation(BookStatus):
"""like a review but without a rating and transient"""

quote = fields.HtmlField()
raw_quote = models.TextField(blank=True, null=True)
position = models.IntegerField(
validators=[MinValueValidator(0)], null=True, blank=True
position = models.TextField(
null=True,
blank=True,
)
endposition = models.IntegerField(
validators=[MinValueValidator(0)], null=True, blank=True
endposition = models.TextField(
null=True,
blank=True,
)
position_mode = models.CharField(
max_length=3,
Expand Down Expand Up @@ -374,6 +407,13 @@ def pure_content(self):

activity_serializer = activitypub.Quotation

@property
def page_title(self):
return _("%(display_name)s's quote from %(book_title)s") % {
"display_name": self.user.display_name,
"book_title": self.book.title,
}


class Review(BookStatus):
"""a book review"""
Expand Down Expand Up @@ -403,6 +443,13 @@ def pure_content(self):
"""indicate the book in question for mastodon (or w/e) users"""
return self.content

@property
def page_title(self):
return _("%(display_name)s's review of %(book_title)s") % {
"display_name": self.user.display_name,
"book_title": self.book.title,
}

activity_serializer = activitypub.Review
pure_type = "Article"

Expand All @@ -426,6 +473,18 @@ def pure_content(self):
template = get_template("snippets/generated_status/rating.html")
return template.render({"book": self.book, "rating": self.rating}).strip()

@property
def page_description(self):
return ngettext_lazy(
"%(display_name)s rated %(book_title)s: %(display_rating).1f star",
"%(display_name)s rated %(book_title)s: %(display_rating).1f stars",
"display_rating",
) % {
"display_name": self.user.display_name,
"book_title": self.book.title,
"display_rating": self.rating,
}

activity_serializer = activitypub.Rating
pure_type = "Note"

Expand Down
3 changes: 1 addition & 2 deletions bookwyrm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@
USE_TZ = True


agent = requests.utils.default_user_agent()
USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)"
USER_AGENT = f"BookWyrm (BookWyrm/{VERSION}; +https://{DOMAIN}/)"

# Imagekit generated thumbnails
ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False)
Expand Down
4 changes: 4 additions & 0 deletions bookwyrm/static/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ const tries = {
},
},
f: {
b: {
2: "FB2",
3: "FB3",
},
l: {
a: {
c: "FLAC",
Expand Down
3 changes: 2 additions & 1 deletion bookwyrm/templates/book/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
{% block title %}{{ book|book_title }}{% endblock %}

{% block opengraph %}
{% include 'snippets/opengraph.html' with title=book.title description=book|book_description image=book.preview_image %}
{% firstof book.preview_image book.cover as book_image %}
{% include 'snippets/opengraph.html' with title=book.title description=book|book_description image=book_image %}
{% endblock %}

{% block content %}
Expand Down
4 changes: 2 additions & 2 deletions bookwyrm/templates/confirm_email/confirm_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{% block content %}
<h1 class="title">{% trans "Confirm your email address" %}</h1>

<div class="columns">
<div class="column">
<div class="columns is-multiline">
<div class="column is-full is-half-desktop">
<div class="block content">
<section class="block">
<p>{% trans "A confirmation code has been sent to the email address you used to register your account." %}</p>
Expand Down
Loading

0 comments on commit 46a158d

Please sign in to comment.