from osinacore.api.utils import *
from osichat.models import *
from rest_framework.decorators import api_view
from .serializers import *


@api_view(['GET'])    
def get_chat_rooms(request):
    chat_rooms = ChatRoom.objects.annotate(last_update=Max('chatmessage__date_sent')).order_by('-last_update', '-date_created')
    chat_rooms_serializer = ChatRoomSerializer(chat_rooms, many=True)
    return successRes(chat_rooms_serializer.data)
    