Get your own comments and votes
Get your own comments and votes in Bitsocial React Hooks. Usage, options, and examples.
// all my own comments
const { accountComments } = useAccountComments();
for (const accountComment of accountComments) {
// it is recommended to show a label in the UI if accountComment.state is 'pending' or 'failed'
console.log("comment", accountComment.index, "is status", accountComment.state);
}
// `state` becomes `failed` as soon as a pending local publish records terminal failure (`publishingState === "failed"` and `state === "stopped"`) or a final publish error, instead of waiting for the 20-minute fallback. An error pkc-js recovers from is in the comment's `error` and `errors` but leaves it `pending` (see "Final and recoverable publish errors" under Actions Hooks).
// local account comments returned by useAccountComment and useAccountComments include the account author's address and shortAddress when an older cached account comment is missing author identity fields.
// comments published in a pseudonymous community (comment.pseudonymityMode is set) keep their community-assigned author instead, because the account identity was never published.
// a pending reply published without `postCid` gets it from its parent when the parent is already loaded (the parent's `postCid`, or the parent's `cid` when the parent is a post), so it can link to its thread before it has a cid; it stays undefined when the parent isn't loaded. This is local metadata: the published reply contains only the `postCid` passed to `publishComment`.
// note: accountComment.index can change after deletions; prefer commentCid for stable identifiers
// all my own votes
const { accountVotes } = useAccountVotes();
// account votes and account edits (useAccountVotes, useAccountVote, useAccountEdits and their filters) include `shortCommunityAddress` next to `communityAddress`, also for history stored by earlier versions. It is derived when read, not stored or exported. They are stored without their author, so they have no `author.shortAddress`.
// my own comments in memes.bso
const communityAddress = "memes.bso";
const myCommentsInMemesEth = useAccountComments({ communityAddress });
// my own posts in memes.bso
const filter = useCallback(
(comment) => comment.communityAddress === communityAddress && !comment.parentCid,
[communityAddress],
);
const myPostsInMemesEth = useAccountComments({ filter });
// my own replies in a post with cid 'Qm...'
const postCid = "Qm...";
const filter = useCallback((comment) => comment.postCid === postCid, [postCid]);
const myCommentsInSomePost = useAccountComments({ filter });
// my own replies to a comment with cid 'Qm...'
const parentCommentCid = "Qm...";
const myRepliesToSomeComment = useAccountComments({ parentCid: parentCommentCid });
// recent own comments in memes.bso, newest first, one page at a time
const recentMyCommentsInMemesEth = useAccountComments({
communityAddress,
newerThan: 60 * 60 * 24 * 30,
sortType: "new",
page: 0,
pageSize: 20,
});
// get one own comment directly by cid
const accountComment = useAccountComment({ commentCid: "Qm..." });
// get a specific set of own comments by account comment index
const replacementReplies = useAccountComments({ commentIndices: [5, 7, 9] });
// voted profile tab helpers
const recentUpvotes = useAccountVotes({
vote: 1,
newerThan: 60 * 60 * 24 * 30,
sortType: "new",
page: 0,
pageSize: 20,
});
// know if you upvoted a comment already with cid 'Qm...'
const { vote } = useAccountVote({ commentCid: "Qm..." });
console.log(vote); // 1, -1 or 0
// my own pending posts in a feed
const { feed } = useFeed({
communities: [{ name: communityAddress }],
accountComments: { newerThan: Infinity, append: false },
});
// my own pending replies in a replies feed
const { replies } = useReplies({
comment: post,
accountComments: { newerThan: Infinity, append: false },
});
// only add my 3 newest posts, and my 3 newest replies to that comment. limit counts the
// account comments that match (community or parent comment, accountComments.newerThan),
// newest first by timestamp, including the ones the feed already loaded from the network
// (those are never added twice). Omit limit to add them all, a new account comment over
// the limit replaces the oldest added one. Only the added account comments are limited,
// never the posts and replies loaded from the network
const { feed: feedWithLimit } = useFeed({
communities: [{ name: communityAddress }],
accountComments: { newerThan: Infinity, limit: 3 },
});
const { replies: repliesWithLimit } = useReplies({
comment: post,
accountComments: { newerThan: Infinity, limit: 3 },
});
// pending local account comments are reconciled with their approved network version
// so the same post or reply is not shown twice after moderation approval
// published account replies stay visible and are deduplicated by cid while
// canonical replies propagate; explicitly purged replies are hidden after an
// exhausted canonical feed refreshes past their timestamp