diff --git a/caesar.json b/caesar.json new file mode 100644 index 0000000..ba6aedd --- /dev/null +++ b/caesar.json @@ -0,0 +1,4 @@ +[ + { "character": 0, "text": "Sire! Forgive my informal message. We must speak."}, + { "character": 1, "text": "What is the meaning of this? What is so urgent it cannot wait for our usual meeting? Speak plainly and get to the pooint. I have more important matters to attend to than deciphering vague missives."} +] diff --git a/index.html b/index.html index c740a44..8530fa3 100644 --- a/index.html +++ b/index.html @@ -7,13 +7,12 @@ -

Hester is typing...

+

NAME is typing...

diff --git a/main.js b/main.js index 73d9e37..9a38832 100644 --- a/main.js +++ b/main.js @@ -17,15 +17,25 @@ class Conversation { } start() { - setTimeout(() => { - this.messageIdx = 0; - this.pings = 1; + document.title = this.contactName; + document.getElementById("header-title").innerHTML = this.contactName; + + // if the first message comes from the other party, + const firstMessage = this.messageData[0]; + const firstMessageIsOurs = firstMessage.character == 0; + if (firstMessageIsOurs) { + } else { + setTimeout(() => { + this.messageIdx = 0; + this.pings = 1; + + const data = this.messageData[this.messageIdx]; + const message = new ReceivedMessage(data); + this.messages.push(message); + this.onMessageReceived(message); + }, 3623); + } - const data = this.messageData[this.messageIdx]; - const message = new ReceivedMessage(data); - this.messages.push(message); - this.onMessageReceived(message); - }, 3623); } peekNextMessageData() { @@ -269,7 +279,7 @@ class SentMessage { function setTypingIndicator(isTyping) { document.getElementById("typing-indicator").innerHTML = isTyping - ? "Hester is typing..." + ? `${conversation.contactName} is typing...` : ""; } @@ -323,18 +333,6 @@ function pressSendButton() { conversation.sendMessage(); } -function updateLightLag() { - const lag = conversation.getLightLag(); - const text = lag.toFixed(5) + " seconds"; - document.getElementById("delay-text").innerHTML = text; -} - -function startLightLagUpdateLoop() { - setInterval(() => { - updateLightLag(); - }, 1000); -} - function onMessageReceived(message) { updateChat(message); setTypingIndicator(false); @@ -345,15 +343,10 @@ function onMessageSent(message) { } function init(messageData) { - conversation = new Conversation(messageData, "Hester Gomez", onMessageReceived, onMessageSent); + conversation = new Conversation(messageData, "Caesar", onMessageReceived, onMessageSent); conversation.start(); - - document.title = conversation.contactName; - - updateLightLag(0); - startLightLagUpdateLoop(); } -fetch("hester.json") +fetch("caesar.json") .then(response => response.json()) .then(json => init(json));