delete unnecessary notifications

This commit is contained in:
Tim Gröger 2023-05-01 22:06:24 +02:00
parent 26235fef49
commit c721f25104
1 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,8 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from enum import IntEnum from enum import IntEnum
from typing import Optional, Tuple from typing import Optional, Tuple, Union
from flaschengeist.models import UtcDateTime from flaschengeist.controller import userController
from flaschengeist.models import Notification, UtcDateTime
from flaschengeist.models.user import User from flaschengeist.models.user import User
from werkzeug.exceptions import BadRequest, Conflict, NotFound from werkzeug.exceptions import BadRequest, Conflict, NotFound
@ -364,9 +365,21 @@ def get_invitations(user: User):
).all() ).all()
def cleanup_notifications(inv: Invitation):
notifications = tuple(
filter(
lambda notification: notification.data.get("invitation") == inv.id, EventPlugin.getPlugin().notifications
)
)
for notification in notifications:
db.session.delete(notification)
db.session.commit()
def cancel_invitation(inv: Invitation): def cancel_invitation(inv: Invitation):
db.session.delete(inv) db.session.delete(inv)
db.session.commit() db.session.commit()
cleanup_notifications(inv)
def respond_invitation(invite: Invitation, accepted=True): def respond_invitation(invite: Invitation, accepted=True):