feat: nip-36

This commit is contained in:
Kieran 2023-04-06 23:12:51 +01:00
parent 6195325200
commit 0cb52cc961
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 85 additions and 1 deletions

View File

@ -83,6 +83,7 @@ export default function Note(props: NoteProps) {
const { pinned, bookmarked } = useSelector((s: RootState) => s.login); const { pinned, bookmarked } = useSelector((s: RootState) => s.login);
const publisher = useEventPublisher(); const publisher = useEventPublisher();
const [translated, setTranslated] = useState<Translation>(); const [translated, setTranslated] = useState<Translation>();
const [contentWarningAccepted, setContentWarningAccepted] = useState(false);
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const reactions = useMemo(() => getReactions(related, ev.id, EventKind.Reaction), [related, ev]); const reactions = useMemo(() => getReactions(related, ev.id, EventKind.Reaction), [related, ev]);
const groupReactions = useMemo(() => { const groupReactions = useMemo(() => {
@ -161,8 +162,32 @@ export default function Note(props: NoteProps) {
</b> </b>
); );
} }
const contentWarning = ev.tags.find(a => a[0] === "content-warning");
if (contentWarning && !contentWarningAccepted) {
return (
<div
className="note-invoice"
onClick={e => {
e.stopPropagation();
setContentWarningAccepted(true);
}}>
<FormattedMessage defaultMessage="This note has been marked as sensitive, click here to reveal" />
{contentWarning[1] && (
<>
<br />
<FormattedMessage
defaultMessage="Reason: {reason}"
values={{
reason: contentWarning[1],
}}
/>
</>
)}
</div>
);
}
return <Text content={body} tags={ev.tags} creator={ev.pubkey} />; return <Text content={body} tags={ev.tags} creator={ev.pubkey} />;
}, [ev]); }, [ev, contentWarningAccepted]);
useLayoutEffect(() => { useLayoutEffect(() => {
if (entry && inView && extendable === false) { if (entry && inView && extendable === false) {

View File

@ -49,6 +49,7 @@ export function NoteCreator(props: NoteCreatorProps) {
const [preview, setPreview] = useState<RawEvent>(); const [preview, setPreview] = useState<RawEvent>();
const [showAdvanced, setShowAdvanced] = useState(false); const [showAdvanced, setShowAdvanced] = useState(false);
const [zapForward, setZapForward] = useState(""); const [zapForward, setZapForward] = useState("");
const [sensitive, setSensitiveContent] = useState<string>();
const uploader = useFileUpload(); const uploader = useFileUpload();
async function sendNote() { async function sendNote() {
@ -68,6 +69,10 @@ export function NoteCreator(props: NoteCreatorProps) {
return; return;
} }
} }
if (sensitive) {
extraTags ??= [];
extraTags.push(["content-warning", sensitive]);
}
const ev = replyTo ? await publisher.reply(replyTo, note, extraTags) : await publisher.note(note, extraTags); const ev = replyTo ? await publisher.reply(replyTo, note, extraTags) : await publisher.note(note, extraTags);
console.debug("Sending note: ", ev); console.debug("Sending note: ", ev);
publisher.broadcast(ev); publisher.broadcast(ev);
@ -192,6 +197,9 @@ export function NoteCreator(props: NoteCreatorProps) {
<p> <p>
<FormattedMessage defaultMessage="All zaps sent to this note will be received by the following LNURL" /> <FormattedMessage defaultMessage="All zaps sent to this note will be received by the following LNURL" />
</p> </p>
<b className="warning">
<FormattedMessage defaultMessage="Not all clients support this yet" />
</b>
<input <input
type="text" type="text"
className="w-max" className="w-max"
@ -201,6 +209,28 @@ export function NoteCreator(props: NoteCreatorProps) {
value={zapForward} value={zapForward}
onChange={e => setZapForward(e.target.value)} onChange={e => setZapForward(e.target.value)}
/> />
<h4>
<FormattedMessage defaultMessage="Sensitive Content" />
</h4>
<p>
<FormattedMessage defaultMessage="Users must accept the content warning to show the content of your note." />
</p>
<b className="warning">
<FormattedMessage defaultMessage="Not all clients support this yet" />
</b>
<div className="flex">
<input
className="w-max"
type="text"
value={sensitive}
onChange={e => setSensitiveContent(e.target.value)}
maxLength={50}
minLength={1}
placeholder={formatMessage({
defaultMessage: "Reason",
})}
/>
</div>
</div> </div>
)} )}
</Modal> </Modal>

View File

@ -12,6 +12,7 @@
--highlight: #8b5cf6; --highlight: #8b5cf6;
--error: #ff6053; --error: #ff6053;
--success: #2ad544; --success: #2ad544;
--warning: #ff8800;
--gray-superlight: #eee; --gray-superlight: #eee;
--gray-light: #999; --gray-light: #999;
@ -480,6 +481,10 @@ body.scroll-lock {
color: var(--error); color: var(--error);
} }
.warning {
color: var(--warning);
}
.bg-error { .bg-error {
background-color: var(--error); background-color: var(--error);
} }

View File

@ -199,6 +199,9 @@
"Adk34V": { "Adk34V": {
"defaultMessage": "Setup your Profile" "defaultMessage": "Setup your Profile"
}, },
"AkCxS/": {
"defaultMessage": "Reason"
},
"AnLrRC": { "AnLrRC": {
"defaultMessage": "Non-Zap", "defaultMessage": "Non-Zap",
"description": "Non-Zap, Regular LN payment" "description": "Non-Zap, Regular LN payment"
@ -372,6 +375,9 @@
"KAhAcM": { "KAhAcM": {
"defaultMessage": "Enter LNDHub config" "defaultMessage": "Enter LNDHub config"
}, },
"KLo3SP": {
"defaultMessage": "Reason: {reason}"
},
"KQvWvD": { "KQvWvD": {
"defaultMessage": "Deleted" "defaultMessage": "Deleted"
}, },
@ -518,6 +524,9 @@
"UQ3pOC": { "UQ3pOC": {
"defaultMessage": "On Nostr, many people have the same username. User names and identity are separate things. You can get a unique identifier in the next step." "defaultMessage": "On Nostr, many people have the same username. User names and identity are separate things. You can get a unique identifier in the next step."
}, },
"UUPFlt": {
"defaultMessage": "Users must accept the content warning to show the content of your note."
},
"Up5U7K": { "Up5U7K": {
"defaultMessage": "Block" "defaultMessage": "Block"
}, },
@ -594,6 +603,9 @@
"aWpBzj": { "aWpBzj": {
"defaultMessage": "Show more" "defaultMessage": "Show more"
}, },
"bQdA2k": {
"defaultMessage": "Sensitive Content"
},
"brAXSu": { "brAXSu": {
"defaultMessage": "Pick a username" "defaultMessage": "Pick a username"
}, },
@ -672,6 +684,9 @@
"gDzDRs": { "gDzDRs": {
"defaultMessage": "Emoji to send when reactiong to a note" "defaultMessage": "Emoji to send when reactiong to a note"
}, },
"gXgY3+": {
"defaultMessage": "Not all clients support this yet"
},
"gjBiyj": { "gjBiyj": {
"defaultMessage": "Loading..." "defaultMessage": "Loading..."
}, },
@ -947,6 +962,9 @@
"wvFw6Y": { "wvFw6Y": {
"defaultMessage": "Hey, it looks like you dont have a NIP-05 handle yet, you should get one! Check out {link}" "defaultMessage": "Hey, it looks like you dont have a NIP-05 handle yet, you should get one! Check out {link}"
}, },
"x/q8d5": {
"defaultMessage": "This note has been marked as sensitive, click here to reveal"
},
"x82IOl": { "x82IOl": {
"defaultMessage": "Mute" "defaultMessage": "Mute"
}, },

View File

@ -64,6 +64,7 @@
"ADmfQT": "Parent", "ADmfQT": "Parent",
"ASRK0S": "This author has been muted", "ASRK0S": "This author has been muted",
"Adk34V": "Setup your Profile", "Adk34V": "Setup your Profile",
"AkCxS/": "Reason",
"AnLrRC": "Non-Zap", "AnLrRC": "Non-Zap",
"AyGauy": "Login", "AyGauy": "Login",
"B4C47Y": "name too short", "B4C47Y": "name too short",
@ -121,6 +122,7 @@
"K3r6DQ": "Delete", "K3r6DQ": "Delete",
"K7AkdL": "Show", "K7AkdL": "Show",
"KAhAcM": "Enter LNDHub config", "KAhAcM": "Enter LNDHub config",
"KLo3SP": "Reason: {reason}",
"KQvWvD": "Deleted", "KQvWvD": "Deleted",
"KWuDfz": "I have saved my keys, continue", "KWuDfz": "I have saved my keys, continue",
"KahimY": "Unknown event kind: {kind}", "KahimY": "Unknown event kind: {kind}",
@ -168,6 +170,7 @@
"TpgeGw": "Hex Salt..", "TpgeGw": "Hex Salt..",
"UDYlxu": "Pending Subscriptions", "UDYlxu": "Pending Subscriptions",
"UQ3pOC": "On Nostr, many people have the same username. User names and identity are separate things. You can get a unique identifier in the next step.", "UQ3pOC": "On Nostr, many people have the same username. User names and identity are separate things. You can get a unique identifier in the next step.",
"UUPFlt": "Users must accept the content warning to show the content of your note.",
"Up5U7K": "Block", "Up5U7K": "Block",
"VBadwB": "Hmm, can't find a key manager extension.. try reloading the page.", "VBadwB": "Hmm, can't find a key manager extension.. try reloading the page.",
"VN0+Fz": "Balance: {amount} sats", "VN0+Fz": "Balance: {amount} sats",
@ -193,6 +196,7 @@
"ZUZedV": "Lightning Donation:", "ZUZedV": "Lightning Donation:",
"a5UPxh": "Fund developers and platforms providing NIP-05 verification services", "a5UPxh": "Fund developers and platforms providing NIP-05 verification services",
"aWpBzj": "Show more", "aWpBzj": "Show more",
"bQdA2k": "Sensitive Content",
"brAXSu": "Pick a username", "brAXSu": "Pick a username",
"bxv59V": "Just now", "bxv59V": "Just now",
"c+oiJe": "Install Extension", "c+oiJe": "Install Extension",
@ -218,6 +222,7 @@
"gBdUXk": "Save your keys!", "gBdUXk": "Save your keys!",
"gDZkld": "Snort is a Nostr UI, nostr is a decentralised protocol for saving and distributing \"notes\".", "gDZkld": "Snort is a Nostr UI, nostr is a decentralised protocol for saving and distributing \"notes\".",
"gDzDRs": "Emoji to send when reactiong to a note", "gDzDRs": "Emoji to send when reactiong to a note",
"gXgY3+": "Not all clients support this yet",
"gjBiyj": "Loading...", "gjBiyj": "Loading...",
"h8XMJL": "Badges", "h8XMJL": "Badges",
"hCUivF": "Notes will stream in real time into global and posts tab", "hCUivF": "Notes will stream in real time into global and posts tab",
@ -308,6 +313,7 @@
"wqyN/i": "Find out more info about {service} at {link}", "wqyN/i": "Find out more info about {service} at {link}",
"wtLjP6": "Copy ID", "wtLjP6": "Copy ID",
"wvFw6Y": "Hey, it looks like you dont have a NIP-05 handle yet, you should get one! Check out {link}", "wvFw6Y": "Hey, it looks like you dont have a NIP-05 handle yet, you should get one! Check out {link}",
"x/q8d5": "This note has been marked as sensitive, click here to reveal",
"x82IOl": "Mute", "x82IOl": "Mute",
"xIoGG9": "Go to", "xIoGG9": "Go to",
"xJ9n2N": "Your public key", "xJ9n2N": "Your public key",