Fix url regexp

This commit is contained in:
Jonathan Staab 2023-02-09 05:56:11 -06:00
parent 3ccec4d5b5
commit 387649ee4c
4 changed files with 16 additions and 5 deletions

View File

@ -183,7 +183,7 @@ const subscribe = async (relays, filters, {onEvent, onEose}: Record<string, (e:
}
}
const request = (relays, filters, {threshold = 0.1} = {}): Promise<Record<string, unknown>[]> => {
const request = (relays, filters, {threshold = 0.5} = {}): Promise<Record<string, unknown>[]> => {
return new Promise(async resolve => {
relays = uniqBy(prop('url'), relays.filter(r => isRelay(r.url)))
threshold = relays.length * threshold

View File

@ -77,6 +77,9 @@ const loadContext = async (relays, notes, {loadParents = false, depth = 0, ...op
events = events.concat(await loadContext(parentRelays, parents, opts))
}
// Load missing people from replies etc
await loadPeople(relays, pluck('pubkey', events))
// We're recurring and so may end up with duplicates here
return uniqBy(prop('id'), events)
})

View File

@ -34,7 +34,7 @@
const showEntire = anchorId === note.id
const interactive = !anchorId || !showEntire
const relays = getEventRelays(note)
const person = database.watch('people', p => p.get(note.pubkey) || {pubkey: note.pubkey})
const person = database.watch('people', () => database.getPersonWithFallback(note.pubkey))
let likes, flags, like, flag

View File

@ -73,15 +73,23 @@ export const fromParentOffset = (element, offset): [HTMLElement, number] => {
throw new Error("Unable to find parent offset")
}
export const extractUrls = url =>
url.match(/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?!&//=]*)/gi)
export const extractUrls = content => {
const regex = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?!&//=;]*)/gi
const urls = content.match(regex)
return (urls || [])
// Skip decimals like 3.5 and ellipses which have more than one dot in a row
.filter(url => !url.match(/^[\d\.]+$/) && !url.match(/\.{2}/))
// Add protocol on to the beginning of the url
.map(url => url.startsWith('http') ? url : '//' + url)
}
export const renderContent = content => {
// Escape html
content = escapeHtml(content)
// Extract urls
for (const url of extractUrls(content) || []) {
for (const url of extractUrls(content)) {
const $a = document.createElement('a')
$a.href = url