Parsing message timestamps, so they look cleaner

This commit is contained in:
Jeremy Zhang 2017-04-05 19:06:51 +00:00
parent 13e9649c10
commit 0bf87ae4b4
2 changed files with 12 additions and 2 deletions

View File

@ -3,6 +3,7 @@
/* global Mustache */
/* global guild_id */
/* global bot_client_id */
/* global moment */
var logintimer; // timer to keep track of user inactivity after hitting login
var fetchtimeout; // fetch routine timer
@ -235,7 +236,14 @@ function format_bot_message(message) {
message.author.username = usernamefield.split("#")[0];
message.author.discriminator = usernamefield.split("#")[1];
}
return message
return message;
}
function parse_message_time(message) {
var mome = moment(message.timestamp);
message.formatted_timestamp = mome.toDate().toString();
message.formatted_time = mome.format("HH:mm A");
return message;
}
function fill_discord_messages(messages, jumpscroll) {
@ -249,7 +257,8 @@ function fill_discord_messages(messages, jumpscroll) {
var message = messages[i];
message = replace_message_mentions(message);
message = format_bot_message(message);
var rendered = Mustache.render(template, {"id": message.id, "full_timestamp": message.timestamp, "time": message.timestamp, "username": message.author.username, "discriminator": message.author.discriminator, "content": message.content});
message = parse_message_time(message);
var rendered = Mustache.render(template, {"id": message.id, "full_timestamp": message.formatted_timestamp, "time": message.formatted_time, "username": message.author.username, "discriminator": message.author.discriminator, "content": message.content});
$("#chatcontent").append(rendered);
last = message.id;
}

View File

@ -96,6 +96,7 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.1/js/materialize.min.js" integrity="sha256-ToPQhpo/E89yaCd7+V8LUCjobNRkjilRXfho6x3twLU=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.3.0/mustache.min.js" integrity="sha256-iaqfO5ue0VbSGcEiQn+OeXxnxAMK2+QgHXIDA5bWtGI=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js" integrity="sha256-1hjUhpc44NwiNg8OwMu2QzJXhD8kcj+sJA3aCQZoUjg=" crossorigin="anonymous"></script>
{% raw %}
<script id="mustache_channellistings" type="text/template">