feat: embedded emoji
This commit is contained in:
@@ -9,6 +9,7 @@ export type TEmbeddedNodeType =
|
||||
| 'hashtag'
|
||||
| 'websocket-url'
|
||||
| 'url'
|
||||
| 'emoji'
|
||||
|
||||
export type TEmbeddedNode =
|
||||
| {
|
||||
@@ -64,6 +65,11 @@ export const EmbeddedNormalUrlParser: TContentParser = {
|
||||
regex: /https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+/gu
|
||||
}
|
||||
|
||||
export const EmbeddedEmojiParser: TContentParser = {
|
||||
type: 'emoji',
|
||||
regex: /:[a-zA-Z0-9_]+:/g
|
||||
}
|
||||
|
||||
export function parseContent(content: string, parsers: TContentParser[]) {
|
||||
let nodes: TEmbeddedNode[] = [{ type: 'text', data: content.trim() }]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BIG_RELAY_URLS, ExtendedKind } from '@/constants'
|
||||
import client from '@/services/client.service'
|
||||
import { TImageInfo, TRelayList, TRelaySet } from '@/types'
|
||||
import { TEmoji, TImageInfo, TRelayList, TRelaySet } from '@/types'
|
||||
import { LRUCache } from 'lru-cache'
|
||||
import { Event, kinds, nip19 } from 'nostr-tools'
|
||||
import { getAmountFromInvoice, getLightningAddressFromProfile } from './lightning'
|
||||
@@ -505,3 +505,12 @@ export function getLatestEvent(events: Event[]) {
|
||||
export function getReplaceableEventIdentifier(event: Event) {
|
||||
return event.tags.find(tagNameEquals('d'))?.[1] ?? ''
|
||||
}
|
||||
|
||||
export function extractEmojiInfosFromTags(tags: string[][] = []) {
|
||||
return tags
|
||||
.map((tag) => {
|
||||
if (tag.length < 3 || tag[0] !== 'emoji') return null
|
||||
return { shortcode: tag[1], url: tag[2] }
|
||||
})
|
||||
.filter(Boolean) as TEmoji[]
|
||||
}
|
||||
|
||||
@@ -66,11 +66,6 @@ export function extractPubkeysFromEventTags(tags: string[][]) {
|
||||
)
|
||||
}
|
||||
|
||||
export function extractEmojiFromEventTags(emojiName: string, tags: string[][]) {
|
||||
const emojiTag = tags.find((tag) => tag[0] === 'emoji' && tag[1] === emojiName)
|
||||
return emojiTag?.[2]
|
||||
}
|
||||
|
||||
export function isSameTag(tag1: string[], tag2: string[]) {
|
||||
if (tag1.length !== tag2.length) return false
|
||||
for (let i = 0; i < tag1.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user