Esempio n. 1
0
    def new_message(self, from_user, subject, content, to_users=None,
                    to_groups=None):
        """Create a new conversation thread and its first message.

        The new thread will involve both the ``from_user`` and all users from
        the ``to_users`` and ``to_groups`` parameters. All users belonging to
        a group in the ``to_groups`` parameter are added to the thread.

        """

        to_users = list(to_users) if to_users is not None else []
        to_groups = list(to_groups) if to_groups is not None else []
        from user_messages.models import Thread
        thread = Thread.objects.create(subject=subject)
        thread.userthread_set.create(user=from_user, unread=False)
        for user in to_users:
            if user.id != from_user.id:
                thread.userthread_set.create(user=user)
        for group_profile in to_groups:
            active_members = group_profile.groupmember_set.filter(
                user__is_active=True)
            for group_member in active_members:
                thread.groupmemberthread_set.create(
                    user=group_member.user,
                    group=group_profile.group,
                    unread=False if group_member.user == from_user else True
                )
        msg = self.create(thread=thread, sender=from_user, content=content)
        message_sent.send(
            sender=self.model, message=msg, thread=thread, reply=False)
        return msg
Esempio n. 2
0
 def new_message(self, from_user, to_users, subject, content):
     from user_messages.models import Thread
     thread = Thread.objects.create(subject=subject)
     for user in to_users:
         thread.userthread_set.create(user=user, deleted=False, unread=True)
     thread.userthread_set.create(user=from_user, deleted=True, unread=False)
     msg = self.create(thread=thread, sender=from_user, content=content)
     message_sent.send(sender=self.model, message=msg, thread=thread, reply=False)
     return msg
Esempio n. 3
0
 def new_reply(self, thread, user, content):
     msg = self.create(thread=thread, sender=user, content=content)
     thread.userthread_set.exclude(user=user).update(deleted=False,
                                                     unread=True)
     message_sent.send(sender=self.model,
                       message=msg,
                       thread=thread,
                       reply=True)
     return msg
Esempio n. 4
0
    def new_reply(self, thread, user, content):
        """Generate a new message for the input thread.

        Whenever a new reply is created, all of the previously subscribed
        users will see this message in their inbox, even if they had
        previously deleted the message in the past.

        """

        msg = self.create(thread=thread, sender=user, content=content)
        thread.userthread_set.exclude(user=user).update(
            deleted=False, unread=True)
        thread.groupmemberthread_set.exclude(user=user).update(
            deleted=False, unread=True)
        thread.userthread_set.filter(user=user).update(unread=False)
        thread.groupmemberthread_set.filter(user=user).update(unread=False)
        message_sent.send(
            sender=self.model, message=msg, thread=thread, reply=True)
        return msg
Esempio n. 5
0
    def new_reply(self, thread, user, content):
        """Generate a new message for the input thread.

        Whenever a new reply is created, all of the previously subscribed
        users will see this message in their inbox, even if they had
        previously deleted the message in the past.

        """

        msg = self.create(thread=thread, sender=user, content=content)
        thread.userthread_set.exclude(user=user).update(deleted=False,
                                                        unread=True)
        thread.groupmemberthread_set.exclude(user=user).update(deleted=False,
                                                               unread=True)
        thread.userthread_set.filter(user=user).update(unread=False)
        thread.groupmemberthread_set.filter(user=user).update(unread=False)
        message_sent.send(sender=self.model,
                          message=msg,
                          thread=thread,
                          reply=True)
        return msg
Esempio n. 6
0
    def new_message(self,
                    from_user,
                    subject,
                    content,
                    to_users=None,
                    to_groups=None):
        """Create a new conversation thread and its first message.

        The new thread will involve both the ``from_user`` and all users from
        the ``to_users`` and ``to_groups`` parameters. All users belonging to
        a group in the ``to_groups`` parameter are added to the thread.

        """

        to_users = list(to_users) if to_users is not None else []
        to_groups = list(to_groups) if to_groups is not None else []
        from user_messages.models import Thread
        thread = Thread.objects.create(subject=subject)
        thread.userthread_set.create(user=from_user, unread=False)
        for user in to_users:
            if user.id != from_user.id:
                thread.userthread_set.create(user=user)
        for group_profile in to_groups:
            active_members = group_profile.groupmember_set.filter(
                user__is_active=True)
            for group_member in active_members:
                thread.groupmemberthread_set.create(
                    user=group_member.user,
                    group=group_profile.group,
                    unread=False if group_member.user == from_user else True)
        msg = self.create(thread=thread, sender=from_user, content=content)
        message_sent.send(sender=self.model,
                          message=msg,
                          thread=thread,
                          reply=False)
        return msg
Esempio n. 7
0
 def new_reply(self, thread, user, content):
     msg = self.create(thread=thread, sender=user, content=content)
     thread.userthread_set.exclude(user=user).update(deleted=False, unread=True)
     message_sent.send(sender=self.model, message=msg, thread=thread, reply=True)
     return msg