# Path: della/inbox/forms.py
# class MessageCreateForm(ModelForm):
# 
#     class Meta:
#         model = Message
#         fields = ['text']
# 
# Path: della/inbox/models.py
# class Message(TimeStampMixin):
#     text = models.TextField()
# 
#     sent_by = models.ForeignKey(User, on_delete=models.CASCADE)
#     thread = models.ForeignKey(Thread, on_delete=models.CASCADE,  related_name='messages')
# 
# class Thread(TimeStampMixin):
#     """
#     `is_sneaky` flag will be used when the message thread is between santa and
#     santee. If `is_sneaky` is set to `True` then `santa` shouldn't be null.
# 
#     `participant_1.id` will be always less than `participant_2.id`
#     """
#     is_sneaky = models.BooleanField(default=False)
# 
#     participant_1 = models.ForeignKey(
#         User, on_delete=models.CASCADE,  related_name='participant_1_threads')
#     participant_2 = models.ForeignKey(
#         User, on_delete=models.CASCADE,  related_name='participant_2_threads')
#     santa = models.ForeignKey(User, on_delete=models.CASCADE,  null=True, related_name='santa_threads')


from django.views.generic.edit import CreateView
from django.views.generic import DetailView, ListView
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.shortcuts import reverse, get_object_or_404
from django.db.models import Q, Max
from django.http import Http404, JsonResponse
from django.contrib.auth.models import User
from django.utils.formats import date_format
from .forms import MessageCreateForm
from .models import Message, Thread
from . import inbox_service
from . import tasks
        object_list = []
        sneaky_list = []
        for obj in context['object_list']:
            try:
                obj.latest_message = obj.messages.latest('created_on')
            except Message.DoesNotExist:
                continue
            if obj.is_sneaky:
                sneaky_list.append(self._get_sneaky_context(thread=obj))
            else:
                obj.recipient = inbox_service.get_recipient(
                    thread=obj, sender=sender)
                object_list.append(obj)
        context['object_list'] = object_list
        context['sneaky_list'] = sneaky_list
        return context

    def _get_sneaky_context(self, thread):
        if thread.santa == self.request.user:
            thread.title = 'Santee Messages'
            thread.url = reverse('inbox:santee-detail')
        else:
            thread.title = 'Santa Messages'
            thread.url = reverse('inbox:santa-detail')
        return thread


@method_decorator(login_required, name='dispatch')
class BaseThreadDetailView(DetailView):
    model = Thread

# Path: della/inbox/forms.py
# class MessageCreateForm(ModelForm):
# 
#     class Meta:
#         model = Message
#         fields = ['text']
# 
# Path: della/inbox/models.py
# class Message(TimeStampMixin):
#     text = models.TextField()
# 
#     sent_by = models.ForeignKey(User, on_delete=models.CASCADE)
#     thread = models.ForeignKey(Thread, on_delete=models.CASCADE,  related_name='messages')
# 
# class Thread(TimeStampMixin):
#     """
#     `is_sneaky` flag will be used when the message thread is between santa and
#     santee. If `is_sneaky` is set to `True` then `santa` shouldn't be null.
# 
#     `participant_1.id` will be always less than `participant_2.id`
#     """
#     is_sneaky = models.BooleanField(default=False)
# 
#     participant_1 = models.ForeignKey(
#         User, on_delete=models.CASCADE,  related_name='participant_1_threads')
#     participant_2 = models.ForeignKey(
#         User, on_delete=models.CASCADE,  related_name='participant_2_threads')
#     santa = models.ForeignKey(User, on_delete=models.CASCADE,  null=True, related_name='santa_threads')


# Path: della/inbox/views.py
from django.views.generic.edit import CreateView
from django.views.generic import DetailView, ListView
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.shortcuts import reverse, get_object_or_404
from django.db.models import Q, Max
from django.http import Http404, JsonResponse
from django.contrib.auth.models import User
from django.utils.formats import date_format
from .forms import MessageCreateForm
from .models import Message, Thread
from . import inbox_service
from . import tasks

        object_list = []
        sneaky_list = []
        for obj in context['object_list']:
            try:
                obj.latest_message = obj.messages.latest('created_on')
            except Message.DoesNotExist:
                continue
            if obj.is_sneaky:
                sneaky_list.append(self._get_sneaky_context(thread=obj))
            else:
                obj.recipient = inbox_service.get_recipient(
                    thread=obj, sender=sender)
                object_list.append(obj)
        context['object_list'] = object_list
        context['sneaky_list'] = sneaky_list
        return context

    def _get_sneaky_context(self, thread):
        if thread.santa == self.request.user:
            thread.title = 'Santee Messages'
            thread.url = reverse('inbox:santee-detail')
        else:
            thread.title = 'Santa Messages'
            thread.url = reverse('inbox:santa-detail')
        return thread


@method_decorator(login_required, name='dispatch')
class BaseThreadDetailView(DetailView):
    model = Thread

    form_class = MessageCreateForm