<script>
    import { activeChannel, events } from '../store';

    let channel;
    let allMessages = [];
    $: messages = allMessages.filter(
        (ev) => ev.type === 'message' && channel !== null && ev.channel.id === channel.id
    );

    activeChannel.subscribe((value) => {
        channel = value;
    });

    events.subscribe((value) => {
        allMessages = value;
    });
</script>

<div>
    {#each messages as message}
        <div>
            <pre><tt>{message.at} @{message.sender.name}: {message.message.body}</tt></pre>
        </div>
    {/each}
</div>

<style>
</style>
