def get_dump_object(self, obj): dump_object = {} dump_object.update({'msg_type': MSG_TYPE_MESSAGE}) dump_object.update({'user_id': str(obj.user.id)}) dump_object.update({'msg_id': str(obj.id)}) dump_object.update({'username': str(obj.user.username)}) dump_object.update({'message': str(obj.content)}) dump_object.update({'profile_image': str(obj.user.profile_image.url)}) dump_object.update({'natural_timestamp': calculate_timestamp(obj.timestamp)}) return dump_object
async def chat_message(self, event): """ Called when someone has messaged our chat. """ # Send a message down to the client print("PublicChatConsumer: chat_message from user #" + str(event["user_id"])) timestamp = calculate_timestamp(timezone.now()) await self.send_json( { "msg_type": MSG_TYPE_MESSAGE, "profile_image": event["profile_image"], "username": event["username"], "user_id": event["user_id"], "message": event["message"], "natural_timestamp": timestamp, }, )