Opinionated Django Chat
Project description
django-df-chat
Development
Installing dev requirements:
pip install -e .[test]
Installing pre-commit hook:
pre-commit install
Running tests:
pytest
New Design
Model Data
ChatRoom
- name = str
- description = str
- avatar = ImageField
- type = Enum: 'private_messages', 'group', 'channel'
- is_public = BooleanField(default=False) # does appear in search results; can be joined by anyone
RoomUser
- room = ForeignKey(ChatRoom)
- user = ForeignKey(settings.CHAT_USER_MODEL)
- muted = BooleanField(default=False)
- created_by = ForeignKey(ChatUser)
- last_seen_at = DateTimeField() # To show how many messages are unread
Somehow we need to manage perms per room:
- can_add_users
- can_remove_users
- can_create_messages
- can_delete_messages
- can_delete_own_messages
- can_edit_messages
- can_edit_own_messages
- can_edit_room
- can_delete_room
It could be JSONField with list of permissions. Or separate RoomUserPermission model (room_user fk + permission Enum).
ChatMessage
- room = ForeignKey(ChatRoom)
- user = ForeignKey(settings.CHAT_USER_MODEL)
- text = TextField()
ChatMessageMedia
- message = ForeignKey(ChatMessage)
- chat_media = ForeignKey(ChatMedia)
- sequence = IntegerField()
ChatMedia
- media = FileField
ChatMessageReaction
- message = ForeignKey(ChatMessage)
- user = ForeignKey(settings.CHAT_USER_MODEL)
- reaction = CharField(max_length=255) -- Constrained in settings: only
like/dislike
oremoji
or custom text.
API:
- chat_room:
- list
- create
- retrieve
- room_user:
- list
- create
- retrieve
- update
- delete
- chat_message:
- list
- create
- retrieve
- update
- delete
- chat_media:
- create
- retrieve
- chat_message_reactions:
- list (for specific message only or for myself)
- create
- retrieve
- delete
Use cases:
- Private messages: room with 2 users. Nobody can add other users to the room. Both can delete the room.
- Group: room where everybody can create a message. Everybody can add other users to the room. Only is_owner can delete the room.
- Channel: room where only
admin
can create a message. Everybody can add other users to the room. Only is_owner can delete the room.
Flows:
- Send picture to a room:
- Create chat_media, retrieve media_id
- Create chat_message with media_id
- Create a chat on 3 people:
- Create new room type=group
- Create room_user for each user
- Create chat_message with text="User X created a chat" and room_id
- Create a news channel:
- Create new room type=channel
- Add User to the room with can_add_users=True, can_write_messages=True (and other perms). So user can post news to the channel.
- Add create other room_users without perms. So they can read the channel.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-df-chat-0.1.0.tar.gz
(12.1 kB
view hashes)
Built Distribution
Close
Hashes for django_df_chat-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c223b47b8e208fb2f807ca5e3861ef45934e8bff7dbbba133d6945691800e3f8 |
|
MD5 | 41aae97d907fdb8d418c87126789e65e |
|
BLAKE2b-256 | 2a2a19ae0431c3724d58ab531c86db1395c61f5b80e593d425831febc28ae164 |