diff --git a/packages/ui/src/lib/adapters/firebase/index.ts b/packages/ui/src/lib/adapters/firebase/index.ts index 2e00c14..f84f66c 100644 --- a/packages/ui/src/lib/adapters/firebase/index.ts +++ b/packages/ui/src/lib/adapters/firebase/index.ts @@ -525,15 +525,4 @@ export class Firebase implements Adapter { const chatDoc = doc(db, `chats/${chatId}`) updateDoc(chatDoc, { messages: arrayUnion(message), lastMessage: text }) } - - async queryPersonaJoined(personId: string): Promise { - // FIXME: properly implement - console.error('NOT IMPLEMENTED', 'queryPersonaJoined') - return true - } - - async joinPersona(personId: string): Promise { - // FIXME: properly implement - console.error('NOT IMPLEMENTED', 'joinPersona') - } } diff --git a/packages/ui/src/lib/adapters/index.ts b/packages/ui/src/lib/adapters/index.ts index 670aa9d..99e4405 100644 --- a/packages/ui/src/lib/adapters/index.ts +++ b/packages/ui/src/lib/adapters/index.ts @@ -32,8 +32,6 @@ export interface Adapter { startChat(chat: DraftChat): Promise sendChatMessage(chatId: string, text: string): Promise subscribeToChat?: (chatId: string) => Promise<() => void> - queryPersonaJoined(personId: string): Promise - joinPersona(personaId: string): Promise } export const adapters = ['zkitter', 'firebase'] as const diff --git a/packages/ui/src/lib/adapters/zkitter/index.ts b/packages/ui/src/lib/adapters/zkitter/index.ts index 23eafc4..098776e 100644 --- a/packages/ui/src/lib/adapters/zkitter/index.ts +++ b/packages/ui/src/lib/adapters/zkitter/index.ts @@ -3,7 +3,7 @@ import { type Chat, chats } from '$lib/stores/chat' import { type DraftPersona, personas } from '$lib/stores/persona' import { get } from 'svelte/store' import { profile } from '$lib/stores/profile' -import { saveToLocalStorage } from '$lib/utils' +import { saveToLocalStorage, sleep } from '$lib/utils' import type { Adapter } from '..' import { GroupAdapter } from './group-adapter' import type { Signer } from 'ethers' @@ -643,6 +643,20 @@ export class ZkitterAdapter implements Adapter { const { Post, MessageType, PostMessageSubType } = await import('zkitter-js') // const {Registry, RLN} = await import('rlnjs') + // User did not join the persona yet + if (await this.queryPersonaJoined(personaId)) { + await this.joinPersona(personaId) + + // Wait for the join to propagate + await new Promise((resolve) => { + const interval = setInterval(async () => { + if (await this.queryPersonaJoined(personaId)) resolve(clearInterval(interval)) + }) + }) + } + + await sleep(1000) // wait for zkitter to sync + const post = new Post({ type: MessageType.Post, subtype: PostMessageSubType.Default, diff --git a/packages/ui/src/routes/persona/[id]/+page.svelte b/packages/ui/src/routes/persona/[id]/+page.svelte index cda9729..5d7b53a 100644 --- a/packages/ui/src/routes/persona/[id]/+page.svelte +++ b/packages/ui/src/routes/persona/[id]/+page.svelte @@ -15,6 +15,10 @@ import Header from '$lib/components/header.svelte' import Container from '$lib/components/container.svelte' import InfoBox from '$lib/components/info-box.svelte' + import SectionTitle from '$lib/components/section-title.svelte' + import Dropdown from '$lib/components/dropdown.svelte' + import DropdownItem from '$lib/components/dropdown-item.svelte' + import Search from '$lib/components/search.svelte' import { posts } from '$lib/stores/post' import { personas } from '$lib/stores/persona' @@ -25,10 +29,6 @@ import adapter from '$lib/adapters' import { canConnectWallet } from '$lib/services' import { onDestroy, onMount } from 'svelte' - import SectionTitle from '$lib/components/section-title.svelte' - import Dropdown from '$lib/components/dropdown.svelte' - import DropdownItem from '$lib/components/dropdown-item.svelte' - import Search from '$lib/components/search.svelte' const groupId = $page.params.id const persona = $personas.all.get(groupId) @@ -37,24 +37,13 @@ let sortBy: 'date' | 'alphabetical' = 'date' let filterQuery = '' let unsubscribe: () => unknown - let hasJoined = false - - const unsubProfile = profile.subscribe(async (state) => { - if (state.unirepIdentity) { - hasJoined = await adapter.queryPersonaJoined(groupId) - } - }) onMount(async () => { adapter.subscribePersonaPosts(groupId).then((unsub) => (unsubscribe = unsub)) - if ($profile.unirepIdentity) { - hasJoined = await adapter.queryPersonaJoined(groupId) - } }) onDestroy(() => { if (unsubscribe) unsubscribe() - unsubProfile() }) let y: number @@ -63,13 +52,6 @@ const addToFavorite = () => adapter.addPersonaToFavorite(groupId, persona) const removeFromFavorite = () => adapter.removePersonaFromFavorite(groupId, persona) - const joinPersona = async () => { - await adapter.joinPersona(groupId) - if ($profile.unirepIdentity) { - hasJoined = await adapter.queryPersonaJoined(groupId) - } - } - $: personaPosts = $posts.data.get(groupId) @@ -122,16 +104,12 @@ {#if $profile.signer !== undefined} - {#if hasJoined} -