diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py
index fdba04ea5..dbded1154 100644
--- a/bookwyrm/models/group.py
+++ b/bookwyrm/models/group.py
@@ -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
\ No newline at end of file
diff --git a/bookwyrm/models/notification.py b/bookwyrm/models/notification.py
index 3632fa10f..a2ddb8747 100644
--- a/bookwyrm/models/notification.py
+++ b/bookwyrm/models/notification.py
@@ -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",
)
diff --git a/bookwyrm/templates/notifications.html b/bookwyrm/templates/notifications.html
index 8dba38c6e..8c076ccbd 100644
--- a/bookwyrm/templates/notifications.html
+++ b/bookwyrm/templates/notifications.html
@@ -42,7 +42,7 @@
{% elif notification.notification_type == 'REPLY' %}
- {% elif notification.notification_type == 'FOLLOW' or notification.notification_type == 'FOLLOW_REQUEST' or notification.notification_type == 'INVITE' or notification.notification_type == 'ACCEPT' %}
+ {% elif notification.notification_type == 'FOLLOW' or notification.notification_type == 'FOLLOW_REQUEST' or notification.notification_type == 'INVITE' or notification.notification_type == 'ACCEPT' or notification.notification_type == 'JOIN' or notification.notification_type == 'LEAVE' or notification.notification_type == 'REMOVE'%}
{% elif notification.notification_type == 'BOOST' %}
@@ -131,9 +131,25 @@
{% endif %}
{% elif notification.notification_type == 'ACCEPT' %}
{% if notification.related_group %}
- {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %} accepted an invitation to join your group "{{ group_name }}"{% endblocktrans %}
+ {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %} accepted your invitation to join group "{{ group_name }}"{% endblocktrans %}
+ {% endif %}
+ {% elif notification.notification_type == 'JOIN' %}
+ {% if notification.related_group %}
+ {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %} has joined your group "{{ group_name }}"{% endblocktrans %}
+ {% endif %}
+ {% elif notification.notification_type == 'LEAVE' %}
+ {% if notification.related_group %}
+ {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %} has left your group "{{ group_name }}"{% endblocktrans %}
+ {% endif %}
+ {% elif notification.notification_type == 'REMOVE' %}
+ {% if notification.related_group %}
+ {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %} has been removed from your group "{{ group_name }}"{% endblocktrans %}
{% endif %}
{% endif %}
+ {% elif notification.notification_type == 'REMOVE' and notification.related_group %}
+ {% blocktrans with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
+ You have been removed from the "{{ group_name }} group"
+ {% endblocktrans %}
{% elif notification.related_import %}
{% url 'import-status' notification.related_import.id as url %}
{% blocktrans %}Your import completed.{% endblocktrans %}
diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py
index 5ae2cecdb..b8c45a4da 100644
--- a/bookwyrm/views/group.py
+++ b/bookwyrm/views/group.py
@@ -158,7 +158,7 @@ def invite_member(request):
@require_POST
@login_required
def remove_member(request):
- """invite a member to the group"""
+ """remove a member from the group"""
group = get_object_or_404(models.BookwyrmGroup, id=request.POST.get("group"))
if not group:
@@ -192,19 +192,28 @@ def remove_member(request):
except IntegrityError:
pass
- # let the other members know about it
+ memberships = models.BookwyrmGroupMember.objects.filter(group=group)
model = apps.get_model("bookwyrm.Notification", require_ready=True)
- memberships = models.BookwyrmGroupMember.objects.get(group=group)
+ notification_type = "LEAVE" if "self_removal" in request.POST and request.POST["self_removal"] else "REMOVE"
+ # let the other members know about it
for membership in memberships:
member = membership.user
if member != request.user:
model.objects.create(
user=member,
- related_user=request.user,
- related_group=request.group,
- notification_type="REMOVE",
+ related_user=user,
+ related_group=group,
+ notification_type=notification_type,
)
+ # let the user (now ex-member) know as well, if they were removed
+ if notification_type == "REMOVE":
+ model.objects.create(
+ user=user,
+ related_group=group,
+ notification_type=notification_type,
+ )
+
return redirect(user.local_path)
@require_POST