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:
@@ -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
|
||||
Reference in New Issue
Block a user