pinax / pinax-messages

a Django app for allowing users of your site to send messages to each other
MIT License
202 stars 58 forks source link

Add `sent` box and/or ThreadStart model #54

Open tarsil opened 4 years ago

tarsil commented 4 years ago

Is your feature request related to a problem? Please describe. Adding a concept of the sent box or something that allows knowing who started a thread in the first place.

Describe the solution you'd like Adding a concept of a sent box it would help to understand which conversations you have started and map better.

For the ThreadStart:

import uuid as _uuid

class ThreadStart(models.Model):
    uuid = models.UUIDField(editable=False, null=False, blank=False, default=_uuid)
    thread = models.ForeignKey(Thread, related_name="threads_started", null=False, blank=False, on_delete =models.CASCADE)
    sender = models.ForeignKey(AUTH_USER_MODEL, related_name="threads_started", null=False, blank=False, on_delete=models.CASCADE)

    def __str__(self):
         return "User: {} - Thread: {}".format(self.sender, self.thread)

For the sent box without thread start:

    @classmethod
    def sent(cls, user):
        """
        Returns the sent message folder
        :param user: User to check the sent messages
        :return:
        """
        ids = [t.pk for t in cls.objects.filter(userthread__user=user, userthread__deleted=False)
               if t.is_user_first_message(user)]
        return cls.objects.filter(userthread__user=user, userthread__deleted=False, pk__in=ids)

Sent box with thread start

@classmethod
def sent(cls, user):
    """
    Returns the sent message folder
    :param user: User to check the sent messages
    :return:
    """
    return cls.objects.filter(threads_started__user=user, userthread__deleted=False)