Change how Kinds work

This commit is contained in:
Jon Staab
2024-05-03 14:11:51 -07:00
parent d4cf63e906
commit 0dc2690e86
3 changed files with 86 additions and 82 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
import type {UnsignedEvent} from 'nostr-tools' import type {UnsignedEvent} from 'nostr-tools'
import {nip19} from 'nostr-tools' import {nip19} from 'nostr-tools'
import {GROUP_DEFINITION, COMMUNITY_DEFINITION} from './Kinds' import {Kind} from './Kinds'
export type Address = { export type Address = {
kind: number, kind: number,
@@ -51,8 +51,8 @@ export const addressFromEvent = (e: UnsignedEvent, relays: string[] = []) =>
// Utils // Utils
export const isGroupAddress = (a: Address) => a.kind === GROUP_DEFINITION export const isGroupAddress = (a: Address) => a.kind === Kind.GroupDefinition
export const isCommunityAddress = (a: Address) => a.kind === COMMUNITY_DEFINITION export const isCommunityAddress = (a: Address) => a.kind === Kind.CommunityDefinition
export const isContextAddress = (a: Address) => [GROUP_DEFINITION, COMMUNITY_DEFINITION].includes(a.kind) export const isContextAddress = (a: Address) => [Kind.GroupDefinition, Kind.CommunityDefinition].includes(a.kind)
+76 -74
View File
@@ -7,77 +7,79 @@ export const isParameterizedReplaceableKind = kinds.isParameterizedReplaceableKi
export const isReplaceableKind = (kind: number) => export const isReplaceableKind = (kind: number) =>
isPlainReplaceableKind(kind) || isParameterizedReplaceableKind(kind) isPlainReplaceableKind(kind) || isParameterizedReplaceableKind(kind)
export const PROFILE = 0 export enum Kind {
export const NOTE = 1 Profile = 0,
export const RELAY = 2 Note = 1,
export const DM = 4 Relay = 2,
export const EVENT_DELETION = 5 DM = 4,
export const REPOST = 6 EventDeletion = 5,
export const REACTION = 7 Repost = 6,
export const BADGE_AWARD = 8 Reaction = 7,
export const GENERIC_REPOST = 16 BadgeAward = 8,
export const CHANNEL_CREATION = 40 GenericRepost = 16,
export const CHANNEL_METADATA = 41 ChannelCreation = 40,
export const CHANNEL_MESSAGE = 42 ChannelMetadata = 41,
export const CHANNEL_HIDE_MESSAGE = 43 ChannelMessage = 42,
export const CHANNEL_MUTE_USER = 44 ChannelHideMessage = 43,
export const OPEN_TIMESTAMP = 1040 ChannelMuteUser = 44,
export const GIFT_WRAP = 1059 OpenTimestamp = 1040,
export const FILE_METADATA = 1063 GiftWrap = 1059,
export const LIVE_CHAT_MESSAGE = 1311 FileMetadata = 1063,
export const REMIX = 1808 LiveChatMessage = 1311,
export const PROBLEM_TRACKER = 1971 Remix = 1808,
export const REPORT = 1984 ProblemTracker = 1971,
export const LABEL = 1985 Report = 1984,
export const COMMUNITY_POST_APPROVAL = 4550 Label = 1985,
export const JOB_REQUEST = 5999 CommunityPostApproval = 4550,
export const JOB_RESULT = 6999 JobRequest = 5999,
export const JOB_FEEDBACK = 7000 JobResult = 6999,
export const ZAP_GOAL = 9041 JobFeedback = 7000,
export const ZAP_REQUEST = 9734 ZapGoal = 9041,
export const ZAP_RESPONSE = 9735 ZapRequest = 9734,
export const HIGHLIGHT = 9802 ZapResponse = 9735,
export const USER_LIST_MUTES = 10000 Highlight = 9802,
export const USER_LIST_PINS = 10001 UserListMutes = 10000,
export const USER_LIST_RELAYS = 10002 UserListPins = 10001,
export const USER_LIST_BOOKMARKS = 10003 UserListRelays = 10002,
export const USER_LIST_COMMUNITIES = 10004 UserListBookmarks = 10003,
export const USER_LIST_PUBLIC_CHATS = 10005 UserListCommunities = 10004,
export const USER_LIST_BLOCKED_RELAYS = 10006 UserListPublicChats = 10005,
export const USER_LIST_SEARCH_RELAYS = 10007 UserListBlockedRelays = 10006,
export const USER_LIST_INTERESTS = 10015 UserListSearchRelays = 10007,
export const USER_LIST_EMOJIS = 10030 UserListInterests = 10015,
export const LIGHTNING_PUB_RPC = 21000 UserListEmojis = 10030,
export const CLIENT_AUTH = 22242 LightningPubRpc = 21000,
export const NWC_INFO = 13194 ClientAuth = 22242,
export const NWC_REQUEST = 23194 NWCInfo = 13194,
export const NWC_RESPONSE = 23195 NWCRequest = 23194,
export const NOSTR_CONNECT = 24133 NWCResponse = 23195,
export const HTTP_AUTH = 27235 NostrConnect = 24133,
export const LIST_FOLLOWS = 3 HttpAuth = 27235,
export const LIST_PEOPLE = 30000 ListFollows = 3,
export const LIST_GENERIC = 30001 ListPeople = 30000,
export const LIST_RELAYS = 30002 ListGeneric = 30001,
export const LIST_BOOKMARKS = 30003 ListRelays = 30002,
export const LIST_CURATIONS = 30004 ListBookmarks = 30003,
export const PROFILE_BADGES = 30008 ListCurations = 30004,
export const BADGE_DEFINITION = 30009 ProfileBadges = 30008,
export const LIST_EMOJIS = 30030 BadgeDefinition = 30009,
export const LIST_INTERESTS = 30015 ListEmojis = 30030,
export const LONG_FORM_ARTICLE = 30023 ListInterests = 30015,
export const LONG_FORM_ARTICLE_DRAFT = 30024 LongFormArticle = 30023,
export const APPLICATION = 30078 LongFormArticleDraft = 30024,
export const LIVE_EVENT = 30311 Application = 30078,
export const USER_STATUSES = 30315 LiveEvent = 30311,
export const CLASSIFIED_LISTING = 30402 UserStatuses = 30315,
export const DRAFT_CLASSIFIED_LISTING = 30403 ClassifiedListing = 30402,
export const AUDIO = 31337 DraftClassifiedListing = 30403,
export const FEED = 31890 Audio = 31337,
export const CALENDAR = 31924 Feed = 31890,
export const CALENDAR_EVENT_DATE = 31922 Calendar = 31924,
export const CALENDAR_EVENT_TIME = 31923 CalendarEventDate = 31922,
export const CALENDAR_EVENT_RSVP = 31925 CalendarEventTime = 31923,
export const HANDLER_RECOMMENDATION = 31989 CalendarEventRsvp = 31925,
export const HANDLER_INFORMATION = 31990 HandlerRecommendation = 31989,
export const COMMUNITY_DEFINITION = 34550 HandlerInformation = 31990,
export const GROUP_DEFINITION = 35834 CommunityDefinition = 34550,
GroupDefinition = 35834,
}
+6 -4
View File
@@ -4,13 +4,15 @@ import {Fluent, ensurePlural, last} from '@welshman/lib'
import {isShareableRelayUrl, normalizeRelayUrl} from './Relays' import {isShareableRelayUrl, normalizeRelayUrl} from './Relays'
import type {Address} from './Address' import type {Address} from './Address'
import {encodeAddress, decodeAddress} from './Address' import {encodeAddress, decodeAddress} from './Address'
import {GROUP_DEFINITION, COMMUNITY_DEFINITION} from './Kinds' import {Kind} from './Kinds'
export class Tag extends (Fluent<string> as OmitStatics<typeof Fluent<string>, 'from'>) { export class Tag extends (Fluent<string> as OmitStatics<typeof Fluent<string>, 'from'>) {
static from = (xs: Iterable<string>) => new Tag(Array.from(xs)) static from = (xs: Iterable<string>) => new Tag(Array.from(xs))
static fromId = (id: string) => new Tag(["e", id]) static fromId = (id: string) => new Tag(["e", id])
static fromIdentifier = (identifier: string) => new Tag(["d", identifier])
static fromTopic = (topic: string) => new Tag(["t", topic]) static fromTopic = (topic: string) => new Tag(["t", topic])
static fromPubkey = (pubkey: string) => new Tag(["p", pubkey]) static fromPubkey = (pubkey: string) => new Tag(["p", pubkey])
@@ -35,11 +37,11 @@ export class Tag extends (Fluent<string> as OmitStatics<typeof Fluent<string>, '
isAddress = (kind?: number) => this.key() === "a" && this.value()?.startsWith(`${kind}:`) isAddress = (kind?: number) => this.key() === "a" && this.value()?.startsWith(`${kind}:`)
isGroup = () => this.isAddress(GROUP_DEFINITION) isGroup = () => this.isAddress(Kind.GroupDefinition)
isCommunity = () => this.isAddress(COMMUNITY_DEFINITION) isCommunity = () => this.isAddress(Kind.CommunityDefinition)
isContext = () => this.isAddress(GROUP_DEFINITION) || this.isAddress(COMMUNITY_DEFINITION) isContext = () => this.isAddress(Kind.GroupDefinition) || this.isAddress(Kind.CommunityDefinition)
} }
export class Tags extends (Fluent<Tag> as OmitStatics<typeof Fluent<Tag>, 'from'>) { export class Tags extends (Fluent<Tag> as OmitStatics<typeof Fluent<Tag>, 'from'>) {