Skip to content

Commit

Permalink
Merge pull request #23 from dibs-devs/ahmed
Browse files Browse the repository at this point in the history
Various Changes
  • Loading branch information
dibs-devs committed May 12, 2019
2 parents 38da1e3 + dc60b10 commit a777f4d
Show file tree
Hide file tree
Showing 18 changed files with 389 additions and 252 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -7,9 +7,6 @@ __pycache__/
# ignore database file
*.sqlite3

# ignore migrations folders
migrations/

# ignore redis database file
*.rdb

Expand Down
2 changes: 2 additions & 0 deletions chatter/settings.py
Expand Up @@ -142,3 +142,5 @@

#
LOGIN_REDIRECT_URL = '/'

# CHATTER_BASE_TEMPLATE="sample.html"
41 changes: 23 additions & 18 deletions django_chatter/consumers.py
Expand Up @@ -52,35 +52,40 @@ def save_message(room, sender, text, multitenant=False, schema_name=None):
with schema_context(schema_name):
new_message = Message(room=room, sender=sender, text=text)
new_message.save()
new_message.recipients.add(sender)
new_message.save()
room.date_modified = new_message.date_modified
room.save()
else:
new_message = Message(room=room, sender=sender, text=text)
new_message.save()
new_message.recipients.add(sender)
new_message.save()
room.date_modified = new_message.date_modified
room.save()


class ChatConsumer(AsyncWebsocketConsumer):

@database_sync_to_async
def save_message(self, room, user, message):
'''
AI-------------------------------------------------------------------
1. Select the Room
2. Select the user who sent the message
3. Select the message to be saved
4. Save message
5. Set room update time to message date_modified
-------------------------------------------------------------------AI
'''
room = room
sender = user
text = message
new_message = Message(room=room, sender=sender, text=text)
new_message.save()
room.date_modified = new_message.date_modified
room.save()
# @database_sync_to_async
# def save_message(self, room, user, message):
# '''
# AI-------------------------------------------------------------------
# 1. Select the Room
# 2. Select the user who sent the message
# 3. Select the message to be saved
# 4. Save message
# 5. Set room update time to message date_modified
# -------------------------------------------------------------------AI
# '''
# print ("I'm the wrong one who's getting executed")
# room = room
# sender = user
# text = message
# new_message = Message(room=room, sender=sender, text=text)
# new_message.save()
# room.date_modified = new_message.date_modified
# room.save()

