Fix editing messages with html tags
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import {PublishStatus} from "@welshman/net"
|
import {PublishStatus} from "@welshman/net"
|
||||||
import {displayRelayUrl} from "@welshman/util"
|
import {displayRelayUrl} from "@welshman/util"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import {addPeriod} from "@lib/util"
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
url: string
|
url: string
|
||||||
@@ -25,7 +26,7 @@
|
|||||||
|
|
||||||
<div class="card2 bg-alt col-2 shadow-lg">
|
<div class="card2 bg-alt col-2 shadow-lg">
|
||||||
<p>
|
<p>
|
||||||
Failed to publish to {displayRelayUrl(url)}: {message}.
|
Failed to publish to {displayRelayUrl(url)}: {addPeriod(message)}
|
||||||
</p>
|
</p>
|
||||||
<Button class="link" onclick={retry}>Retry</Button>
|
<Button class="link" onclick={retry}>Retry</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from "@welshman/app"
|
} from "@welshman/app"
|
||||||
import type {FileAttributes} from "@welshman/editor"
|
import type {FileAttributes} from "@welshman/editor"
|
||||||
import {Editor, MentionSuggestion, WelshmanExtension, editorProps} from "@welshman/editor"
|
import {Editor, MentionSuggestion, WelshmanExtension, editorProps} from "@welshman/editor"
|
||||||
|
import {escapeHtml} from "@lib/html"
|
||||||
import {makeMentionNodeView} from "@app/editor/MentionNodeView"
|
import {makeMentionNodeView} from "@app/editor/MentionNodeView"
|
||||||
import ProfileSuggestion from "@app/editor/ProfileSuggestion.svelte"
|
import ProfileSuggestion from "@app/editor/ProfileSuggestion.svelte"
|
||||||
import {uploadFile} from "@app/core/commands"
|
import {uploadFile} from "@app/core/commands"
|
||||||
@@ -82,7 +83,7 @@ export const makeEditor = async ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
return new Editor({
|
return new Editor({
|
||||||
content,
|
content: escapeHtml(content),
|
||||||
autofocus,
|
autofocus,
|
||||||
editorProps,
|
editorProps,
|
||||||
element: document.createElement("div"),
|
element: document.createElement("div"),
|
||||||
|
|||||||
@@ -164,3 +164,11 @@ export const compressFile = async (
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const escapeHtml = (html: string) => {
|
||||||
|
const element = document.createElement("div")
|
||||||
|
|
||||||
|
element.innerText = html
|
||||||
|
|
||||||
|
return element.innerHTML
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,3 +26,5 @@ export const buildUrl = (base: string | URL, ...pathname: string[]) => {
|
|||||||
|
|
||||||
return url.toString()
|
return url.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const addPeriod = (s: string) => (s + ".").replace(/\.+$/, ".")
|
||||||
|
|||||||
@@ -110,51 +110,58 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = async ({content, tags}: EventContent) => {
|
const onSubmit = async ({content, tags}: EventContent) => {
|
||||||
tags.push(["h", h])
|
try {
|
||||||
|
tags.push(["h", h])
|
||||||
|
|
||||||
if (await shouldProtect) {
|
if (await shouldProtect) {
|
||||||
tags.push(PROTECTED)
|
tags.push(PROTECTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
let template: EventContent & {created_at?: number} = {content, tags}
|
let template: EventContent & {created_at?: number} = {content, tags}
|
||||||
|
|
||||||
if (eventToEdit) {
|
if (eventToEdit) {
|
||||||
// Delete previous message, to be republished with same timestamp
|
// Don't do anything if message hasn't changed
|
||||||
template.created_at = eventToEdit.created_at
|
if (eventToEdit.content === content) {
|
||||||
publishDelete({
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete previous message, to be republished with same timestamp
|
||||||
|
template.created_at = eventToEdit.created_at
|
||||||
|
publishDelete({
|
||||||
|
relays: [url],
|
||||||
|
event: $state.snapshot(eventToEdit),
|
||||||
|
protect: await shouldProtect,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (share) {
|
||||||
|
template = prependParent(share, template, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
template = prependParent(parent, template, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
const thunk = publishThunk({
|
||||||
relays: [url],
|
relays: [url],
|
||||||
event: $state.snapshot(eventToEdit),
|
event: makeEvent(MESSAGE, template),
|
||||||
protect: await shouldProtect,
|
delay: $userSettingsValues.send_delay,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if ($userSettingsValues.send_delay) {
|
||||||
|
pushToast({
|
||||||
|
timeout: 30_000,
|
||||||
|
children: {
|
||||||
|
component: ThunkToast,
|
||||||
|
props: {thunk},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
clearParent()
|
||||||
|
clearShare()
|
||||||
|
clearEventToEdit()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (share) {
|
|
||||||
template = prependParent(share, template, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parent) {
|
|
||||||
template = prependParent(parent, template, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
const thunk = publishThunk({
|
|
||||||
relays: [url],
|
|
||||||
event: makeEvent(MESSAGE, template),
|
|
||||||
delay: $userSettingsValues.send_delay,
|
|
||||||
})
|
|
||||||
|
|
||||||
if ($userSettingsValues.send_delay) {
|
|
||||||
pushToast({
|
|
||||||
timeout: 30_000,
|
|
||||||
children: {
|
|
||||||
component: ThunkToast,
|
|
||||||
props: {thunk},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
clearParent()
|
|
||||||
clearShare()
|
|
||||||
clearEventToEdit()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const onScroll = () => {
|
const onScroll = () => {
|
||||||
|
|||||||
@@ -54,45 +54,52 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = async ({content, tags}: EventContent) => {
|
const onSubmit = async ({content, tags}: EventContent) => {
|
||||||
let template: EventContent & {created_at?: number} = {content, tags}
|
try {
|
||||||
|
let template: EventContent & {created_at?: number} = {content, tags}
|
||||||
|
|
||||||
if (eventToEdit) {
|
if (eventToEdit) {
|
||||||
// Delete previous message, to be republished with same timestamp
|
// Don't do anything if message hasn't changed
|
||||||
template.created_at = eventToEdit.created_at
|
if (eventToEdit.content === content) {
|
||||||
publishDelete({relays: [url], event: eventToEdit, protect: await shouldProtect})
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await shouldProtect) {
|
// Delete previous message, to be republished with same timestamp
|
||||||
tags.push(PROTECTED)
|
template.created_at = eventToEdit.created_at
|
||||||
}
|
publishDelete({relays: [url], event: eventToEdit, protect: await shouldProtect})
|
||||||
|
}
|
||||||
|
|
||||||
if (share) {
|
if (await shouldProtect) {
|
||||||
template = prependParent(share, template, url)
|
tags.push(PROTECTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent) {
|
if (share) {
|
||||||
template = prependParent(parent, template, url)
|
template = prependParent(share, template, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
const thunk = publishThunk({
|
if (parent) {
|
||||||
relays: [url],
|
template = prependParent(parent, template, url)
|
||||||
event: makeEvent(MESSAGE, template),
|
}
|
||||||
delay: $userSettingsValues.send_delay,
|
|
||||||
})
|
|
||||||
|
|
||||||
if ($userSettingsValues.send_delay) {
|
const thunk = publishThunk({
|
||||||
pushToast({
|
relays: [url],
|
||||||
timeout: 30_000,
|
event: makeEvent(MESSAGE, template),
|
||||||
children: {
|
delay: $userSettingsValues.send_delay,
|
||||||
component: ThunkToast,
|
|
||||||
props: {thunk},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
clearParent()
|
if ($userSettingsValues.send_delay) {
|
||||||
clearShare()
|
pushToast({
|
||||||
clearEventToEdit()
|
timeout: 30_000,
|
||||||
|
children: {
|
||||||
|
component: ThunkToast,
|
||||||
|
props: {thunk},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
clearParent()
|
||||||
|
clearShare()
|
||||||
|
clearEventToEdit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onScroll = () => {
|
const onScroll = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user