mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Updates group leave and remove notifications
This commit is contained in:
parent
c65381adf9
commit
736d29ea20
5 changed files with 28 additions and 21 deletions
|
@ -57,10 +57,11 @@ class Notification(BookWyrmModel):
|
|||
@transaction.atomic
|
||||
def notify(cls, user, related_user, **kwargs):
|
||||
"""Create a notification"""
|
||||
if not user.local or user == related_user:
|
||||
if related_user and (not user.local or user == related_user):
|
||||
return
|
||||
notification, _ = cls.objects.get_or_create(user=user, **kwargs)
|
||||
notification.related_users.add(related_user)
|
||||
if related_user:
|
||||
notification.related_users.add(related_user)
|
||||
notification.read = False
|
||||
notification.save()
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
{% block description %}
|
||||
|
||||
{% blocktrans trimmed with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
accepted your invitation to join group "<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
accepted your invitation to join group
|
||||
"<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -12,11 +12,15 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block description %}
|
||||
|
||||
{% blocktrans trimmed with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
invited you to join the group "<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
invited you to join the group
|
||||
"<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
|
||||
<div class="row shrink">
|
||||
{% include 'snippets/join_invitation_buttons.html' with group=notification.related_group %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
{% block description %}
|
||||
|
||||
{% blocktrans trimmed with group_name=notification.related_group.name group_path=notification.related_group.local_path %}
|
||||
has left your group "<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
<a href="{{ related_user_link }}">{{ related_user }}</a>
|
||||
has left your group
|
||||
"<a href="{{ group_path }}">{{ group_name }}</a>"
|
||||
{% endblocktrans %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -59,11 +59,11 @@ class Group(View):
|
|||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||
for field in form.changed_data:
|
||||
notification_type = (
|
||||
"GROUP_PRIVACY"
|
||||
model.GROUP_PRIVACY
|
||||
if field == "privacy"
|
||||
else "GROUP_NAME"
|
||||
else model.GROUP_NAME
|
||||
if field == "name"
|
||||
else "GROUP_DESCRIPTION"
|
||||
else model.GROUP_DESCRIPTION
|
||||
if field == "description"
|
||||
else None
|
||||
)
|
||||
|
@ -71,9 +71,9 @@ class Group(View):
|
|||
for membership in memberships:
|
||||
member = membership.user
|
||||
if member != request.user:
|
||||
model.objects.create(
|
||||
user=member,
|
||||
related_user=request.user,
|
||||
model.notify(
|
||||
member,
|
||||
request.user,
|
||||
related_group=user_group,
|
||||
notification_type=notification_type,
|
||||
)
|
||||
|
@ -244,24 +244,22 @@ def remove_member(request):
|
|||
|
||||
memberships = models.GroupMember.objects.filter(group=group)
|
||||
model = apps.get_model("bookwyrm.Notification", require_ready=True)
|
||||
notification_type = "LEAVE" if user == request.user else "REMOVE"
|
||||
notification_type = models.LEAVE if user == request.user else model.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=user,
|
||||
model.notify(
|
||||
member,
|
||||
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,
|
||||
if notification_type == model.REMOVE:
|
||||
model.notify(
|
||||
user, None, related_group=group, notification_type=notification_type
|
||||
)
|
||||
|
||||
return redirect(group.local_path)
|
||||
|
|
Loading…
Reference in a new issue