mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Get rid of customevent
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {memoize, assoc} from "@welshman/lib"
|
import {memoize, assoc} from "@welshman/lib"
|
||||||
import type {CustomEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {Repository, createEvent, Relay} from "@welshman/util"
|
import {Repository, createEvent, Relay} from "@welshman/util"
|
||||||
import {withGetter} from "@welshman/store"
|
import {withGetter} from "@welshman/store"
|
||||||
import {NetworkContext, Tracker} from "@welshman/net"
|
import {NetworkContext, Tracker} from "@welshman/net"
|
||||||
@@ -55,8 +55,8 @@ export const signer = withGetter(derived(session, getSigner))
|
|||||||
const seenChallenges = new Set()
|
const seenChallenges = new Set()
|
||||||
|
|
||||||
Object.assign(NetworkContext, {
|
Object.assign(NetworkContext, {
|
||||||
onEvent: (url: string, event: CustomEvent) => tracker.track(event.id, url),
|
onEvent: (url: string, event: TrustedEvent) => tracker.track(event.id, url),
|
||||||
isDeleted: (url: string, event: CustomEvent) => repository.isDeleted(event),
|
isDeleted: (url: string, event: TrustedEvent) => repository.isDeleted(event),
|
||||||
onAuth: async (url: string, challenge: string) => {
|
onAuth: async (url: string, challenge: string) => {
|
||||||
if (seenChallenges.has(challenge)) {
|
if (seenChallenges.has(challenge)) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
import twColors from "tailwindcss/colors"
|
import twColors from "tailwindcss/colors"
|
||||||
import {readable} from "svelte/store"
|
import {readable} from "svelte/store"
|
||||||
import {hash} from "@welshman/lib"
|
import {hash} from "@welshman/lib"
|
||||||
import type {CustomEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {GROUP_REPLY, getAncestorTags, displayProfile, displayPubkey} from "@welshman/util"
|
import {GROUP_REPLY, getAncestorTags, displayProfile, displayPubkey} from "@welshman/util"
|
||||||
import {fly} from "@lib/transition"
|
import {fly} from "@lib/transition"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Avatar from "@lib/components/Avatar.svelte"
|
import Avatar from "@lib/components/Avatar.svelte"
|
||||||
import {deriveProfile, deriveEvent} from "@app/state"
|
import {deriveProfile, deriveEvent} from "@app/state"
|
||||||
|
|
||||||
export let event: CustomEvent
|
export let event: TrustedEvent
|
||||||
export let showPubkey: boolean
|
export let showPubkey: boolean
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import {
|
|||||||
GROUP_JOIN,
|
GROUP_JOIN,
|
||||||
GROUP_ADD_USER,
|
GROUP_ADD_USER,
|
||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
import type {SignedEvent, HashedEvent, EventTemplate, CustomEvent, PublishedProfile, PublishedList} from "@welshman/util"
|
import type {SignedEvent, HashedEvent, EventTemplate, TrustedEvent, PublishedProfile, PublishedList} from "@welshman/util"
|
||||||
import type {SubscribeRequest, PublishRequest, PublishStatus} from "@welshman/net"
|
import type {SubscribeRequest, PublishRequest, PublishStatus} from "@welshman/net"
|
||||||
import {publish as basePublish, subscribe as baseSubscribe} from "@welshman/net"
|
import {publish as basePublish, subscribe as baseSubscribe} from "@welshman/net"
|
||||||
import {decrypt, stamp, own, hash} from "@welshman/signer"
|
import {decrypt, stamp, own, hash} from "@welshman/signer"
|
||||||
@@ -107,7 +107,7 @@ export const deriveEvent = (idOrAddress: string, hints: string[] = []) => {
|
|||||||
|
|
||||||
return derived(
|
return derived(
|
||||||
deriveEvents(repository, {filters, includeDeleted: true}),
|
deriveEvents(repository, {filters, includeDeleted: true}),
|
||||||
(events: CustomEvent[]) => {
|
(events: TrustedEvent[]) => {
|
||||||
if (!attempted && events.length === 0) {
|
if (!attempted && events.length === 0) {
|
||||||
load({relays, filters})
|
load({relays, filters})
|
||||||
attempted = true
|
attempted = true
|
||||||
@@ -180,9 +180,9 @@ export const subscribe = (request: SubscribeRequest) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const load = (request: SubscribeRequest) =>
|
export const load = (request: SubscribeRequest) =>
|
||||||
new Promise<CustomEvent[]>(resolve => {
|
new Promise<TrustedEvent[]>(resolve => {
|
||||||
const sub = subscribe({closeOnEose: true, timeout: 3000, ...request})
|
const sub = subscribe({closeOnEose: true, timeout: 3000, ...request})
|
||||||
const events: CustomEvent[] = []
|
const events: TrustedEvent[] = []
|
||||||
|
|
||||||
sub.emitter.on("event", (url: string, e: SignedEvent) => {
|
sub.emitter.on("event", (url: string, e: SignedEvent) => {
|
||||||
repository.publish(e)
|
repository.publish(e)
|
||||||
@@ -217,12 +217,12 @@ export const setFreshnessBulk = (ns: string, updates: Record<string, number>) =>
|
|||||||
|
|
||||||
export const plaintext = withGetter(writable<Record<string, string>>({}))
|
export const plaintext = withGetter(writable<Record<string, string>>({}))
|
||||||
|
|
||||||
export const getPlaintext = (e: CustomEvent) => plaintext.get()[e.id]
|
export const getPlaintext = (e: TrustedEvent) => plaintext.get()[e.id]
|
||||||
|
|
||||||
export const setPlaintext = (e: CustomEvent, content: string) =>
|
export const setPlaintext = (e: TrustedEvent, content: string) =>
|
||||||
plaintext.update(assoc(e.id, content))
|
plaintext.update(assoc(e.id, content))
|
||||||
|
|
||||||
export const ensurePlaintext = async (e: CustomEvent) => {
|
export const ensurePlaintext = async (e: TrustedEvent) => {
|
||||||
if (e.content && !getPlaintext(e)) {
|
if (e.content && !getPlaintext(e)) {
|
||||||
const $signer = getSigner(getSession(e.pubkey))
|
const $signer = getSigner(getSession(e.pubkey))
|
||||||
|
|
||||||
@@ -323,12 +323,12 @@ export const {
|
|||||||
|
|
||||||
// Relay selections
|
// Relay selections
|
||||||
|
|
||||||
export const getReadRelayUrls = (event?: CustomEvent): string[] =>
|
export const getReadRelayUrls = (event?: TrustedEvent): string[] =>
|
||||||
getRelayTags(event?.tags || [])
|
getRelayTags(event?.tags || [])
|
||||||
.filter((t: string[]) => !t[2] || t[2] === "read")
|
.filter((t: string[]) => !t[2] || t[2] === "read")
|
||||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||||
|
|
||||||
export const getWriteRelayUrls = (event?: CustomEvent): string[] =>
|
export const getWriteRelayUrls = (event?: TrustedEvent): string[] =>
|
||||||
getRelayTags(event?.tags || [])
|
getRelayTags(event?.tags || [])
|
||||||
.filter((t: string[]) => !t[2] || t[2] === "write")
|
.filter((t: string[]) => !t[2] || t[2] === "write")
|
||||||
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
.map((t: string[]) => normalizeRelayUrl(t[1]))
|
||||||
@@ -357,7 +357,7 @@ export const {
|
|||||||
export const follows = deriveEventsMapped<PublishedList>(repository, {
|
export const follows = deriveEventsMapped<PublishedList>(repository, {
|
||||||
filters: [{kinds: [FOLLOWS]}],
|
filters: [{kinds: [FOLLOWS]}],
|
||||||
itemToEvent: item => item.event,
|
itemToEvent: item => item.event,
|
||||||
eventToItem: async (event: CustomEvent) =>
|
eventToItem: async (event: TrustedEvent) =>
|
||||||
readList(
|
readList(
|
||||||
asDecryptedEvent(event, {
|
asDecryptedEvent(event, {
|
||||||
content: await ensurePlaintext(event),
|
content: await ensurePlaintext(event),
|
||||||
@@ -387,7 +387,7 @@ export const {
|
|||||||
export const mutes = deriveEventsMapped<PublishedList>(repository, {
|
export const mutes = deriveEventsMapped<PublishedList>(repository, {
|
||||||
filters: [{kinds: [MUTES]}],
|
filters: [{kinds: [MUTES]}],
|
||||||
itemToEvent: item => item.event,
|
itemToEvent: item => item.event,
|
||||||
eventToItem: async (event: CustomEvent) =>
|
eventToItem: async (event: TrustedEvent) =>
|
||||||
readList(
|
readList(
|
||||||
asDecryptedEvent(event, {
|
asDecryptedEvent(event, {
|
||||||
content: await ensurePlaintext(event),
|
content: await ensurePlaintext(event),
|
||||||
@@ -429,9 +429,9 @@ export const getGroupUrl = (groupId: string) => splitGroupId(groupId)[0]
|
|||||||
|
|
||||||
export const getGroupNom = (groupId: string) => splitGroupId(groupId)[1]
|
export const getGroupNom = (groupId: string) => splitGroupId(groupId)[1]
|
||||||
|
|
||||||
export const getGroupName = (e?: CustomEvent) => e?.tags.find(nthEq(0, "name"))?.[1]
|
export const getGroupName = (e?: TrustedEvent) => e?.tags.find(nthEq(0, "name"))?.[1]
|
||||||
|
|
||||||
export const getGroupPicture = (e?: CustomEvent) => e?.tags.find(nthEq(0, "picture"))?.[1]
|
export const getGroupPicture = (e?: TrustedEvent) => e?.tags.find(nthEq(0, "picture"))?.[1]
|
||||||
|
|
||||||
export const displayGroup = (group?: Group) => group?.name || "[no name]"
|
export const displayGroup = (group?: Group) => group?.name || "[no name]"
|
||||||
|
|
||||||
@@ -440,14 +440,14 @@ export type Group = {
|
|||||||
name?: string
|
name?: string
|
||||||
about?: string
|
about?: string
|
||||||
picture?: string
|
picture?: string
|
||||||
event?: CustomEvent
|
event?: TrustedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PublishedGroup = Omit<Group, "event"> & {
|
export type PublishedGroup = Omit<Group, "event"> & {
|
||||||
event: CustomEvent
|
event: TrustedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readGroup = (event: CustomEvent) => {
|
export const readGroup = (event: TrustedEvent) => {
|
||||||
const nom = getIdentifier(event)!
|
const nom = getIdentifier(event)!
|
||||||
const name = event?.tags.find(nthEq(0, "name"))?.[1] || "[no name]"
|
const name = event?.tags.find(nthEq(0, "name"))?.[1] || "[no name]"
|
||||||
const about = event?.tags.find(nthEq(0, "about"))?.[1] || ""
|
const about = event?.tags.find(nthEq(0, "about"))?.[1] || ""
|
||||||
@@ -536,14 +536,14 @@ export type GroupMembership = {
|
|||||||
ids: Set<string>
|
ids: Set<string>
|
||||||
noms: Set<string>
|
noms: Set<string>
|
||||||
urls: Set<string>
|
urls: Set<string>
|
||||||
event?: CustomEvent
|
event?: TrustedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PublishedGroupMembership = Omit<GroupMembership, "event"> & {
|
export type PublishedGroupMembership = Omit<GroupMembership, "event"> & {
|
||||||
event: CustomEvent
|
event: TrustedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readGroupMembership = (event: CustomEvent) => {
|
export const readGroupMembership = (event: TrustedEvent) => {
|
||||||
const ids = new Set<string>()
|
const ids = new Set<string>()
|
||||||
const noms = new Set<string>()
|
const noms = new Set<string>()
|
||||||
const urls = new Set<string>()
|
const urls = new Set<string>()
|
||||||
@@ -584,10 +584,10 @@ export const {
|
|||||||
|
|
||||||
export type GroupMessage = {
|
export type GroupMessage = {
|
||||||
nom: string
|
nom: string
|
||||||
event: CustomEvent
|
event: TrustedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readGroupMessage = (event: CustomEvent): Maybe<GroupMessage> => {
|
export const readGroupMessage = (event: TrustedEvent): Maybe<GroupMessage> => {
|
||||||
const nom = event.tags.find(nthEq(0, "h"))?.[1]
|
const nom = event.tags.find(nthEq(0, "h"))?.[1]
|
||||||
|
|
||||||
if (!nom || between(GROUP_ADD_USER - 1, GROUP_JOIN + 1, event.kind)) {
|
if (!nom || between(GROUP_ADD_USER - 1, GROUP_JOIN + 1, event.kind)) {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
type Element = {
|
type Element = {
|
||||||
id: string
|
id: string
|
||||||
type: "date" | "note"
|
type: "date" | "note"
|
||||||
value: string | CustomEvent
|
value: string | TrustedEvent
|
||||||
showPubkey: boolean
|
showPubkey: boolean
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {sortBy} from "@welshman/lib"
|
import {sortBy} from "@welshman/lib"
|
||||||
import type {CustomEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {formatTimestampAsDate} from "@lib/util"
|
import {formatTimestampAsDate} from "@lib/util"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
const {nom} = $page.params
|
const {nom} = $page.params
|
||||||
const conversation = deriveGroupConversation(nom)
|
const conversation = deriveGroupConversation(nom)
|
||||||
|
|
||||||
const assertEvent = (e: any) => e as CustomEvent
|
const assertEvent = (e: any) => e as TrustedEvent
|
||||||
|
|
||||||
let loading = true
|
let loading = true
|
||||||
let elements: Element[] = []
|
let elements: Element[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user