mirror of
https://github.com/acid-info/Kurate.git
synced 2025-02-14 08:46:45 +00:00
fix(firebase): submit post (#389)
This commit is contained in:
parent
10137cf1e3
commit
4acdff71fe
@ -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<boolean> {
|
||||
// FIXME: properly implement
|
||||
console.error('NOT IMPLEMENTED', 'queryPersonaJoined')
|
||||
return true
|
||||
}
|
||||
|
||||
async joinPersona(personId: string): Promise<void> {
|
||||
// FIXME: properly implement
|
||||
console.error('NOT IMPLEMENTED', 'joinPersona')
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ export interface Adapter {
|
||||
startChat(chat: DraftChat): Promise<string>
|
||||
sendChatMessage(chatId: string, text: string): Promise<void>
|
||||
subscribeToChat?: (chatId: string) => Promise<() => void>
|
||||
queryPersonaJoined(personId: string): Promise<boolean>
|
||||
joinPersona(personaId: string): Promise<void>
|
||||
}
|
||||
|
||||
export const adapters = ['zkitter', 'firebase'] as const
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
</script>
|
||||
|
||||
@ -122,16 +104,12 @@
|
||||
|
||||
<svelte:fragment slot="button_primary">
|
||||
{#if $profile.signer !== undefined}
|
||||
{#if hasJoined}
|
||||
<Button
|
||||
variant="primary"
|
||||
label="Submit post"
|
||||
icon={Edit}
|
||||
on:click={() => goto(ROUTES.POST_NEW(groupId))}
|
||||
/>
|
||||
{:else}
|
||||
<Button variant="primary" label="Join Persona" icon={Edit} on:click={joinPersona} />
|
||||
{/if}
|
||||
<Button
|
||||
variant="primary"
|
||||
label="Submit post"
|
||||
icon={Edit}
|
||||
on:click={() => goto(ROUTES.POST_NEW(groupId))}
|
||||
/>
|
||||
{:else}
|
||||
<Button
|
||||
variant="primary"
|
||||
|
Loading…
x
Reference in New Issue
Block a user