mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 00:43:53 +00:00
Modify group msg notification
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
from signals import *
|
||||||
|
from handlers import *
|
||||||
|
from models import GroupMessage
|
||||||
|
|
||||||
|
grpmsg_added.connect(grpmsg_added_cb, sender=GroupMessage)
|
||||||
|
21
group/handlers.py
Normal file
21
group/handlers.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from seaserv import ccnet_threaded_rpc
|
||||||
|
|
||||||
|
from signals import grpmsg_added
|
||||||
|
from seahub.notifications.models import UserNotification
|
||||||
|
|
||||||
|
def grpmsg_added_cb(sender, **kwargs):
|
||||||
|
group_id = kwargs['group_id']
|
||||||
|
from_email = kwargs['from_email']
|
||||||
|
l = UserNotification.objects.filter(msg_type='group_msg',
|
||||||
|
detail=group_id)
|
||||||
|
if len(l) == 0:
|
||||||
|
group_members = ccnet_threaded_rpc.get_group_members(int(group_id))
|
||||||
|
for m in group_members:
|
||||||
|
if from_email == m.user_name:
|
||||||
|
continue
|
||||||
|
n = UserNotification(to_user=m.user_name, msg_type='group_msg',
|
||||||
|
detail=group_id)
|
||||||
|
n.save()
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
@@ -1,6 +1,8 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
from seahub.notifications.models import UserNotification
|
||||||
|
|
||||||
class GroupMessage(models.Model):
|
class GroupMessage(models.Model):
|
||||||
group_id = models.IntegerField()
|
group_id = models.IntegerField()
|
||||||
from_email = models.EmailField()
|
from_email = models.EmailField()
|
||||||
|
3
group/signals.py
Normal file
3
group/signals.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import django.dispatch
|
||||||
|
|
||||||
|
grpmsg_added = django.dispatch.Signal(providing_args=["group_id", "from_email"])
|
@@ -12,6 +12,7 @@ from pysearpc import SearpcError
|
|||||||
|
|
||||||
from models import GroupMessage, MessageReply
|
from models import GroupMessage, MessageReply
|
||||||
from forms import MessageForm
|
from forms import MessageForm
|
||||||
|
from signals import grpmsg_added
|
||||||
from seahub.contacts.models import Contact
|
from seahub.contacts.models import Contact
|
||||||
from seahub.notifications.models import UserNotification
|
from seahub.notifications.models import UserNotification
|
||||||
from seahub.utils import go_error, go_permission_error, validate_group_name
|
from seahub.utils import go_error, go_permission_error, validate_group_name
|
||||||
@@ -140,7 +141,7 @@ def render_group_info(request, group_id, form):
|
|||||||
repos.append(repo)
|
repos.append(repo)
|
||||||
|
|
||||||
# remove user notifications
|
# remove user notifications
|
||||||
UserNotification.objects.filter(email=request.user.username,
|
UserNotification.objects.filter(to_user=request.user.username,
|
||||||
detail=str(group_id)).delete()
|
detail=str(group_id)).delete()
|
||||||
|
|
||||||
"""group messages"""
|
"""group messages"""
|
||||||
@@ -234,18 +235,9 @@ def group_info(request, group_id):
|
|||||||
# clear form data
|
# clear form data
|
||||||
form = MessageForm()
|
form = MessageForm()
|
||||||
|
|
||||||
# add user notification if not exists
|
# send signal
|
||||||
l = UserNotification.objects.filter(note_type='group_msg',
|
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
|
||||||
detail=group_id)
|
from_email=request.user.username)
|
||||||
if len(l) == 0:
|
|
||||||
group_members = ccnet_threaded_rpc.get_group_members(int(group_id))
|
|
||||||
for m in group_members:
|
|
||||||
if request.user.username == m.user_name:
|
|
||||||
continue
|
|
||||||
n = UserNotification(email=m.user_name,
|
|
||||||
note_type='group_msg', detail=group_id)
|
|
||||||
n.save()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
form = MessageForm()
|
form = MessageForm()
|
||||||
|
|
||||||
|
@@ -6,9 +6,9 @@ class Notification(models.Model):
|
|||||||
primary = models.BooleanField(default=False)
|
primary = models.BooleanField(default=False)
|
||||||
|
|
||||||
class UserNotification(models.Model):
|
class UserNotification(models.Model):
|
||||||
email = models.EmailField(max_length=255)
|
to_user = models.EmailField(max_length=255)
|
||||||
note_type = models.CharField(max_length=30)
|
msg_type = models.CharField(max_length=30)
|
||||||
detail = models.CharField(max_length=100)
|
detail = models.TextField()
|
||||||
|
|
||||||
class NotificationForm(ModelForm):
|
class NotificationForm(ModelForm):
|
||||||
"""
|
"""
|
||||||
|
4
views.py
4
views.py
@@ -547,9 +547,9 @@ def myhome(request):
|
|||||||
|
|
||||||
# user notifications
|
# user notifications
|
||||||
l = []
|
l = []
|
||||||
notes = UserNotification.objects.filter(email=request.user.username)
|
notes = UserNotification.objects.filter(to_user=request.user.username)
|
||||||
for n in notes:
|
for n in notes:
|
||||||
if n.note_type == 'group_msg':
|
if n.msg_type == 'group_msg':
|
||||||
l.append(n.detail)
|
l.append(n.detail)
|
||||||
|
|
||||||
# my groups
|
# my groups
|
||||||
|
Reference in New Issue
Block a user