Add a few utilities
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {parseJson, nth, nthEq} from "@welshman/lib"
|
||||
import {parseJson, ensurePlural, nth} from "@welshman/lib"
|
||||
import {Address} from "./Address"
|
||||
import {isShareableRelayUrl} from "./Relay"
|
||||
import {Encryptable, DecryptedEvent} from "./Encryptable"
|
||||
@@ -45,5 +45,10 @@ export const createList = ({kind, publicTags = [], privateTags = []}: List) =>
|
||||
export const editList = ({kind, publicTags = [], privateTags = []}: PublishedList) =>
|
||||
new Encryptable({kind, tags: publicTags}, {content: JSON.stringify(privateTags)})
|
||||
|
||||
export const getListValues = (tagName: string, list: List | undefined) =>
|
||||
[...list?.publicTags || [], ...list?.privateTags || []].filter(nthEq(0, tagName)).map(nth(1))
|
||||
export const getListValues = (tagName: string | string[], list: List | undefined) => {
|
||||
const tagNames = ensurePlural(tagName)
|
||||
const allTags = [...list?.publicTags || [], ...list?.privateTags || []]
|
||||
const filteredTags = allTags.filter(t => tagNames.includes(t[0])).map(nth(1))
|
||||
|
||||
return filteredTags
|
||||
}
|
||||
|
||||
@@ -140,6 +140,12 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
|
||||
}
|
||||
|
||||
publish = (event: E, {shouldNotify = true} = {}): boolean => {
|
||||
if (!event?.id) {
|
||||
console.warn("Attempted to publish invalid event to repository", event)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// If we've already seen this event, or it's been deleted, we're done
|
||||
if (this.eventsById.get(event.id) || this.isDeleted(event)) {
|
||||
return false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type {OmitStatics} from '@welshman/lib'
|
||||
import {Fluent, nth, nthEq, ensurePlural} from '@welshman/lib'
|
||||
import {Fluent, mapVals, nth, nthEq, ensurePlural} from '@welshman/lib'
|
||||
import {isRelayUrl, normalizeRelayUrl} from './Relay'
|
||||
import {Address, isContextAddress} from './Address'
|
||||
import {GROUP, COMMUNITY} from './Kinds'
|
||||
@@ -249,3 +249,6 @@ export const getAncestorTags = (tags: string[][]) => {
|
||||
|
||||
return {roots, replies, mentions}
|
||||
}
|
||||
|
||||
export const getAncestorTagValues = (tags: string[][]) =>
|
||||
mapVals(tags => tags.map(nth(1)), getAncestorTags(tags))
|
||||
|
||||
Reference in New Issue
Block a user