77 lines
2.1 KiB
JavaScript
77 lines
2.1 KiB
JavaScript
|
messages = [
|
||
|
{
|
||
|
messageid: 98568,
|
||
|
timestamp: 1630000000000,
|
||
|
author: {
|
||
|
name: "Velecísař Empy",
|
||
|
id: 1,
|
||
|
},
|
||
|
content: "Test message 01",
|
||
|
},
|
||
|
{
|
||
|
messageid: 98868,
|
||
|
timestamp: 1640000000000,
|
||
|
author: {
|
||
|
name: "Velecísař Empy 2",
|
||
|
id: 2,
|
||
|
},
|
||
|
content: "Test message 02",
|
||
|
},
|
||
|
{
|
||
|
messageid: 96666,
|
||
|
timestamp: 1650000000000,
|
||
|
author: {
|
||
|
name: "Velecísař Empy",
|
||
|
id: 1,
|
||
|
},
|
||
|
content: "Test message 03\n\n\n\n\nPokračování\ntest\na\na\n\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n\na\na\na\na\na\na\na\na\na\n\na\na\na\na\na\na\na\na\na\n\na\na\na\na\na\na\na\na\na\n",
|
||
|
},
|
||
|
];
|
||
|
|
||
|
const messagesDescending = messages.sort((a, b) => a.timestamp - b.timestamp);
|
||
|
|
||
|
let htmlString = "";
|
||
|
|
||
|
const currentUser = {
|
||
|
name: "Velecísař Empy",
|
||
|
id: 1,
|
||
|
};
|
||
|
|
||
|
messagesDescending.forEach((obj) => {
|
||
|
var meAuthor = obj.author.id == currentUser.id;
|
||
|
var tempString = "";
|
||
|
if (meAuthor) {
|
||
|
tempString = '<div class="message left">';
|
||
|
} else {
|
||
|
tempString = '<div class="message right">';
|
||
|
}
|
||
|
|
||
|
tempString += "<div class=\"firstLine\">"
|
||
|
|
||
|
// console.log(event.toLocaleString('cs-CZ', { weekday: "long", year: "numeric", month:"long", day: "numeric", era: "long", hour: "numeric", minute: "numeric", second: "numeric"}));
|
||
|
const locale = "cs-CZ";
|
||
|
const options = {
|
||
|
weekday: "long",
|
||
|
year: "numeric",
|
||
|
month: "long",
|
||
|
day: "numeric",
|
||
|
hour: "numeric",
|
||
|
minute: "numeric",
|
||
|
second: "numeric",
|
||
|
era: "long"
|
||
|
};
|
||
|
|
||
|
|
||
|
tempString += `<p class=\"author\">${ obj.author.name}</p>`;
|
||
|
tempString += "<p class=\"spacer\"></p>"
|
||
|
tempString += `<p class=\"time\">${ new Date(obj.timestamp).toLocaleString(locale, options)}</p>`;
|
||
|
tempString += "</div>"
|
||
|
//htmlString += `<p>ID: ${obj.messageid}, Timestamp: ${obj.timestamp}, Author Name: ${obj.author.name}, Author ID: ${obj.author.id}, Content: ${obj.content}</p>`;
|
||
|
tempString += `<p class=\"content\">${obj.content.replaceAll("\n", "<br/>")}</p>`;
|
||
|
|
||
|
tempString += "</div>";
|
||
|
htmlString += tempString;
|
||
|
});
|
||
|
|
||
|
$(".chatHier").html(htmlString);
|