Get chat back to working ish
This commit is contained in:
@@ -4,13 +4,14 @@
|
|||||||
import {writable} from "svelte/store"
|
import {writable} from "svelte/store"
|
||||||
import {createEditor, type Editor, EditorContent} from "svelte-tiptap"
|
import {createEditor, type Editor, EditorContent} from "svelte-tiptap"
|
||||||
import {NProfileExtension, ImageExtension} from "nostr-editor"
|
import {NProfileExtension, ImageExtension} from "nostr-editor"
|
||||||
import {createEvent, CHAT_MESSAGE} from "@welshman/util"
|
import {createEvent} from "@welshman/util"
|
||||||
import {publishThunk, makeThunk} from "@welshman/app"
|
import {publishThunk, makeThunk} from "@welshman/app"
|
||||||
import {findNodes} from "@lib/tiptap"
|
import {findNodes} from "@lib/tiptap"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import {makeMention, makeIMeta} from "@app/commands"
|
import {makeMention, makeIMeta} from "@app/commands"
|
||||||
import {getChatEditorOptions, addFile} from "@app/editor"
|
import {getChatEditorOptions, addFile} from "@app/editor"
|
||||||
|
import {MESSAGE} from "@app/state"
|
||||||
|
|
||||||
export let url
|
export let url
|
||||||
export let topic = ""
|
export let topic = ""
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
|
|
||||||
const sendMessage = () => {
|
const sendMessage = () => {
|
||||||
const json = $editor.getJSON()
|
const json = $editor.getJSON()
|
||||||
const topicTag = topic ? ["t", topic] : []
|
const topicTags = topic ? [["t", topic]] : []
|
||||||
const mentionTags = findNodes(NProfileExtension.name, json).map(m =>
|
const mentionTags = findNodes(NProfileExtension.name, json).map(m =>
|
||||||
makeMention(m.attrs!.pubkey, m.attrs!.relays),
|
makeMention(m.attrs!.pubkey, m.attrs!.relays),
|
||||||
)
|
)
|
||||||
@@ -29,9 +30,9 @@
|
|||||||
makeIMeta(src, {x, ox: x}),
|
makeIMeta(src, {x, ox: x}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const event = createEvent(CHAT_MESSAGE, {
|
const event = createEvent(MESSAGE, {
|
||||||
content: $editor.getText(),
|
content: $editor.getText(),
|
||||||
tags: [topicTag, ...mentionTags, ...imetaTags],
|
tags: [["-"], ["relay", url], ...topicTags, ...mentionTags, ...imetaTags],
|
||||||
})
|
})
|
||||||
|
|
||||||
publishThunk(makeThunk({event, relays: [url]}))
|
publishThunk(makeThunk({event, relays: [url]}))
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import {nip19} from "nostr-tools"
|
import {nip19} from "nostr-tools"
|
||||||
import type {Page} from "@sveltejs/kit"
|
import type {Page} from "@sveltejs/kit"
|
||||||
import {userMembership, decodeNEvent} from "@app/state"
|
import {userMembership, decodeNRelay} from "@app/state"
|
||||||
|
|
||||||
export const makeSpacePath = (url: string, extra = "") => {
|
export const makeSpacePath = (url: string, extra = "") => {
|
||||||
let path = `/spaces/${nip19.nrelayEncode(url)}`
|
let path = `/spaces/${nip19.nrelayEncode(url)}`
|
||||||
@@ -21,7 +21,7 @@ export const getPrimaryNavItemIndex = ($page: Page) => {
|
|||||||
case "discover":
|
case "discover":
|
||||||
return urls.length + 2
|
return urls.length + 2
|
||||||
case "spaces": {
|
case "spaces": {
|
||||||
const routeUrl = decodeNEvent($page.params.nrelay)
|
const routeUrl = decodeNRelay($page.params.nrelay)
|
||||||
|
|
||||||
return urls.findIndex(url => url === routeUrl) + 1
|
return urls.findIndex(url => url === routeUrl) + 1
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-11
@@ -69,10 +69,6 @@ export const deriveEvent = (idOrAddress: string, hints: string[] = []) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persist relay/event mappings
|
|
||||||
|
|
||||||
export const relaysByMessage = withGetter(writable(new Map<string, string[]>()))
|
|
||||||
|
|
||||||
// Topics
|
// Topics
|
||||||
|
|
||||||
export const topicsByUrl = withGetter(writable(new Map<string, string[]>()))
|
export const topicsByUrl = withGetter(writable(new Map<string, string[]>()))
|
||||||
@@ -133,18 +129,19 @@ export type Message = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const readMessage = (event: TrustedEvent): Maybe<Message[]> => {
|
export const readMessage = (event: TrustedEvent): Maybe<Message[]> => {
|
||||||
|
const urls = getRelayTagValues(event.tags)
|
||||||
const topics = getTopicTagValues(event.tags)
|
const topics = getTopicTagValues(event.tags)
|
||||||
|
|
||||||
if (topics.length !== 1) return undefined
|
if (topics.length > 1 || urls.length !== 1) return undefined
|
||||||
|
|
||||||
const topic = topics[0]
|
const topic = topics[0] || ""
|
||||||
const urls = relaysByMessage.get().get(event.id) || []
|
const url = urls[0]
|
||||||
|
|
||||||
return urls.map(url => ({url, topic, chat: getChatId(url, topic), event}))
|
return urls.map(url => ({url, topic, chat: makeChatId(url, topic), event}))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const messages = deriveEventsMapped<Message>(repository, {
|
export const messages = deriveEventsMapped<Message>(repository, {
|
||||||
filters: [{}],
|
filters: [{kinds: [MESSAGE, REPLY]}],
|
||||||
eventToItem: readMessage,
|
eventToItem: readMessage,
|
||||||
itemToEvent: item => item.event,
|
itemToEvent: item => item.event,
|
||||||
})
|
})
|
||||||
@@ -158,7 +155,7 @@ export type Chat = {
|
|||||||
messages: Message[]
|
messages: Message[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getChatId = (url: string, topic: string) => `${url}'${topic}`
|
export const makeChatId = (url: string, topic: string) => `${url}'${topic}`
|
||||||
|
|
||||||
export const splitChatId = (id: string) => id.split("'")
|
export const splitChatId = (id: string) => id.split("'")
|
||||||
|
|
||||||
@@ -210,7 +207,7 @@ export const userMembership = withGetter(
|
|||||||
|
|
||||||
// Other utils
|
// Other utils
|
||||||
|
|
||||||
export const decodeNEvent = (nevent: string) => nip19.decode(nevent).data as string
|
export const decodeNRelay = (nevent: string) => nip19.decode(nevent).data as string
|
||||||
|
|
||||||
export const displayReaction = (content: string) => {
|
export const displayReaction = (content: string) => {
|
||||||
if (content === "+") return "❤️"
|
if (content === "+") return "❤️"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
import PrimaryNav from "@app/components/PrimaryNav.svelte"
|
import PrimaryNav from "@app/components/PrimaryNav.svelte"
|
||||||
import {modals, clearModal} from "@app/modal"
|
import {modals, clearModal} from "@app/modal"
|
||||||
import {theme} from "@app/theme"
|
import {theme} from "@app/theme"
|
||||||
import {INDEXER_RELAYS, topicsByUrl, relaysByMessage} from "@app/state"
|
import {INDEXER_RELAYS, topicsByUrl} from "@app/state"
|
||||||
import {loadUserData} from "@app/commands"
|
import {loadUserData} from "@app/commands"
|
||||||
import * as state from "@app/state"
|
import * as state from "@app/state"
|
||||||
|
|
||||||
@@ -77,7 +77,6 @@
|
|||||||
store: handles,
|
store: handles,
|
||||||
},
|
},
|
||||||
topicsByUrl: storageAdapters.fromMapStore(topicsByUrl),
|
topicsByUrl: storageAdapters.fromMapStore(topicsByUrl),
|
||||||
relaysByMessage: storageAdapters.fromMapStore(relaysByMessage),
|
|
||||||
publishStatus: storageAdapters.fromObjectStore(publishStatusData),
|
publishStatus: storageAdapters.fromObjectStore(publishStatusData),
|
||||||
freshness: storageAdapters.fromObjectStore(freshness),
|
freshness: storageAdapters.fromObjectStore(freshness),
|
||||||
plaintext: storageAdapters.fromObjectStore(plaintext),
|
plaintext: storageAdapters.fromObjectStore(plaintext),
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
import SpaceExit from "@app/components/SpaceExit.svelte"
|
import SpaceExit from "@app/components/SpaceExit.svelte"
|
||||||
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
import SpaceJoin from "@app/components/SpaceJoin.svelte"
|
||||||
import RoomCreate from "@app/components/RoomCreate.svelte"
|
import RoomCreate from "@app/components/RoomCreate.svelte"
|
||||||
import {userMembership, decodeNEvent} from "@app/state"
|
import {userMembership, decodeNRelay} from "@app/state"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
import {makeSpacePath} from "@app/routes"
|
import {makeSpacePath} from "@app/routes"
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
let showMenu = false
|
let showMenu = false
|
||||||
|
|
||||||
$: url = decodeNEvent($page.params.nrelay)
|
$: url = decodeNRelay($page.params.nrelay)
|
||||||
$: rooms = sort($userMembership?.topicsByUrl?.get(url) || [])
|
$: rooms = sort($userMembership?.topicsByUrl?.get(url) || [])
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
import Spinner from "@lib/components/Spinner.svelte"
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import ChatMessage from "@app/components/ChatMessage.svelte"
|
import ChatMessage from "@app/components/ChatMessage.svelte"
|
||||||
import ChatCompose from "@app/components/ChatCompose.svelte"
|
import ChatCompose from "@app/components/ChatCompose.svelte"
|
||||||
import {deriveChat, MESSAGE, REPLY} from "@app/state"
|
import {decodeNRelay, makeChatId, deriveChat, MESSAGE, REPLY} from "@app/state"
|
||||||
|
|
||||||
const {url, topic} = $page.params
|
const {nrelay, topic = ""} = $page.params
|
||||||
const chat = deriveChat(url)
|
const url = decodeNRelay(nrelay)
|
||||||
|
const chat = deriveChat(makeChatId(url, topic))
|
||||||
|
|
||||||
const assertEvent = (e: any) => e as TrustedEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user