Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use post's replyRef instead of thread top post to stop stranded replies #56

Merged
merged 6 commits into from
Sep 17, 2023

Conversation

mozzius
Copy link
Owner

@mozzius mozzius commented Sep 15, 2023

Should fix the issue revealed by the more rigourous checks to replyRefs added recently

@vercel
Copy link

vercel bot commented Sep 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
graysky ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2023 11:08am

Comment on lines 50 to 85
const getReplyRef = (post: AppBskyFeedDefs.PostView) => {
if (AppBskyFeedPost.isRecord(post.record)) {
return post.record.reply;
}
};

export const useComposer = () => {
const router = useRouter();
const queryClient = useQueryClient();
return {
open: () => router.push("/composer"),
reply: (reply: {
parent: AppBskyFeedDefs.PostView;
root: AppBskyFeedDefs.PostView;
}) => {
queryClient.setQueryData(["context", reply.parent.uri], {
post: reply.parent,
reply: (post: AppBskyFeedDefs.PostView) => {
queryClient.setQueryData(["context", post.uri], {
post,
} satisfies AppBskyFeedDefs.ThreadViewPost);

const parent = {
uri: post.uri,
cid: post.cid,
} satisfies ComAtprotoRepoStrongRef.Main;

const root = getReplyRef(post)?.root ?? parent;

const replyRef = {
parent,
root,
} satisfies AppBskyFeedPost.ReplyRef;

router.push(
`/composer?reply=${encodeURIComponent(
JSON.stringify({
parent: {
uri: reply.parent.uri,
cid: reply.parent.cid,
},
root: {
uri: reply.root.uri,
cid: reply.root.cid,
},
} satisfies AppBskyFeedPost.ReplyRef),
)}`,
`/composer?reply=${encodeURIComponent(JSON.stringify(replyRef))}`,
);
},
quote: (post: AppBskyFeedDefs.PostView) =>
router.push(
`/composer?quote=${encodeURIComponent(
JSON.stringify({
uri: post.uri,
cid: post.cid,
}),
)}`,
),
quote: (ref: ComAtprotoRepoStrongRef.Main) =>
router.push(`/composer?quote=${encodeURIComponent(JSON.stringify(ref))}`),
};
};
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the relevant part

@mozzius mozzius merged commit ad975bb into main Sep 17, 2023
2 checks passed
@mozzius mozzius deleted the replyref-fix branch September 17, 2023 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant