From 0bf87ae4b481457b38e11005e9a7d18d7fab5af5 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 5 Apr 2017 19:06:51 +0000 Subject: [PATCH] Parsing message timestamps, so they look cleaner --- titanembeds/static/js/embed.js | 13 +++++++++++-- titanembeds/templates/embed.html.j2 | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/titanembeds/static/js/embed.js b/titanembeds/static/js/embed.js index 0bf036f..0463d05 100644 --- a/titanembeds/static/js/embed.js +++ b/titanembeds/static/js/embed.js @@ -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; } diff --git a/titanembeds/templates/embed.html.j2 b/titanembeds/templates/embed.html.j2 index b8e4344..45d0e74 100644 --- a/titanembeds/templates/embed.html.j2 +++ b/titanembeds/templates/embed.html.j2 @@ -96,6 +96,7 @@ + {% raw %}