Add chat models and scaffold pages/posts apps

Implemented comprehensive models for chat functionality, including Chat, Message, MessageHistory, MessageReaction, and MessageFile. Updated ChatConsumer to enforce authentication and improve message handling. Added initial scaffolding for 'pages' and 'posts' Django apps with basic files.
This commit is contained in:
2025-12-26 04:48:39 +01:00
parent 00271e59e4
commit deb853b564
16 changed files with 232 additions and 6 deletions

View File

@@ -9,19 +9,34 @@ from channels.generic.websocket import AsyncWebsocketConsumer
class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
user = self.scope["user"]
if not user.is_authenticated:
await self.close(code=4401) # unauthorized
return
await self.accept()
async def disconnect(self, close_code):
self.disconnect()
pass
async def receive(self, text_data):
text_data_json = json.loads(text_data)
message = text_data_json["message"]
async def receive(self, data):
if data["type"] == "chat_message":
pass
else:
self.close(reason="Unsupported message type")
# -- CUSTOM METHODS --
async def send_message_to_chat_group(self, event):
message = event["message"]
await create_new_message()
await self.send(text_data=json.dumps({"message": message}))
@database_sync_to_async
def get_user_profile(user_id):
return UserProfile.objects.get(pk=user_id)
def create_new_message(user_id):
return None