completed message persistence
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -9,17 +9,17 @@
|
||||
let messages = [];
|
||||
let timer = null;
|
||||
|
||||
async function display(hash){
|
||||
const url = api(`message/${hash}`);
|
||||
async function display(id){
|
||||
const url = api(`message/${id}`);
|
||||
const res = await get(url);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
const json = await res.json();
|
||||
if (timer) clearTimeout(timer);
|
||||
for (let i in messages){
|
||||
if (messages[i].hash == hash){
|
||||
if (messages[i].id == id){
|
||||
messages[i].body = json.body;
|
||||
timer = setTimeout(() => {mark_read(hash)}, 2000);
|
||||
timer = setTimeout(() => {mark_read(id)}, 2000);
|
||||
} else {
|
||||
delete messages[i].body;
|
||||
}
|
||||
@@ -40,13 +40,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function mark_read(hash){
|
||||
async function mark_read(id){
|
||||
timer = null;
|
||||
const url = api(`message/read/${hash}`);
|
||||
const url = api(`message/read/${id}`);
|
||||
const res = await patch(url);
|
||||
if (res.ok) {
|
||||
for (let i in messages){
|
||||
if (messages[i].hash == hash) messages[i].read = true;
|
||||
if (messages[i].id == id) messages[i].read = true;
|
||||
}
|
||||
yikes();
|
||||
} else {
|
||||
@@ -73,7 +73,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each messages as message}
|
||||
<tr class="message-{message.hash}" onclick={ev => display(message.hash)}>
|
||||
<tr class="message-{message.id}" onclick={ev => display(message.id)}>
|
||||
<td>
|
||||
{#if message.read}→ {/if}
|
||||
{message.timestamp}
|
||||
@@ -82,7 +82,7 @@
|
||||
<td>{message.subject}</td>
|
||||
</tr>
|
||||
{#if message.body}
|
||||
<tr class="message-{message.hash} body">
|
||||
<tr class="message-{message.id} body">
|
||||
<td></td>
|
||||
<td colspan="2">
|
||||
<pre>{message.body.trim()}</pre>
|
||||
|
||||
Reference in New Issue
Block a user