Change how Kinds work
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type {UnsignedEvent} from 'nostr-tools'
|
||||
import {nip19} from 'nostr-tools'
|
||||
import {GROUP_DEFINITION, COMMUNITY_DEFINITION} from './Kinds'
|
||||
import {Kind} from './Kinds'
|
||||
|
||||
export type Address = {
|
||||
kind: number,
|
||||
@@ -51,8 +51,8 @@ export const addressFromEvent = (e: UnsignedEvent, relays: string[] = []) =>
|
||||
|
||||
// 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
@@ -7,77 +7,79 @@ export const isParameterizedReplaceableKind = kinds.isParameterizedReplaceableKi
|
||||
export const isReplaceableKind = (kind: number) =>
|
||||
isPlainReplaceableKind(kind) || isParameterizedReplaceableKind(kind)
|
||||
|
||||
export const PROFILE = 0
|
||||
export const NOTE = 1
|
||||
export const RELAY = 2
|
||||
export const DM = 4
|
||||
export const EVENT_DELETION = 5
|
||||
export const REPOST = 6
|
||||
export const REACTION = 7
|
||||
export const BADGE_AWARD = 8
|
||||
export const GENERIC_REPOST = 16
|
||||
export const CHANNEL_CREATION = 40
|
||||
export const CHANNEL_METADATA = 41
|
||||
export const CHANNEL_MESSAGE = 42
|
||||
export const CHANNEL_HIDE_MESSAGE = 43
|
||||
export const CHANNEL_MUTE_USER = 44
|
||||
export const OPEN_TIMESTAMP = 1040
|
||||
export const GIFT_WRAP = 1059
|
||||
export const FILE_METADATA = 1063
|
||||
export const LIVE_CHAT_MESSAGE = 1311
|
||||
export const REMIX = 1808
|
||||
export const PROBLEM_TRACKER = 1971
|
||||
export const REPORT = 1984
|
||||
export const LABEL = 1985
|
||||
export const COMMUNITY_POST_APPROVAL = 4550
|
||||
export const JOB_REQUEST = 5999
|
||||
export const JOB_RESULT = 6999
|
||||
export const JOB_FEEDBACK = 7000
|
||||
export const ZAP_GOAL = 9041
|
||||
export const ZAP_REQUEST = 9734
|
||||
export const ZAP_RESPONSE = 9735
|
||||
export const HIGHLIGHT = 9802
|
||||
export const USER_LIST_MUTES = 10000
|
||||
export const USER_LIST_PINS = 10001
|
||||
export const USER_LIST_RELAYS = 10002
|
||||
export const USER_LIST_BOOKMARKS = 10003
|
||||
export const USER_LIST_COMMUNITIES = 10004
|
||||
export const USER_LIST_PUBLIC_CHATS = 10005
|
||||
export const USER_LIST_BLOCKED_RELAYS = 10006
|
||||
export const USER_LIST_SEARCH_RELAYS = 10007
|
||||
export const USER_LIST_INTERESTS = 10015
|
||||
export const USER_LIST_EMOJIS = 10030
|
||||
export const LIGHTNING_PUB_RPC = 21000
|
||||
export const CLIENT_AUTH = 22242
|
||||
export const NWC_INFO = 13194
|
||||
export const NWC_REQUEST = 23194
|
||||
export const NWC_RESPONSE = 23195
|
||||
export const NOSTR_CONNECT = 24133
|
||||
export const HTTP_AUTH = 27235
|
||||
export const LIST_FOLLOWS = 3
|
||||
export const LIST_PEOPLE = 30000
|
||||
export const LIST_GENERIC = 30001
|
||||
export const LIST_RELAYS = 30002
|
||||
export const LIST_BOOKMARKS = 30003
|
||||
export const LIST_CURATIONS = 30004
|
||||
export const PROFILE_BADGES = 30008
|
||||
export const BADGE_DEFINITION = 30009
|
||||
export const LIST_EMOJIS = 30030
|
||||
export const LIST_INTERESTS = 30015
|
||||
export const LONG_FORM_ARTICLE = 30023
|
||||
export const LONG_FORM_ARTICLE_DRAFT = 30024
|
||||
export const APPLICATION = 30078
|
||||
export const LIVE_EVENT = 30311
|
||||
export const USER_STATUSES = 30315
|
||||
export const CLASSIFIED_LISTING = 30402
|
||||
export const DRAFT_CLASSIFIED_LISTING = 30403
|
||||
export const AUDIO = 31337
|
||||
export const FEED = 31890
|
||||
export const CALENDAR = 31924
|
||||
export const CALENDAR_EVENT_DATE = 31922
|
||||
export const CALENDAR_EVENT_TIME = 31923
|
||||
export const CALENDAR_EVENT_RSVP = 31925
|
||||
export const HANDLER_RECOMMENDATION = 31989
|
||||
export const HANDLER_INFORMATION = 31990
|
||||
export const COMMUNITY_DEFINITION = 34550
|
||||
export const GROUP_DEFINITION = 35834
|
||||
export enum Kind {
|
||||
Profile = 0,
|
||||
Note = 1,
|
||||
Relay = 2,
|
||||
DM = 4,
|
||||
EventDeletion = 5,
|
||||
Repost = 6,
|
||||
Reaction = 7,
|
||||
BadgeAward = 8,
|
||||
GenericRepost = 16,
|
||||
ChannelCreation = 40,
|
||||
ChannelMetadata = 41,
|
||||
ChannelMessage = 42,
|
||||
ChannelHideMessage = 43,
|
||||
ChannelMuteUser = 44,
|
||||
OpenTimestamp = 1040,
|
||||
GiftWrap = 1059,
|
||||
FileMetadata = 1063,
|
||||
LiveChatMessage = 1311,
|
||||
Remix = 1808,
|
||||
ProblemTracker = 1971,
|
||||
Report = 1984,
|
||||
Label = 1985,
|
||||
CommunityPostApproval = 4550,
|
||||
JobRequest = 5999,
|
||||
JobResult = 6999,
|
||||
JobFeedback = 7000,
|
||||
ZapGoal = 9041,
|
||||
ZapRequest = 9734,
|
||||
ZapResponse = 9735,
|
||||
Highlight = 9802,
|
||||
UserListMutes = 10000,
|
||||
UserListPins = 10001,
|
||||
UserListRelays = 10002,
|
||||
UserListBookmarks = 10003,
|
||||
UserListCommunities = 10004,
|
||||
UserListPublicChats = 10005,
|
||||
UserListBlockedRelays = 10006,
|
||||
UserListSearchRelays = 10007,
|
||||
UserListInterests = 10015,
|
||||
UserListEmojis = 10030,
|
||||
LightningPubRpc = 21000,
|
||||
ClientAuth = 22242,
|
||||
NWCInfo = 13194,
|
||||
NWCRequest = 23194,
|
||||
NWCResponse = 23195,
|
||||
NostrConnect = 24133,
|
||||
HttpAuth = 27235,
|
||||
ListFollows = 3,
|
||||
ListPeople = 30000,
|
||||
ListGeneric = 30001,
|
||||
ListRelays = 30002,
|
||||
ListBookmarks = 30003,
|
||||
ListCurations = 30004,
|
||||
ProfileBadges = 30008,
|
||||
BadgeDefinition = 30009,
|
||||
ListEmojis = 30030,
|
||||
ListInterests = 30015,
|
||||
LongFormArticle = 30023,
|
||||
LongFormArticleDraft = 30024,
|
||||
Application = 30078,
|
||||
LiveEvent = 30311,
|
||||
UserStatuses = 30315,
|
||||
ClassifiedListing = 30402,
|
||||
DraftClassifiedListing = 30403,
|
||||
Audio = 31337,
|
||||
Feed = 31890,
|
||||
Calendar = 31924,
|
||||
CalendarEventDate = 31922,
|
||||
CalendarEventTime = 31923,
|
||||
CalendarEventRsvp = 31925,
|
||||
HandlerRecommendation = 31989,
|
||||
HandlerInformation = 31990,
|
||||
CommunityDefinition = 34550,
|
||||
GroupDefinition = 35834,
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@ import {Fluent, ensurePlural, last} from '@welshman/lib'
|
||||
import {isShareableRelayUrl, normalizeRelayUrl} from './Relays'
|
||||
import type {Address} 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'>) {
|
||||
static from = (xs: Iterable<string>) => new Tag(Array.from(xs))
|
||||
|
||||
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 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}:`)
|
||||
|
||||
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'>) {
|
||||
|
||||
Reference in New Issue
Block a user