Repost init

This commit is contained in:
Kieran 2023-01-08 17:33:54 +00:00
parent bfc25f6ce1
commit c01e0ca457
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
6 changed files with 30 additions and 11 deletions

View File

@ -1,6 +1,6 @@
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { faHeart, faReply, faThumbsDown, faTrash, faBolt } from "@fortawesome/free-solid-svg-icons"; import { faHeart, faReply, faThumbsDown, faTrash, faBolt, faRepeat } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import useEventPublisher from "../feed/EventPublisher"; import useEventPublisher from "../feed/EventPublisher";
@ -46,6 +46,11 @@ export default function NoteFooter(props) {
} }
} }
async function repost() {
let evRepost = await publisher.repost(ev);
publisher.broadcast(evRepost);
}
function tipButton() { function tipButton() {
let service = author?.lud16 || author?.lud06; let service = author?.lud16 || author?.lud06;
if (service) { if (service) {
@ -79,6 +84,9 @@ export default function NoteFooter(props) {
<FontAwesomeIcon icon={faTrash} onClick={(e) => deleteEvent()} /> <FontAwesomeIcon icon={faTrash} onClick={(e) => deleteEvent()} />
</span> : null} </span> : null}
{tipButton()} {tipButton()}
<span className="pill" onClick={() => repost()}>
<FontAwesomeIcon icon={faRepeat} />
</span>
<span className="pill" onClick={(e) => setReply(s => !s)}> <span className="pill" onClick={(e) => setReply(s => !s)}>
<FontAwesomeIcon icon={faReply} /> <FontAwesomeIcon icon={faReply} />
</span> </span>

View File

@ -64,15 +64,13 @@ export default function useEventPublisher() {
let thread = replyTo.Thread; let thread = replyTo.Thread;
if (thread) { if (thread) {
console.debug(replyTo);
if (thread.Root) { if (thread.Root) {
ev.Tags.push(new Tag(["e", thread.Root.Event, "", "root"], ev.Tags.length)); ev.Tags.push(new Tag(["e", thread.Root.Event, "", "root"], ev.Tags.length));
} else { } else {
let unRootedReply = thread.Reply.Thread; ev.Tags.push(new Tag(["e", thread.ReplyTo.Event, "", "root"], ev.Tags.length));
ev.Tags.push(new Tag(["e", unRootedReply.ReplyTo.Event, "", "root"], ev.Tags.length));
}
if (thread.Reply) {
ev.Tags.push(new Tag(["e", thread.Reply.Id, "", "reply"], ev.Tags.length));
} }
ev.Tags.push(new Tag(["e", replyTo.Id, "", "reply"], ev.Tags.length));
ev.Tags.push(new Tag(["p", replyTo.PubKey], ev.Tags.length)); ev.Tags.push(new Tag(["p", replyTo.PubKey], ev.Tags.length));
for (let pk of thread.PubKeys) { for (let pk of thread.PubKeys) {
ev.Tags.push(new Tag(["p", pk], ev.Tags.length)); ev.Tags.push(new Tag(["p", pk], ev.Tags.length));
@ -121,6 +119,17 @@ export default function useEventPublisher() {
ev.Content = ""; ev.Content = "";
ev.Tags.push(new Tag(["e", id])); ev.Tags.push(new Tag(["e", id]));
return await signEvent(ev); return await signEvent(ev);
},
repost: async (note) => {
if (typeof note.Id !== "string") {
throw "Must be parsed note in Event class";
}
let ev = Event.ForPubKey(pubKey);
ev.Kind = EventKind.Repost;
ev.Content = "";
ev.Tags.push(new Tag(["e", note.Id]));
ev.Tags.push(new Tag(["p", note.PubKey]));
return await signEvent(ev);
} }
} }
} }

View File

@ -65,6 +65,10 @@ code {
border-radius: 25px; border-radius: 25px;
} }
textarea {
font: inherit;
}
input[type="text"], input[type="password"], input[type="number"], textarea { input[type="text"], input[type="password"], input[type="number"], textarea {
padding: 10px; padding: 10px;
border-radius: 5px; border-radius: 5px;

View File

@ -5,7 +5,8 @@ const EventKind = {
RecommendServer: 2, RecommendServer: 2,
ContactList: 3, // NIP-02 ContactList: 3, // NIP-02
DirectMessage: 4, // NIP-04 DirectMessage: 4, // NIP-04
Deletion: 5, Deletion: 5, // NIP-09
Repost: 6, // NIP-18
Reaction: 7 // NIP-25 Reaction: 7 // NIP-25
}; };

View File

@ -42,7 +42,7 @@ export default class Tag {
ToObject() { ToObject() {
switch (this.Key) { switch (this.Key) {
case "e": { case "e": {
return ["e", this.Event, this.Relay, this.Marker].filter(a => a !== null); return ["e", this.Event, this.Relay, this.Marker];
} }
case "p": { case "p": {
return ["p", this.PubKey]; return ["p", this.PubKey];

View File

@ -8,8 +8,6 @@ export default class Thread {
this.ReplyTo = null; this.ReplyTo = null;
/** @type {Array<Tag>} */ /** @type {Array<Tag>} */
this.Mentions = []; this.Mentions = [];
/** @type {Event} */
this.Reply = null;
/** @type {Array<String>} */ /** @type {Array<String>} */
this.PubKeys = []; this.PubKeys = [];
} }
@ -25,7 +23,6 @@ export default class Thread {
} }
let ret = new Thread(); let ret = new Thread();
ret.Reply = ev;
let eTags = ev.Tags.filter(a => a.Key === "e"); let eTags = ev.Tags.filter(a => a.Key === "e");
let marked = eTags.some(a => a.Marker !== null); let marked = eTags.some(a => a.Marker !== null);
if (!marked) { if (!marked) {