'''
AI-------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions django_chatter/context_processors.py
Expand Up @@ -6,12 +6,11 @@ def get_chatroom_list(request):
# Get the list of rooms the user is in, from latest to earliest
rooms_list = Room.objects.filter(members=request.user).order_by('-date_modified')
rooms_with_unread = []
# Go through each list of rooms and check if any of the latest 50 messages
# was unread
# Go through each list of rooms and check if the last message was unread
for room in rooms_list:
message = room.message_set.all().order_by('-id')[0]
if request.user not in message.recipients.all():
rooms_with_unread.append(room.id)
rooms_with_unread.append(room.id)]

#unread rooms are marked with bold letterings
return ({'rooms_list': rooms_list, 'rooms_with_unread': rooms_with_unread})
Expand Down
61 changes: 61 additions & 0 deletions django_chatter/migrations/0001_initial.py
@@ -0,0 +1,61 @@
# Generated by Django 2.0.9 on 2019-05-04 09:42

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_created', models.DateTimeField(auto_now_add=True)),
('date_modified', models.DateTimeField(auto_now=True)),
('text', models.TextField()),
('recipients', models.ManyToManyField(related_name='recipients', to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Room',
fields=[
('date_created', models.DateTimeField(auto_now_add=True)),
('date_modified', models.DateTimeField(auto_now=True)),
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('members', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('last_visit', models.DateTimeField()),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='message',
name='room',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_chatter.Room'),
),
migrations.AddField(
model_name='message',
name='sender',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sender', to=settings.AUTH_USER_MODEL),
),
]
Empty file.
19 changes: 1 addition & 18 deletions django_chatter/static/css/base.css
Expand Up @@ -8,12 +8,7 @@ AI-------------------------------------------------------------------
AI-------------------------------------------------------------------
Body styles applied to the whole body.
-------------------------------------------------------------------AI
*//*
body {
padding: 40px 20px 0px 20px;
position: relative;
font-family: 'Raleway', sans-serif;
}*/
*/

input {
height: 2rem;
Expand All @@ -24,20 +19,8 @@ AI-------------------------------------------------------------------
Logout link on the top right
-------------------------------------------------------------------AI
*/
/*.float {
position: absolute;
padding: inherit;
right: 0px;
top: 0px;
}*/

.float {
display: block;
text-align: right;
}

@media only screen and (max-width: 768px) {
.chatroom-list {
display: none;
}
}
164 changes: 102 additions & 62 deletions django_chatter/static/css/chat-window.css
Expand Up @@ -4,24 +4,103 @@ AI-------------------------------------------------------------------
-------------------------------------------------------------------AI
*/

:root {
--main-bg-color: #08d18e;
}

/*Chatter's container. Contains chatroom-list and chat-dialog*/
.app-container {
height: 100%;
max-height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}

/*Container of chat box. Includes the dialog and input field and button*/
.chat-container {
display: inline-block;
vertical-align: top;
height: 80vh;
width: 90%;
padding: 0;
width: 100%;
max-width: 1200px;
max-height: 100%;
display: flex;
flex-direction: row;
}

.chat-subsection {
display: flex;
flex-direction: column;
border: 2px solid var(--main-bg-color);
border-radius: 2px;
box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.2);
}

.chatroom-list-container {
flex-grow: 1;
border-right: 0;
}

.dialog-container {
flex-grow: 3;
}

#room-title {
height: 40px;
align-items: center;
justify-content: center;
display: flex;
height: 40px;
border-bottom: 2px solid var(--main-bg-color);
}

/*This is the setting for the chat history dialog.*/
#chat-dialog {
margin: 0 auto;
width: 100%;
height: 90%;
border: 2px solid #35b88f;
border-radius: 5px;
background-color: white;
overflow: auto;
height: 96%;
}

/*
AI-------------------------------------------------------------------
The following contains settings for the input field and button.
-------------------------------------------------------------------AI
*/
.input-container {
padding-top: 2px;
padding-bottom: 2px;
display: flex;
justify-content: center;
border-top: 2px solid var(--main-bg-color);
height: 40px;
}

/*This is the text box where the user inputs the messages to send.
It's a textarea element to enable scroll.*/
#send-message {
width: calc(100% - 50px);
height: 100%;
font-size: 1rem;
overflow: auto;
resize: none;
border: none;
font-family: 'Raleway', sans-serif;
padding: 0 10px;
}

/*Send button's parent*/
#send-btn-parent {
width: 50px;
display:flex;
justify-content: center;
align-items: center;
}
/*Send button settings*/
#send-button {
background: transparent;
font-weight: bold;
font-size: 1rem;
color: var(--main-bg-color);
border: none;
width: 50px;
}

/*
Expand All @@ -43,7 +122,7 @@ AI-------------------------------------------------------------------

/*Messages sent by current user has these settings.*/
.message-sent {
background: #35b88f;
background: var(--main-bg-color);
color: white;
float: right;
}
Expand All @@ -63,69 +142,30 @@ AI-------------------------------------------------------------------
float: left;
}

/*
AI-------------------------------------------------------------------
The following contains settings for the input field and button.
-------------------------------------------------------------------AI
*/
.input-container {
margin: 0 auto;
margin-top: 5px;
text-align: center;
position: relative;
border: 2px solid #35b88f;
border-radius: 5px;
}

/*This is the text box where the user inputs the messages to send.
It's a textarea element to enable scroll.*/
#send-message {
width: calc(100% - 4em);
font-size: 1rem;
padding-left: 10px;
overflow: auto;
resize: none;
display: inline;
border: none;
margin-top: 5px;
font-family: 'Raleway', sans-serif;
}

/*Send button settings*/
#send-button {
background: transparent;
font-weight: bold;
font-size: 1rem;
color: #35b88f;
border: none;
display: inline;
vertical-align: top;
padding-top: 5px;
}

.fa-arrow-left {
float: left;
padding-top: 0.2em;
padding-bottom: 0.2em;
color: #35b88f;
color: var(--main-bg-color);
}

@media only screen and (max-width: 768px) {
@media only screen and (max-width: 767px) {
body {
text-align: center;
}
.chat-container {
max-width: 90%;
}
}

@media only screen and (min-width: 769px) {
@media only screen and (min-width: 768px) {
.fa-arrow-left {
display: none;
}
.chat-container {
width: 70%;
display: inline-block;
height: 80vh;
min-width: 768px;
}
}
}

@media only screen and (max-width: 576px) {
.chatroom-list-container {
display: none;
}
}

0 comments on commit a777f4d

Please sign in to comment.