diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api/notifications.py')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/api/notifications.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/notifications.py b/packages/meshbay-hub/src/meshbay_hub/api/notifications.py index e4bac2e..128c0d1 100644 --- a/packages/meshbay-hub/src/meshbay_hub/api/notifications.py +++ b/packages/meshbay-hub/src/meshbay_hub/api/notifications.py @@ -26,8 +26,9 @@ from sqlalchemy import delete, func, select from sqlalchemy.ext.asyncio import AsyncSession from meshbay_hub.api.deps import get_current_user +from meshbay_hub.api.push import push_notification from meshbay_hub.db.engine import get_db -from meshbay_hub.db.models import GroupMember, Notification, User +from meshbay_hub.db.models import GroupMember, Notification, User, UserPreference router = APIRouter(prefix="/v1/notifications", tags=["notifications"]) @@ -157,9 +158,23 @@ async def create_notification( conversation is a single line saying when it last spoke rather than forty saying that it spoke. - Returns None when the person muted this group: the point of muting is that - nothing is created, not that something is created and hidden. + Returns None when the person muted this group, or turned every notification + off: the point of muting is that nothing is created, not that something is + created and hidden — and nothing created is nothing pushed to a phone. + + The account-wide switch used to be read by the interface alone, which hid + the list while rows went on accumulating; with a phone that is told about + each row, a switch only the interface honours is a switch that does nothing. """ + disabled = await db.execute( + select(UserPreference.value).where( + UserPreference.user_id == user_id, + UserPreference.key == "notifications_disabled", + ) + ) + if disabled.scalar() == "true": + return None + if group_id is not None: muted = await db.execute( select(GroupMember.muted).where( @@ -185,6 +200,7 @@ async def create_notification( existing.read = False existing.created_at = datetime.now(UTC) await db.flush() + await push_notification(db, existing) return existing notif = Notification( @@ -193,4 +209,5 @@ async def create_notification( ) db.add(notif) await db.flush() + await push_notification(db, notif) return notif |