Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added A Django Optimised Chat Sample #434

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,723 changes: 1,881 additions & 1,842 deletions samples/angular-chat/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions samples/angular-chat/src/app/QBconfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const QBconfig = {
credentials: {
appId: '',
authKey: '',
authSecret: '',
accountKey: ''
appId: 'YOUR_APP_ID',
authKey: 'YOUR_AUTH_KEY',
authSecret: 'DcFckTJd-hk',
accountKey: 'Ks9sNV-F11T6Z3g'
},
appConfig: {
chatProtocol: {
10 changes: 5 additions & 5 deletions samples/chat/js/QBconfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var QBconfig = {
credentials: {
appId: '',
authKey: '',
authSecret: '',
accountKey: ''
},
appId: 'YOUR_APP_ID',
authKey: 'Ad6zC2V5W7',
authSecret: 'DcFckTJd-hk',
accountKey: 'KsNV-F11T6Z3g'
},
appConfig: {
chatProtocol: {
active: 2
4 changes: 4 additions & 0 deletions samples/django-chat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
djangovenv*
static
*__pycache__*
*.pyc
78 changes: 78 additions & 0 deletions samples/django-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Overview
QuickBlox JS-Django Sample Chat

# Running the Django App
1. Install Python 3.8+ and Django 3.1.7 +
2. Activate a virtual environment. You may need to install some additional packages if you are on Linux.
Run the command `python -m venv <my-env>` and hit enter. You may need to use `python3` on Unix. Please note that `<my-env>` can be a name of choice, but use something descriptive, like `djangovenv`.
Then after run the command `<my-venv>\Scripts\activate` on Windows or `source <my-env>/bin/activate` on Unix.
3. Install the requirements by running `pip install -r requirements.txt`
4. Run the server by running `python manage.py runserver` in an active virtual environment.
5. Collect static files by running `python manage.py collectstatic`
6. Open the browser and go to `http://localhost:8000/` to see the app running.
NOTE: You do not need to perform any database migrations as this app does not use the django ORM and Database. But this is a future enhancement.
-----
This is a code sample for [QuickBlox](http://quickblox.com/) platform. It is a great way for developers using QuickBlox platform to learn how to integrate private and group chat, add text and image attachments sending into your application.

# Features
* Log in/log out
* Send and receive message/attachment
* Create and leave a 1-to-1 and group chat
* Create a public chat
* Display users who have received/read the message
* Mark messages as read/delivered
* Send typing indicators
* List and delete chats
* Display chat history
* Display a list with chat participants
* Optimised for Django [Still in Development]
# Get application credentials
[](#get-application-credentials)

QuickBlox application includes everything that brings messaging right
into your application - chat, video calling, users, push notifications,
etc. To create a QuickBlox application, follow the steps below:

1. Register a new account following [this
link](https://admin.quickblox.com/signup). Type in your email and
password to sign in. You can also sign in with your Google or Github
accounts.
2. Create the app clicking **New app** button.
3. Configure the app. Type in the information about your organization
into corresponding fields and click **Add** button.
4. Go to **Dashboard =\> *YOUR\_APP* =\> Overview** section and copy
your **Application ID**, **Authorization Key**, **Authorization
Secret**, and **Account Key**.

# Run chat sample

To run a code sample, follow the steps below:

1. Download the code sample.
2. [Get application credentials](#get-application-credentials) and get appId, authKey, authSecret, and accountKey.
3. Put these values in file **QBconfig.js** following **samples =\>
chat =\> js** directory.

JavaScript

var QBconfig = {
credentials: {
appId: '',
authKey: '',
authSecret: '',
accountKey: ''
}
}

4. Run the code sample by opening **index.html** file.

# Requirements
[](#requirements)

The minimum requirements for QuickBlox JavaScript SDK are:

- JavaScript es5.

# Documentation

Sample documentation is available [here](https://quickblox.com/developers/Web_XMPP_Chat_Sample#Guide:_Getting_Started_with_Chat_API).
Empty file added samples/django-chat/db.sqlite3
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions samples/django-chat/dj_quickblox/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for dj_quickblox project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj_quickblox.settings')

application = get_asgi_application()
128 changes: 128 additions & 0 deletions samples/django-chat/dj_quickblox/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
Django settings for dj_quickblox project.

Generated by 'django-admin startproject' using Django 4.1.2.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-=y)3p$j(0q61$=glavewd--t_utb@mml2o-l$55g3g+65g#a++'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'index'
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'dj_quickblox.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'dj_quickblox.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
22 changes: 22 additions & 0 deletions samples/django-chat/dj_quickblox/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""dj_quickblox URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('index.urls')),
]
16 changes: 16 additions & 0 deletions samples/django-chat/dj_quickblox/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for dj_quickblox project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj_quickblox.settings')

application = get_wsgi_application()
Empty file.
3 changes: 3 additions & 0 deletions samples/django-chat/index/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions samples/django-chat/index/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class IndexConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'index'
Empty file.
3 changes: 3 additions & 0 deletions samples/django-chat/index/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Loading
Oops, something went wrong.