can create and join rooms, but messages are all mixed up

This commit is contained in:
hugogogo
2023-01-09 08:43:55 +01:00
parent ebbd5ff530
commit 258e7596fe
5 changed files with 148 additions and 152 deletions

View File

@@ -36,7 +36,8 @@
item.name = "me";
}
});
msgs.update(msgs => msgs.concat(data.messages));
//msgs.update(msgs => msgs.concat(data.messages));
msgs.update(msgs => msgs = data.messages);
});
layout = "room";
}

View File

@@ -1,6 +1,7 @@
<script>
import Button from './Element_button.svelte';
import { msgs, user } from './Store_chat';
export let layout = "";
export let back = "";
@@ -24,7 +25,7 @@
room_name: evt.target.innerText,
}
const messages = fetch('/api/v2/chat/join',
fetch('/api/v2/chat/join',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -34,15 +35,8 @@
.then(data =>
{
console.log(data);
// data.messages.forEach(function(item) {
// if (item.name === user.username) {
// item.name = "me";
// }
// });
// msgs.update(msgs => msgs.concat(data.messages));
});
/*
const messages = fetch('/api/v2/chat/messages')
.then(resp => resp.json())
.then(data =>
@@ -53,9 +47,10 @@
item.name = "me";
}
});
msgs.update(msgs => msgs.concat(data.messages));
msgs.update(msgs => msgs = data.messages);
});
layout = "room";
/*
*/
}