Improve chat replies, hubs API & UI
Backend: enrich message reply data (include created_at and media_files) and ensure chat owners are treated as members; tighten/extend permission checks and message query filters; fix hub routers so moderators/tags routes are resolved before hub detail; accept hub id from request.data in hub permission/tag views; add PostHub serializer and expose hub_detail on posts. Frontend: update generated API models (postHub, replyTo, members_detail, hub_detail); add hub-related pages/routes and components (HubCard, HubHeader, Tags) and a hub posts feed hook; rework message UI and composer to show richer reply previews (media thumbnails, timestamps), adjust video preload to metadata; add tag selection UI to PostComposer and wire hub tags fetching. Also: minor UI/UX improvements and generated model exports updated to match backend changes.
This commit is contained in:
@@ -54,6 +54,10 @@ class ChatViewSet(viewsets.ModelViewSet):
|
||||
|
||||
def perform_create(self, serializer):
|
||||
chat = serializer.save(owner=self.request.user)
|
||||
|
||||
# Ensure the creator is always a member so they pass membership checks.
|
||||
chat.members.add(self.request.user)
|
||||
|
||||
if chat.chat_type == Chat.ChatType.DM:
|
||||
other = chat.members.exclude(pk=self.request.user.pk).first()
|
||||
if other:
|
||||
@@ -192,8 +196,7 @@ class MessageViewSet(viewsets.ModelViewSet):
|
||||
qs = Message.objects.select_related('sender', 'chat').prefetch_related('media_files', 'reactions')
|
||||
if user.is_superuser:
|
||||
return qs
|
||||
# Only messages from chats the user is a member of
|
||||
return qs.filter(chat__members=user)
|
||||
return qs.filter(Q(chat__members=user) | Q(chat__owner=user)).distinct()
|
||||
|
||||
def perform_update(self, serializer):
|
||||
message = serializer.instance
|
||||
@@ -233,7 +236,7 @@ class MessageViewSet(viewsets.ModelViewSet):
|
||||
ser.is_valid(raise_exception=True)
|
||||
|
||||
chat = ser.validated_data['chat']
|
||||
if not request.user.is_superuser and not chat.members.filter(pk=request.user.pk).exists():
|
||||
if not request.user.is_superuser and not chat.members.filter(pk=request.user.pk).exists() and chat.owner != request.user:
|
||||
raise PermissionDenied('You are not a member of this chat.')
|
||||
|
||||
message = Message.objects.create(
|
||||
|
||||
Reference in New Issue
Block a user