Пример #1
0
 def test_format_group_message_title(self):
     detail = group_msg_to_json(self.group.id, '*****@*****.**', 'message')
     notice = UserNotification(to_user='******',
                               msg_type='group_msg',
                               detail=detail)
     msg = notice.format_group_message_title()
     assert '/#group/%(group_id)s/discussions/' % {
         'group_id': self.group.id
     } in msg
Пример #2
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()
Пример #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 org_user_added_cb(sender, **kwargs):
    org_id = kwargs['org_id']
    from_email = kwargs['from_email']
    to_email = kwargs['to_email']
    
    org = get_org_by_id(org_id)
    if not org:
        return
    
    msg_dict = {'from_email': from_email,
                'org_name': org.org_name,
                'org_prefix': org.url_prefix,
                'creator': org.creator}

    n = UserNotification(to_user=to_email, msg_type='org_join_msg',
                         detail=json.dumps(msg_dict))
    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_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()
Пример #7
0
 def test_format_group_message(self):
     detail = group_msg_to_json(self.group.id, '*****@*****.**', 'message')
     notice = UserNotification(to_user='******',
                               msg_type='group_msg',
                               detail=detail)
     resp = Command().format_group_message(notice)
     assert resp.group_url == '/#group/%(group_id)s/discussions/' % {
         'group_id': self.group.id
     }
Пример #8
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()
Пример #9
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()
Пример #10
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 seahub.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()
Пример #11
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()
Пример #12
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()