Giter VIP home page Giter VIP logo

django-df-chat's Introduction

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

  • title = CharField()
  • users = ManyToManyField(through="ChatMember")
  • chat_type = Enum: 'private', 'group',

ChatMember

  • is_owner = BooleanField(default=False)
  • is_admin = BooleanField(default=False)
  • user = ForeignKey(ChatUser)
  • chat_room = ForeignKey(ChatRoom)

MemberChannel (service table)

  • last_alive_at = DateTimeField()
  • channel_name = CharField()
  • user = ForeignKey(ChatUser)

ChatMessage

  • created_by = ForeignKey(ChatUser)
  • chat_room = ForeignKey(ChatRoom)
  • message = TextField(settings.CHAT_USER_MODEL)

API:

[GET] /api/v1/chat/rooms/

[POST] /api/v1/chat/rooms/

[GET] /api/v1/chat/rooms/{id}/

[PUT] /api/v1/chat/rooms/{id}/

[PATCH] /api/v1/chat/rooms/{id}/

[DELETE] /api/v1/chat/rooms/{id}/

[POST] /api/v1/chat/rooms/{id}/member/

[GET] /api/v1/chat/rooms/{room_id}/messages/

[POST] /api/v1/chat/rooms/{room_id}/messages/

[GET] /api/v1/chat/rooms/{room_id}/messages/{id}/

[PUT] /api/v1/chat/rooms/{room_id}/messages/{id}/

[PATCH] /api/v1/chat/rooms/{room_id}/messages/{id}/

[DELETE] /api/v1/chat/rooms/{room_id}/messages/{id}/

Use cases:

  • Create chat room with specific type, and add user. Channel layer should be created if user are online and all online users should to receive messages
  • Private chat room (chat between 2 members). Nobody can add new members.
  • Group chat (chat between multiple users). Users could be added through API endpoint call
  • moderation part is missed at the moment

Flow:

  • User connected to WS
  • Channel layer stored to DB to use it in a future to dynamically subscribe user with a new chatRooms
  • on user disconnected channel layer should be removed from DB

django-df-chat's People

Contributors

eugapx avatar sreekanthreddybalne avatar mavenium avatar dokterbob avatar dependabot[bot] avatar yevhenii-apex avatar

Watchers

Alexis Yushin avatar

django-df-chat's Issues

Cleanup the README

A good FOSS project deserves a good README. ;)

I would suggest:

  • Getting rid of '...'
  • Fixing the Markdown/layout

readme

Message.seen_by & received_by missing in current version

Message.seen_by and .received_by fields available in previous chat version are missing from current implementation.

Refs #45 .

Pay attention to this message from the old code base:

    # TODO(alexis): consider through a model to record timestamps when the message is seen / sent to implement
    # whatsapp like double checkmarks

Message Reactions

We need to add reactions on messages like 👍, 👎, ❤️, etc.

  • Create a model schema for reactions
  • Add available reactions to library settings
  • Add API method to add/remove reaction for the message
  • Add live updates with message's reactions for websocket listeners.
  • Add reactions as nested field for Message API.

Add features from the v0 version

On previous chat version we had much more features like:

  • Mute/unmute room
  • Replies
  • Reactions, etc.

We reworked an architecture since then and dropped a lot of features.

The task is to research an old chat version, create full list of missing features (as separate GitHub tickets) and implement them.

As an example, I created a feature for reactions #44

We need to keep architecture clean and performant. All live chat changes for new features (reactions, replies, etc.) should be sent via websocket.

Room invitations

Implement a feature allowing room admins or the room creator to send invitations to users to join a private room.

Room categories

Add room categories to better organize the public rooms, and allow users to filter the room list based on these categories.

Incomplete APIs

Hi I am checking api methods and models on https://github.com/djangoflow/flutter-djangoflow/tree/main/packages/djangoflow_openapi

I see after the latest refactor few things went missing.

Critical ones:

  • Room id should be String instead of int . Currently in every API we use int type but for some reason GET /api/v1/chat/rooms/{id}/ uses String. But all should be String type.
  • No API get the users that are in a room(need it to display who sent which message, and which one user is me, previously there used to be RoomUser model that used to give information like id, name, avatar etc of the user)
  • GET /api/v1/chat/rooms/{room_id}/messages/ does not support limit , offset parameter passing for pagination

Less critical ones:

Message editing and deletion

Allow users to edit or delete their messages within a certain time frame after they’ve sent them. Include an indicator showing that a message has been edited.

Pinned messages

Give room admins the ability to pin important messages to the top of the chat for all users to see.

Suggestion: rename UserChat for verbosity

Docstring for UserChat reads: This model stores attributes that should be visible across all rooms for a user.

The current name is suggestive to something more akin to a chat session whereas, quite literally, it's chat-related attributes of a user. Given that the model is already namespaced to df_chat, I would suggest renaming to UserAttributes (and use import as in external contexts) or UserState (as that's how it's currently used).

I think a change like this will significantly increase comprehension of the code and data structures.

Remove the `users` field from the `Room` model

Since users are associated with rooms via the RoomUser through-model, having the users field on the Room model is unnecessary and redundant.

Changes made need to take into consideration the various uses of the users field on the Room model (if any).

Sugestion: A better way to implement requirements.txt files

Instead of pip installing an individual requirements.txt file it is better to make folder of with different requirements.txt file and and call them in one requirements.txt file. So that contributors/users can run a single pip install requirements.txt file.

Allow users to create messages via Websocket instead of HTTP

In the current approach, in order to create a message in a room, a user should make a HTTP POST request. And then the message is propagated to all the listeners in that room.

But, chatting is done in real-time. Users expect to send and receive messages real quick. An HTTP connection is not stateful and takes some time to connect. They disconnect immediately once the request is fulfilled.

On the other hand, a Websocket connection is stateful - the connection is live until either party terminates it.

So, we could communicate in real time by using Websockets instead of HTTP and should allow users to create messages via Websocket instead of HTTP.

Refactor WebSocket Implementation for Chat Rooms

  • Modify the WebSocket URL pattern to handle all chat rooms with a single WebSocket URL.
  • Update the WebSocket consumer to manage multiple rooms using the new URL pattern.
  • Ensure that the chat functionality continues to work correctly after the refactoring.

User profiles

Create user profiles with customizable avatars, display names, and a short bio. Users should be able to view each other’s profiles by clicking on their names in the chat interface.

Attributes missing on ChatRoom model from v0

The following fields available in previous chat version seem to be missing from current implementation.

  • creator - user which created the room
  • is_public - may be implemented via ChatType
  • image
  • description
  • muted_by
  • admins

Refs #45 .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.