diff --git a/alembic/env.py b/alembic/env.py index f0bf9cd..ca982b3 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -49,6 +49,7 @@ def run_migrations_offline() -> None: target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, + render_as_batch=True, ) with context.begin_transaction(): @@ -69,7 +70,11 @@ def run_migrations_online() -> None: ) with connectable.connect() as connection: - context.configure(connection=connection, target_metadata=target_metadata) + context.configure( + connection=connection, + target_metadata=target_metadata, + render_as_batch=True, + ) with context.begin_transaction(): context.run_migrations() diff --git a/alembic/versions/2b51ae7047cb_webmention_notifications.py b/alembic/versions/2b51ae7047cb_webmention_notifications.py new file mode 100644 index 0000000..a72eb87 --- /dev/null +++ b/alembic/versions/2b51ae7047cb_webmention_notifications.py @@ -0,0 +1,32 @@ +"""Webmention notifications + +Revision ID: 2b51ae7047cb +Revises: e58c1ffadf2e +Create Date: 2022-07-19 20:22:06.968951 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = '2b51ae7047cb' +down_revision = 'e58c1ffadf2e' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('notifications', schema=None) as batch_op: + batch_op.create_foreign_key('fk_webmention_id', 'webmention', ['webmention_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('notifications', schema=None) as batch_op: + batch_op.drop_constraint('fk_webmention_id', type_='foreignkey') + + # ### end Alembic commands ### diff --git a/app/admin.py b/app/admin.py index f939f5e..57aaa38 100644 --- a/app/admin.py +++ b/app/admin.py @@ -435,6 +435,7 @@ async def get_notifications( models.OutboxObject.outbox_object_attachments ).options(joinedload(models.OutboxObjectAttachment.upload)), ), + joinedload(models.Notification.webmention), ) .order_by(models.Notification.created_at.desc()) ) diff --git a/app/main.py b/app/main.py index eca9b27..ed540db 100644 --- a/app/main.py +++ b/app/main.py @@ -76,6 +76,8 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac # TODO(ts): # # Next: +# - Webmention notification +# - Page support # - Article support # - indieauth tweaks # - API for posting notes diff --git a/app/models.py b/app/models.py index 1958561..80ec2d6 100644 --- a/app/models.py +++ b/app/models.py @@ -300,35 +300,6 @@ class Following(Base): ap_actor_id = Column(String, nullable=False, unique=True) -@enum.unique -class NotificationType(str, enum.Enum): - NEW_FOLLOWER = "new_follower" - UNFOLLOW = "unfollow" - LIKE = "like" - UNDO_LIKE = "undo_like" - ANNOUNCE = "announce" - UNDO_ANNOUNCE = "undo_announce" - MENTION = "mention" - - -class Notification(Base): - __tablename__ = "notifications" - - id = Column(Integer, primary_key=True, index=True) - created_at = Column(DateTime(timezone=True), nullable=False, default=now) - notification_type = Column(Enum(NotificationType), nullable=True) - is_new = Column(Boolean, nullable=False, default=True) - - actor_id = Column(Integer, ForeignKey("actor.id"), nullable=True) - actor = relationship(Actor, uselist=False) - - outbox_object_id = Column(Integer, ForeignKey("outbox.id"), nullable=True) - outbox_object = relationship(OutboxObject, uselist=False) - - inbox_object_id = Column(Integer, ForeignKey("inbox.id"), nullable=True) - inbox_object = relationship(InboxObject, uselist=False) - - class IncomingActivity(Base): __tablename__ = "incoming_activity" @@ -503,6 +474,43 @@ class Webmention(Base): return None +@enum.unique +class NotificationType(str, enum.Enum): + NEW_FOLLOWER = "new_follower" + UNFOLLOW = "unfollow" + LIKE = "like" + UNDO_LIKE = "undo_like" + ANNOUNCE = "announce" + UNDO_ANNOUNCE = "undo_announce" + MENTION = "mention" + NEW_WEBMENTION = "new_webmention" + UPDATED_WEBMENTION = "updated_webmention" + DELETED_WEBMENTION = "deleted_webmention" + + +class Notification(Base): + __tablename__ = "notifications" + + id = Column(Integer, primary_key=True, index=True) + created_at = Column(DateTime(timezone=True), nullable=False, default=now) + notification_type = Column(Enum(NotificationType), nullable=True) + is_new = Column(Boolean, nullable=False, default=True) + + actor_id = Column(Integer, ForeignKey("actor.id"), nullable=True) + actor = relationship(Actor, uselist=False) + + outbox_object_id = Column(Integer, ForeignKey("outbox.id"), nullable=True) + outbox_object = relationship(OutboxObject, uselist=False) + + inbox_object_id = Column(Integer, ForeignKey("inbox.id"), nullable=True) + inbox_object = relationship(InboxObject, uselist=False) + + webmention_id = Column( + Integer, ForeignKey("webmention.id", name="fk_webmention_id"), nullable=True + ) + webmention = relationship(Webmention, uselist=False) + + outbox_fts = Table( "outbox_fts", metadata_obj, diff --git a/app/templates/indieauth_flow.html b/app/templates/indieauth_flow.html index 6af8071..819ee45 100644 --- a/app/templates/indieauth_flow.html +++ b/app/templates/indieauth_flow.html @@ -2,41 +2,40 @@ {% extends "layout.html" %} {% block content %}
wants you to login as {{ me }} with the following redirect URI: {{ redirect_uri }}
.
wants you to login as {{ me }} with the following redirect URI: {{ redirect_uri }}
.