diff --git a/bookwyrm/migrations/0104_auto_20211001_2012.py b/bookwyrm/migrations/0104_auto_20211001_2012.py new file mode 100644 index 00000000..8d429040 --- /dev/null +++ b/bookwyrm/migrations/0104_auto_20211001_2012.py @@ -0,0 +1,53 @@ +# Generated by Django 3.2.5 on 2021-10-01 20:12 + +from django.db import migrations, models + + +def set_thread_id(app_registry, schema_editor): + """set thread ids""" + db_alias = schema_editor.connection.alias + # set the thread id on parent nodes + model = app_registry.get_model("bookwyrm", "Status") + model.objects.using(db_alias).filter(reply_parent__isnull=True).update( + thread_id=models.F("id") + ) + + queryset = model.objects.using(db_alias).filter( + reply_parent__isnull=False, + reply_parent__thread_id__isnull=False, + thread_id__isnull=True, + ) + iters = 0 + while queryset.exists(): + queryset.update( + thread_id=models.Subquery( + model.objects.filter(id=models.OuterRef("reply_parent")).values_list( + "thread_id" + )[:1] + ) + ) + print(iters) + iters += 1 + if iters > 50: + print("exceeded query depth") + break + + +def reverse(*_): + """do nothing""" + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0103_remove_connector_local"), + ] + + operations = [ + migrations.AddField( + model_name="status", + name="thread_id", + field=models.IntegerField(blank=True, null=True), + ), + migrations.RunPython(set_thread_id, reverse), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index b6203678..58488123 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -57,6 +57,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): on_delete=models.PROTECT, activitypub_field="inReplyTo", ) + thread_id = models.IntegerField(blank=True, null=True) objects = InheritanceManager() activity_serializer = activitypub.Note @@ -68,6 +69,17 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): ordering = ("-published_date",) + def save(self, *args, **kwargs): + """save and notify""" + if self.reply_parent: + self.thread_id = self.reply_parent.thread_id or self.reply_parent.id + + super().save(*args, **kwargs) + + if not self.reply_parent: + self.thread_id = self.id + super().save(broadcast=False, update_fields=["thread_id"]) + def delete(self, *args, **kwargs): # pylint: disable=unused-argument """ "delete" a status""" if hasattr(self, "boosted_status"): diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 895a537a..39469a7a 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -13,7 +13,7 @@ VERSION = "0.0.1" PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") -JS_CACHE = "e2bc0653" +JS_CACHE = "c02929b1" # email EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend") diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index e1012c2f..eca7914a 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -492,6 +492,23 @@ ol.ordered-list li::before { } } +/* Threads + ******************************************************************************/ + +.thread .is-main .card { + box-shadow: 0 0.5em 1em -0.125em rgb(50 115 220 / 35%), 0 0 0 1px rgb(50 115 220 / 2%); +} + +.thread::after { + content: ""; + position: absolute; + z-index: -1; + top: 0; + bottom: 0; + left: 2.5em; + border-left: 2px solid #e0e0e0; +} + /* Dimensions * @todo These could be in rem. ******************************************************************************/ diff --git a/bookwyrm/templates/feed/thread.html b/bookwyrm/templates/feed/thread.html index 793cddfc..c1b624e3 100644 --- a/bookwyrm/templates/feed/thread.html +++ b/bookwyrm/templates/feed/thread.html @@ -1,6 +1,7 @@ {% load status_display %} -
- {{ status.published_date|published_date }}
+ {{ status.published_date|published_date }}
{% if status.progress %}
{% if status.progress_mode == 'PG' %}
diff --git a/bookwyrm/templates/snippets/status/layout.html b/bookwyrm/templates/snippets/status/layout.html
index 39445d9c..9d1863ee 100644
--- a/bookwyrm/templates/snippets/status/layout.html
+++ b/bookwyrm/templates/snippets/status/layout.html
@@ -3,7 +3,10 @@
{% load utilities %}
{% block card-header %}
- (comment on "Test Edition") (comment on "Test Edition")