def by_channel(cls, channel): q = cls.all() q = q.filter(cls.channels.any(channel)) q = q.filter(cls._event.in_(Events.names())) q = q.order_by(cls.created_at.desc()) q = q.order_by(cls.id.desc()) return q
def by_role(cls, role): sq = db.session.query(Subscription.channel) sq = sq.filter(Subscription.deleted_at == None) # noqa sq = sq.filter(Subscription.role_id == role.id) sq = sq.cte('sq') q = cls.all() q = q.filter(cls.actor_id != role.id) q = q.filter(cls.channels.any(sq.c.channel)) q = q.filter(cls._event.in_(Events.names())) q = q.order_by(cls.created_at.desc()) q = q.order_by(cls.id.desc()) return q
def by_channels(cls, channels, since=None, exclude_actor_id=None): channels = cast(channels, ARRAY(db.String(255))) q = cls.all() q = q.filter(cls.channels.overlap(channels)) # q = q.filter(cls.channels.any(channel)) q = q.filter(cls._event.in_(Events.names())) if exclude_actor_id is not None: q = q.filter(cls.actor_id != exclude_actor_id) if since is not None: q = q.filter(cls.created_at >= since) q = q.order_by(cls.created_at.desc()) q = q.order_by(cls.id.desc()) return q
def by_channels(cls, channels, role, since=None): channels = cast(channels, ARRAY(db.String(255))) q = cls.all() q = q.filter(cls.channels.overlap(channels)) q = q.filter(cls._event.in_(Events.names())) q = q.filter(or_( cls.actor_id != role.id, cls.actor_id == None # noqa )) since = since or role.notified_at if since is not None and role.notified_at is not None: since = max(since, role.notified_at) if since is not None: q = q.filter(cls.created_at >= since) q = q.order_by(cls.created_at.desc()) return q
def by_role(cls, role, since=None): columns = array_agg(Subscription.channel).label('channels') sq = db.session.query(columns) sq = sq.filter(Subscription.deleted_at == None) # noqa sq = sq.filter(Subscription.role_id == role.id) sq = sq.cte('sq') q = cls.all() q = q.filter(or_( cls.actor_id != role.id, cls.actor_id == None # noqa )) q = q.filter(cls.channels.overlap(sq.c.channels)) q = q.filter(cls._event.in_(Events.names())) if since is not None: q = q.filter(cls.created_at >= since) if role.notified_at is not None: q = q.filter(cls.created_at >= role.notified_at) q = q.order_by(cls.created_at.desc()) q = q.order_by(cls.id.desc()) return q
def event(self): return Events.get(self._event)