Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. All message created time processing now takes place in the front-end. The backend only sends time in format "May 24 2019 13:00:00 UTC". 2. UI improvements: select2 is themed a little better using flex, The latest message appears in chat preview. The times displayed when the user clicks on a message are now more intuitive i.e. if the message had been sent in the past week, only the weekday name and time appears, if it's sent today, only time appears, etc. Functions are added to filter out strings that are present in multiple spots in the WebSocket for better readability. 3. Messages are now automatically ordered from last to first in the model level.
- Loading branch information
1 parent
ce30439
commit caab5a3
Showing
14 changed files
with
273 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.0.9 on 2019-05-25 03:08 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_chatter', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='message', | ||
options={'ordering': ['-id']}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.0.9 on 2019-05-25 03:15 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_chatter', '0002_auto_20190524_2308'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='message', | ||
options={}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
dateFormatter: str -> str | ||
This function takes in a time in the format ex. "24 May 2019 00:00:00 UTC" | ||
and returns a string that is one of the following: | ||
str ::= | 12:00 am | ||
| <Weekday> 12:00 am | ||
| <Month> <Day>, <Year> 12:00AM if time - timeNow > 7 days | ||
*/ | ||
|
||
function dateFormatter (string) { | ||
inputTime = new Date(Date.parse(string)); | ||
timeNow = new Date(Date.now()); | ||
difference = convertMS(timeNow - inputTime); | ||
var options = {}; | ||
if (difference["days"] > 7) { | ||
// days > 7 | ||
options = { | ||
month: "short", | ||
day: "numeric", | ||
year: "numeric", | ||
hour: "numeric", | ||
minute: "numeric", | ||
hour12: true | ||
}; | ||
return inputTime.toLocaleDateString('en-US', options); | ||
} | ||
else { | ||
if (sameDay(inputTime, timeNow)) { | ||
// "same day" | ||
options = { | ||
hour: "numeric", | ||
minute: "numeric", | ||
hour12: true | ||
}; | ||
return inputTime.toLocaleTimeString('en-US', options); | ||
} | ||
else { | ||
// "0 < days < 7" | ||
options = { | ||
weekday: "short", | ||
hour: "numeric", | ||
minute: "numeric", | ||
hour12: true | ||
} | ||
return inputTime.toLocaleTimeString('en-US', options); | ||
} | ||
} | ||
} | ||
|
||
|
||
//Converts milliseconds to days, hours, minutes and seconds and returns a dict. | ||
function convertMS(ms) { | ||
var d, h, m, s; | ||
s = Math.floor(ms / 1000); | ||
m = Math.floor(s / 60); | ||
s = s % 60; | ||
h = Math.floor(m / 60); | ||
m = m % 60; | ||
d = Math.floor(h / 24); | ||
h = h % 24; | ||
return { days: d, hours: h, minutes: m, seconds: s }; | ||
}; | ||
|
||
// Taken from https://stackoverflow.com/questions/43855166/how-to-tell-if-two-dates-are-in-the-same-day | ||
function sameDay(d1, d2) { | ||
return d1.getFullYear() === d2.getFullYear() && | ||
d1.getMonth() === d2.getMonth() && | ||
d1.getDate() === d2.getDate(); | ||
} |
Oops, something went wrong.