Skip to content

Commit

Permalink
feat: improved invite flow (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
agazso authored Sep 21, 2023
1 parent e9ff597 commit 29c3f72
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/routes/invite/[address]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@
import { goto } from '$app/navigation'
import routes from '$lib/routes'
import { page } from '$app/stores'
import { chats } from '$lib/stores/chat'
import { chats, isGroupChatId } from '$lib/stores/chat'
import adapters from '$lib/adapters'
import { Html5Qrcode } from 'html5-qrcode'
import Camera from '$lib/components/icons/camera.svelte'
import QrCodeIcon from '$lib/components/icons/qr-code.svelte'
import { onDestroy } from 'svelte'
import { onDestroy, onMount } from 'svelte'
import ButtonBlock from '$lib/components/button-block.svelte'
import ChevronRight from '$lib/components/icons/chevron-right.svelte'
import Layout from '$lib/components/layout.svelte'
import type { User as UserType } from '$lib/types'
import { profile } from '$lib/stores/profile'
import { walletStore } from '$lib/stores/wallet'
import Avatar from '$lib/components/avatar.svelte'
import type { Unsubscriber } from 'svelte/store'
// check if the chat already exists
$: if ($chats.chats.has($page.params.address)) {
goto(routes.CHAT($page.params.address))
}
let unsubscribe: Unsubscriber | undefined
let copied = false
let loading = false
function copyToClipboard() {
Expand Down Expand Up @@ -107,7 +109,23 @@
goto(routes.CHAT(chatId))
}
onMount(() => {
// make a copy of the list of chatIds when the screen is opened so that later we can compare
const oldChatIds = new Set($chats.chats.keys())
unsubscribe = chats.subscribe((store) => {
store.chats.forEach((value, key) => {
if (!oldChatIds.has(key) && !isGroupChatId(value.chatId)) {
// found new private chat
goto(routes.CHAT(value.chatId))
}
})
})
})
onDestroy(() => {
if (unsubscribe) {
unsubscribe()
}
stop()
})
</script>
Expand Down

1 comment on commit 29c3f72

@vercel
Copy link

@vercel vercel bot commented on 29c3f72 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.