complete group notifications

- notify group members when a new member accepts an invitation
- notify all group members when a member leaves or is removed
- notify ex-member when they are removed
This commit is contained in:
Hugh Rundle
2021-10-02 15:48:55 +10:00
parent f82af6382f
commit 21e6ed7388
4 changed files with 45 additions and 14 deletions

View File

@ -133,21 +133,27 @@ class GroupMemberInvitation(models.Model):
with transaction.atomic():
BookwyrmGroupMember.from_request(self)
# let the other members know about it
model = apps.get_model("bookwyrm.Notification", require_ready=True)
# tell the group owner
model.objects.create(
user=self.group.user,
related_user=self.user,
related_group=self.group,
notification_type="ACCEPT",
)
# let the other members know about it
for membership in self.group.memberships.all():
member = membership.user
if member != self.user:
if member != self.user and member != self.group.user:
model.objects.create(
user=member,
related_user=self.user,
related_group=self.group,
notification_type="ACCEPT",
notification_type="JOIN",
)
def reject(self):
"""generate a Reject for this membership request"""
self.delete()
# TODO: send notification

View File

@ -7,7 +7,7 @@ from . import Boost, Favorite, ImportJob, Report, Status, User
NotificationType = models.TextChoices(
"NotificationType",
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD REPORT INVITE ACCEPT",
"FAVORITE REPLY MENTION TAG FOLLOW FOLLOW_REQUEST BOOST IMPORT ADD REPORT INVITE ACCEPT JOIN LEAVE REMOVE",
)