~sircmpwn/lists.sr.ht

lists.sr.ht/listssrht/webhooks.py -rw-r--r-- 1.1 KiB View raw
91b54240Drew DeVault Add button to forward a thread to the user 3 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sqlalchemy as sa
from srht.config import cfg
from srht.database import DbSession, db
if not hasattr(db, "session"):
    # Initialize the database if not already configured (for running daemon)
    db = DbSession(cfg("lists.sr.ht", "connection-string"))
    import listssrht.types
    db.init()
from srht.webhook import Event
from srht.webhook.celery import CeleryWebhook, make_worker

worker = make_worker(broker=cfg("lists.sr.ht", "webhooks"))

class ListWebhook(CeleryWebhook):
    events = [
        Event("post:received", "lists:read"),
        Event("list:update", "lists:read"),
        Event("list:delete", "lists:read"),
        Event("patchset:received", "patches:read"),
        Event("patchset:update", "patches:read"), # TODO: Deliver
    ]

    list_id = sa.Column(sa.Integer, sa.ForeignKey("list.id"), nullable=False)
    list = sa.orm.relationship("List")

class UserWebhook(CeleryWebhook):
    events = [
        Event("email:received", "emails:read"),
        Event("list:create", "lists:read"),
        Event("subscription:create", "subs:read"),
        Event("subscription:remove", "subs:read"),
    ]