Skip to main content

A Django one to one chat application

Project description

realchat

MIT License

Features

  • One to one chat
  • message encrypted before entering database
  • Less hassle

realchat is a Django app to conduct web-based chat.

Detailed documentation is in the "docs" directory.

Quick start

  1. Add to your settings.py

    INSTALLED_APPS

       ```
            INSTALLED_APPS = [
                 'chat',
            ]
       ```
    

    To use the chat app, add it to your INSTALLED_APPS

    Auth_USER_MODEL

       ```
            AUTH_USER_MODEL = 'app.User' # it can be whatever user model you create
       ```
    

    The auth user model will communicate with the chat app and provide the user's name, email and auth status.

    LOGIN_URL

       ```
            LOGIN_URL = '/login/' # it can be whatever login url you create
       ```
    

    The login url provide url redirect from the chat view classes if the user is not logged in.

  2. Include the chat URLconf in your project urls.py like this

       ```
            path('chat/', include('chat.urls')),
       ```
    
  3. Templating
    The chat app views return the following context variables:

MessageListView

context

 ```
 "inbox": # returns a dictionary of users you have chats with, 
           # and the latest message between you both
           # also including the time and unread message count
 ```

usage (django html)

 ```
      # use a for loop
      {% for key, item in inbox.items %}
           {{ key }} # to get the user you're chatting with 
           {{ item.message }} # to get the latest message between you two
           {{ item.date }} # the date the lastest message was sent
           {{ item.count }} # to get the unread messages count

           # to give access the inbox of the user, make each item template 
           # of the loop clickable and the url should be:
           {% url 'chat:inbox' key %}
      {% endfor %}
      # the url for messagelistview is:
      {% chat:message_list %}

 ```

InboxView

context

 ```
      "messages":     # returns all messages between you and the other user
      "other_person": # returns the user object of the person you're 
                     # chatting with
      "inbox":         # does the same as in the message list view, 
                     # it is passed to make sidepanel work like whatsapp web
      "you": #         # your user object is passed also 
 ```

usage (django html)

 ```
      # use a for loop
      {{ other_person.username }} # will get the username to display
      {% for message in messages%}
           # you can seperate user message and other user messages by
           # comparing the message sender and recipient objects
           # i.e
           {% if message.sender == other_person %}
           {{ message.message }}
           {{ message.date }}
           {% else %}
           # this will return messages that are not sent from the other_person
           {{ message.message }}
           {{ message.date }}
           {% endif %} 

      # finally, when sending messages to a user, create the following 
      # input tags in your from
           # hidden
           <input type="hidden" name="recipient" value="{{ other_person.pk }}">
           <input type="hidden" name="you" value="{{ you.pk }}">
      # get the message
      <input type=text name="message" placeholder="...">

      # the action of the form should be:
      {% url 'chat:inbox' other_person.username %}

      {% endfor %}

      # to use the inbox context,
      # extend the messaelist template
 ```

UserListView

context

 ```
      # usser list view has one context
      "users": # returns all users excluding the user logged in
 ```

usage

 ```
      # use a for loop and style your template however
 ```

4.Run python manage.py migrate to create the chat models.

5.Visit http://127.0.0.1:8000/chat/ to participate in the to see a messages.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

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

realchat-1.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

realchat-1.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file realchat-1.2.tar.gz.

File metadata

  • Download URL: realchat-1.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for realchat-1.2.tar.gz
Algorithm Hash digest
SHA256 7beee3a0dc6cc5f3ef576c61466f350b4099b58a17328441d78e756e850abf16
MD5 71a3d90dc6845e84e88485d85bf40684
BLAKE2b-256 deb12edf9084360022e7903935b73748e593192fab3de72e58054e8fe7b011d3

See more details on using hashes here.

File details

Details for the file realchat-1.2-py3-none-any.whl.

File metadata

  • Download URL: realchat-1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for realchat-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87a56d7f8b933501fe5a62cdd6841256a6bcb67bd7a4dc440086d6dbf3b4e550
MD5 c0bc1f0ab216b2c81079af6b155d8d7d
BLAKE2b-256 89eea7af7cc495196b3c5d3d2a72cf8dc58152219b7066853d95d49f590e0172

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page