Allow user to close a conversation (chatbox)

One step ahead in the memory game! This commit closes #12 (closes,
get it? :P)
This commit is contained in:
Badri Sunderarajan 2024-03-24 16:45:08 +05:30
parent 26e344e28c
commit 86c5489f19
Signed by: badrihippo
GPG key ID: 9F594532AD60DE03

View file

@ -1,6 +1,8 @@
<script lang="ts">
import Text from '../components/Text.svelte'
import ChatMessage from '../components/ChatMessage.svelte'
import OptionsMenu from '../components/OptionsMenu.svelte'
import ListItem from '../components/ListItem.svelte'
import Input from '../components/Input.svelte'
import { onMount } from 'svelte'
@ -22,6 +24,10 @@
let chatListEl
let composeBox
// Whether the options menu is visible or not
let optionsMenuVisible = false
$: title = chatbox?.attributes?.nickname || chatbox?.attributes?.id || params.chatID || 'Convo'
$: titleStore.update(() => title)
@ -90,7 +96,9 @@
}
k.right.label = 'Options'
k.right.callback = () => {}
k.right.callback = () => {
optionsMenuVisible = !optionsMenuVisible
}
return k
})
@ -183,6 +191,14 @@
onComposeBoxUpdate()
}
// Function to close a conversation
function closeChat() {
chatbox.close().then(() => {
push('/messages')
})
}
// Get it all running!
onMount(() => {
// Initialise the chatbox
chatbox = _converse.chatboxes.get(params.chatID)
@ -223,6 +239,15 @@
/>
</div>
{#if optionsMenuVisible}
<OptionsMenu title="Options">
<ListItem
text="Close conversation"
onclick={closeChat}
/>
</OptionsMenu>
{/if}
<style>
.compose-box {
height: 8rem;