Skip to content

Commit

Permalink
Various reads fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
moysa committed Dec 19, 2024
1 parent 5552e84 commit c565556
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/HomeSidebar/ArticleSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ArticleSidebar: Component< { id?: string, user: PrimalUser, article: Prima
const recs = articles.filter(a => a.id !== props.article.id);
const indicies = getRandomIntegers(0, recs.length, 3);

setRecomended(() => indicies.map(i => recs[i]));
setRecomended(() => indicies.map(i => recs[i]).sort((a, b) => b.published - a.published));

setIsFetchingArticles(() => false);
}
Expand Down
48 changes: 47 additions & 1 deletion src/components/NewNote/EditBox/EditBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,53 @@ const EditBox: Component<{
let tags = referencesToTags(messageToSend, relayHints);
const rep = props.replyToNote;

if (rep) {
// @ts-ignore
if (rep && rep.naddr) {
let rootTag = rep.msg.tags.find(t => t[0] === 'a' && t[3] === 'root');

const rHints = (rep.relayHints && rep.relayHints[rep.id]) ?
rep.relayHints[rep.id] :
'';

const decoded = nip19.decode(rep.naddr);

const data = decoded.data as nip19.AddressPointer;

const coord = `${data.kind}:${data.pubkey}:${data.identifier}`;

// If the note has a root tag, that meens it is not a root note itself
// So we need to copy the `root` tag and add a `reply` tag
if (rootTag) {
const tagWithHint = rootTag.map((v, i) => i === 2 ?
rHints :
v,
);
tags.push([...tagWithHint]);
tags.push(['a', coord, rHints, 'reply']);
}
// Otherwise, add the note as the root tag for this reply
else {
tags.push([
'a',
coord,
rHints,
'root',
]);
}

// Copy all `p` tags from the note we are repling to
const repPeople = rep.msg.tags.filter(t => t[0] === 'p');

tags = [...tags, ...(unwrap(repPeople))];

// If the author of the note is missing, add them
if (!tags.find(t => t[0] === 'p' && t[1] === rep.pubkey)) {
tags.push(['p', rep.pubkey]);
}
}

// @ts-ignore
if (rep && !rep.naddr) {
let rootTag = rep.msg.tags.find(t => t[0] === 'e' && t[3] === 'root');

const rHints = (rep.relayHints && rep.relayHints[rep.id]) ?
Expand Down
11 changes: 10 additions & 1 deletion src/components/Note/MentionedUserLink/MentionedUserLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const MentionedUserLink: Component<{

const LinkComponent: Component<{ children: JSXElement }> = (p) => {

if (!props.user && props.npub) {
return <A
id={props.id}
class={styles.userMention}
href={app?.actions.profileLink(props.npub) || ''}
>
{p.children}
</A>;
}
if (!props.user) {
return <div
id={props.id}
Expand Down Expand Up @@ -63,7 +72,7 @@ const MentionedUserLink: Component<{

return (
<LinkComponent>
@{userName(props.user) || 'UNKNOWN'}
@{userName(props.user) || props.npub || 'UNKNOWN'}
</LinkComponent>
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/components/Note/Note.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { A } from '@solidjs/router';
import { batch, Component, createEffect, Match, onMount, Show, Switch } from 'solid-js';
import { PrimalNote, TopZap, ZapOption } from '../../types/primal';
import { PrimalNote, PrimalUser, TopZap, ZapOption } from '../../types/primal';
import ParsedNote from '../ParsedNote/ParsedNote';
import NoteFooter from './NoteFooter/NoteFooter';

Expand Down Expand Up @@ -53,6 +53,7 @@ const Note: Component<{
onClick?: () => void,
quoteCount?: number,
size?: 'xwide' | 'wide' | 'normal' | 'short',
defaultParentAuthor?: PrimalUser,
}> = (props) => {

const threadContext = useThreadContext();
Expand Down Expand Up @@ -431,7 +432,7 @@ const Note: Component<{
</div>
</div>

<NoteReplyToHeader note={props.note} />
<NoteReplyToHeader note={props.note} defaultParentAuthor={props.defaultParentAuthor} />

<div class={`${styles.message} ${bigMessageFont() ? styles.bigFont : ''}`}>
<ParsedNote
Expand Down Expand Up @@ -500,7 +501,7 @@ const Note: Component<{
/>
</div>

<NoteReplyToHeader note={props.note} />
<NoteReplyToHeader note={props.note} defaultParentAuthor={props.defaultParentAuthor} />

<div class={styles.message}>
<ParsedNote
Expand Down Expand Up @@ -562,7 +563,7 @@ const Note: Component<{
time={props.note.post.created_at}
/>

<NoteReplyToHeader note={props.note} />
<NoteReplyToHeader note={props.note} defaultParentAuthor={props.defaultParentAuthor} />

<div class={styles.message}>
<ParsedNote
Expand Down
2 changes: 1 addition & 1 deletion src/components/Note/NoteFooter/NoteFooter.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}

&.xwide {
grid-template-columns: 153px 153px 153px 153px auto;
grid-template-columns: 145px 145px 145px 145px auto;

.bookmarkFoot {
display: flex;
Expand Down
33 changes: 30 additions & 3 deletions src/components/Note/NoteReplyToHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
import { Component, createMemo, Show } from 'solid-js';
import { PrimalNote } from '../../types/primal';
import { PrimalNote, PrimalUser } from '../../types/primal';


import styles from './Note.module.scss';
import { useIntl } from '@cookbook/solid-intl';
import { note as t } from '../../translations';
import { hookForDev } from '../../lib/devTools';
import MentionedUserLink from './MentionedUserLink/MentionedUserLink';
import { hexToNpub } from '../../lib/keys';
import { nip19 } from 'nostr-tools';

const NoteReplyHeader: Component<{
note: PrimalNote,
id?: string,
defaultParentAuthor?: PrimalUser,
}> = (props) => {
const intl = useIntl();

const rootAuthor = createMemo(() => {
const replyTo = props.note.replyTo;
const mentions = props.note.mentionedNotes;
const mentionedReads = props.note.mentionedArticles;


if (replyTo && mentions && mentions[replyTo]) {
return mentions[replyTo].user;
return mentions[replyTo].user || props.defaultParentAuthor;
}

if (replyTo && mentionedReads) {
const [kind, pubkey, identifier] = replyTo.split(':');

try {
const naddr = nip19.naddrEncode({
kind: parseInt(kind),
pubkey,
identifier
})

return mentionedReads[naddr] ? mentionedReads[naddr].user : props.defaultParentAuthor;
} catch {
return props.defaultParentAuthor;
}
}

return props.defaultParentAuthor;

});

return (
Expand All @@ -29,7 +53,10 @@ const NoteReplyHeader: Component<{
<span class={styles.label}>
{intl.formatMessage(t.reply)}
</span>&nbsp;
<MentionedUserLink user={rootAuthor()} />
<MentionedUserLink
user={rootAuthor()}
npub={hexToNpub(props.note.replyTo)}
/>
</span>
</Show>
)
Expand Down
11 changes: 10 additions & 1 deletion src/components/PrimalMarkdown/MarkdownSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ const MarkdownSlice: Component<{
.use(history)
.create();

insert(props.content)(e.ctx);

const regex = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g;

const cont = props.content.replace(regex, (e) => {
const arr = e.split('@');

return `${arr[0]}&#8203;@${arr[1]}`;
});

insert(cont)(e.ctx);
setHtml(() => getHTML()(e.ctx));

setEditor(() => e);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReplyToNote/ReplyToNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useAccountContext } from "../../contexts/AccountContext";
import { hookForDev } from "../../lib/devTools";
import { userName } from "../../stores/profile";
import { actions as t } from "../../translations";
import { PrimalNote, SendNoteResult } from "../../types/primal";
import { PrimalArticle, PrimalNote, SendNoteResult } from "../../types/primal";
import Avatar from "../Avatar/Avatar";
import EditBox from "../NewNote/EditBox/EditBox";
import styles from "./ReplyToNote.module.scss";


const ReplyToNote: Component<{
note: PrimalNote,
note: PrimalNote | PrimalArticle,
onNotePosted?: (note: SendNoteResult) => void,
id?: string,
}> = (props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Longform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ const Longform: Component< { naddr: string } > = (props) => {

<div>
<For each={store.replies}>
{reply => <Note note={reply} noteType='thread' shorten={true} size="xwide" />}
{reply => <Note note={reply} noteType='thread' shorten={true} size="xwide" defaultParentAuthor={store.article?.user} />}
</For>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/stores/megaFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const extractReplyTo = (tags: string[][]) => {
for (let i=0; i<tags.length; i++) {
const tag = tags[i];

if (tag[0] !== 'e') continue;
if (!['e', 'a'].includes(tag[0])) continue;

if (tag[3] === 'mention') continue;

Expand All @@ -114,10 +114,14 @@ export const extractReplyTo = (tags: string[][]) => {

if (!replyTo) {
const eTags = tags.filter(t => t[0] === 'e' && t[3] !== 'mention');
const aTags = tags.filter(t => t[0] === 'a' && t[3] !== 'mention');

if (eTags.length === 1) {
replyTo = [...eTags[0]];
}
else if (eTags.length > 1){
replyTo = [...aTags[aTags.length - 1]];
}
else if (eTags.length > 1){
replyTo = [...eTags[eTags.length - 1]];
}
Expand Down

0 comments on commit c565556

Please sign in to comment.