mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Use signal for creating group invite notification
This commit is contained in:
parent
03f5a3f2c1
commit
aeefd5a3e9
2 changed files with 16 additions and 13 deletions
|
@ -140,15 +140,6 @@ class GroupMemberInvitation(models.Model):
|
|||
# make an invitation
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# now send the invite
|
||||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||
model.notify(
|
||||
self.user,
|
||||
self.group.user,
|
||||
related_group=self.group,
|
||||
notification_type="INVITE",
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def accept(self):
|
||||
"""turn this request into the real deal"""
|
||||
|
@ -160,7 +151,7 @@ class GroupMemberInvitation(models.Model):
|
|||
self.group.user,
|
||||
self.user,
|
||||
related_group=self.group,
|
||||
notification_type="ACCEPT",
|
||||
notification_type=model.ACCEPT,
|
||||
)
|
||||
|
||||
# let the other members know about it
|
||||
|
@ -171,10 +162,9 @@ class GroupMemberInvitation(models.Model):
|
|||
member,
|
||||
self.user,
|
||||
related_group=self.group,
|
||||
notification_type="JOIN",
|
||||
notification_type=model.JOIN,
|
||||
)
|
||||
|
||||
def reject(self):
|
||||
"""generate a Reject for this membership request"""
|
||||
|
||||
self.delete()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from django.db import models, transaction
|
||||
from django.dispatch import receiver
|
||||
from .base_model import BookWyrmModel
|
||||
from . import Boost, Favorite, ImportJob, Report, Status, User
|
||||
from . import Boost, Favorite, GroupMemberInvitation, ImportJob, Report, Status, User
|
||||
|
||||
|
||||
class Notification(BookWyrmModel):
|
||||
|
@ -205,3 +205,16 @@ def notify_admins_on_report(sender, instance, *args, **kwargs):
|
|||
unread=True,
|
||||
)
|
||||
notification.related_reports.add(instance)
|
||||
|
||||
|
||||
@receiver(models.signals.post_save, sender=GroupMemberInvitation)
|
||||
@transaction.atomic
|
||||
# pylint: disable=unused-argument
|
||||
def notify_user_on_group_invite(sender, instance, *args, **kwargs):
|
||||
"""Cool kids club here we come"""
|
||||
Notification.notify(
|
||||
instance.user,
|
||||
instance.group.user,
|
||||
related_group=instance.group,
|
||||
notification_type=Notification.INVITE,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue