Пример #1
0
def read_notification(request, methods=['GET']):
    notification = get_object_or_404(Notification, pk=request.GET['pk'])
    read_user = request.user
    read_notification = UserNotification.objects.filter(user=read_user).filter(notification=notification)
    if not read_notification:
        user_notification = UserNotification(user=read_user, notification=notification)
        user_notification.save()
    return JsonResponse({'notification': notification.as_json(), 'result': 'success'})
Пример #2
0
def archive_notification(request, methods=['GET']):
    notification = get_object_or_404(Notification, pk=request.GET['pk'])
    user_notification = UserNotification.objects.filter(user=request.user).filter(notification=notification).first()
    if not user_notification:
        user_notification = UserNotification(user=request.user, notification=notification, archived=True)

    user_notification.archived = True
    user_notification.save()
    return JsonResponse({'notification': notification.as_json(), 'result': 'success'})
Пример #3
0
def innerpub_msg_added_cb(sender, instance, **kwargs):
    from_email = instance.from_email

    users = get_emailusers(-1, -1)
    for u in users:
        if u.email == from_email:
            continue
        try:
            UserNotification.objects.get(to_user=u.email,
                                         msg_type='innerpub_msg')
        except UserNotification.DoesNotExist:
            n = UserNotification(to_user=u.email, msg_type='innerpub_msg',
                                 detail='')
            n.save()
Пример #4
0
def grpmsg_added_cb(sender, **kwargs):
    group_id = kwargs['group_id']
    from_email = kwargs['from_email']
    group_members = ccnet_threaded_rpc.get_group_members(int(group_id))
    for m in group_members:
        if from_email == m.user_name:
            continue
        try:
            UserNotification.objects.get(to_user=m.user_name,
                                         msg_type='group_msg',
                                         detail=group_id)
        except UserNotification.DoesNotExist:
            n = UserNotification(to_user=m.user_name, msg_type='group_msg',
                                 detail=group_id)
            n.save()
Пример #5
0
def grpmsg_reply_added_cb(sender, **kwargs):
    msg_id = kwargs['msg_id']
    reply_from_email = kwargs['from_email'] # this value may be used in future
    try:
        group_msg = GroupMessage.objects.get(id=msg_id)
    except GroupMessage.DoesNotExist:
        pass

    try:
        UserNotification.objects.get(to_user=group_msg.from_email,
                                     msg_type='grpmsg_reply',
                                     detail=msg_id)
    except UserNotification.DoesNotExist:
        n = UserNotification(to_user=group_msg.from_email,
                             msg_type='grpmsg_reply',
                             detail=msg_id)
        n.save()
Пример #6
0
def grpmsg_added_cb(sender, **kwargs):
    group_id = kwargs['group_id']
    from_email = kwargs['from_email']
    group_members = get_group_members(int(group_id))
    if len(group_members) > 15: # No need to send notification when group is 
        return                  # too large

    for m in group_members:
        if from_email == m.user_name:
            continue
        try:
            UserNotification.objects.get(to_user=m.user_name,
                                         msg_type='group_msg',
                                         detail=group_id)
        except UserNotification.DoesNotExist:
            n = UserNotification(to_user=m.user_name, msg_type='group_msg',
                                 detail=group_id)
            n.save()
Пример #7
0
def msgreply_save_handler(sender, instance, **kwargs):
    """
    Handle sending notification to '@<user>' when reply messages.
    """
    from_email = instance.from_email
    reply_msg =  instance.message
    group_msg =  instance.reply_to
    to_user = ''

    from base.templatetags.seahub_tags import at_pattern
    m = re.match(at_pattern, reply_msg)
    if m:
        nickname_or_emailprefix = m.group()[1:]
        for member in get_group_members(group_msg.group_id):
            # For every group member, get his username and nickname if
            # it exists, check whether match.
            username = member.user_name
            if username == from_email:
                continue
            
            p = get_first_object_or_none(
                Profile.objects.filter(user=username))
            nickname = p.nickname if p else ''
            if nickname == nickname_or_emailprefix or \
                    username.split('@')[0] == nickname_or_emailprefix:
                to_user = username
                break

        if to_user:
            # Send notification to the user if he replies someone else'
            # message.
            try:
                UserNotification.objects.get(to_user=to_user,
                                             msg_type='grpmsg_reply',
                                             detail=group_msg.id)
            except UserNotification.DoesNotExist:
                n = UserNotification(to_user=to_user,
                                     msg_type='grpmsg_reply',
                                     detail=group_msg.id)
                n.save()
Пример #8
0
def innerpubmsg_reply_added_cb(sender, instance, **kwargs):
    innerpub_msg = instance.reply_to
    from_email = instance.from_email
    msg_id = innerpub_msg.id
    
    if from_email == innerpub_msg.from_email:
        # No need to send notification when reply own message.
        return

    try:
        innerpub_msg = InnerPubMsg.objects.get(id=msg_id)
    except InnerPubMsg.DoesNotExist:
        pass

    try:
        UserNotification.objects.get(to_user=innerpub_msg.from_email,
                                     msg_type='innerpubmsg_reply',
                                     detail=msg_id)
    except UserNotification.DoesNotExist:
        n = UserNotification(to_user=innerpub_msg.from_email,
                             msg_type='innerpubmsg_reply',
                             detail=msg_id)
        n.save()