Skip to content

Commit

Permalink
legacy: Comments fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
victorgcramos authored Aug 21, 2022
1 parent 6a92a9a commit 8bd4848
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/components/Proposal/Proposal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ const Proposal = React.memo(function Proposal({
<ChartsLink token={fullToken} />
)}
</div>
{extended && <MarkdownLink to={`/record/${shortToken}/raw`} />}
</Row>
)}
{extended && files.length > 1 && (
Expand Down Expand Up @@ -546,7 +545,7 @@ const Proposal = React.memo(function Proposal({
getVotesReceived(voteSummary) > 0 && (
<SearchVotes onClick={openSearchVotesModal} />
)}
{extended && (
{!isCensored && (isVetted || isAuthor || isAdmin) && (
<MarkdownLink to={`/record/${shortToken}/raw`} />
)}
</Row>
Expand Down
5 changes: 3 additions & 2 deletions src/containers/Comments/Comment/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const Comment = ({
const currentTimeSec = new Date().getTime() / 1000;
const isEditable =
authorID === userid &&
!disableReply &&
allowedits &&
currentTimeSec < createdAt + editperiod;
const remaining = createdAt + editperiod - currentTimeSec;
Expand Down Expand Up @@ -182,7 +183,7 @@ const Comment = ({
<DateTooltip timestamp={timestamp} placement="bottom">
{({ timeAgo }) => (
<Link className={styles.timeAgo} to={`${permalink}`}>
{version > 1 && <span>Edited </span>}
{version > 1 && <span>edited </span>}
{timeAgo}
</Link>
)}
Expand Down Expand Up @@ -284,7 +285,7 @@ Comment.propTypes = {
censored: PropTypes.bool,
censoredBy: PropTypes.string,
reason: PropTypes.string,
sectionId: PropTypes.string,
sectionId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
highlightAuthor: PropTypes.bool,
disableLikes: PropTypes.bool,
likesCount: PropTypes.number,
Expand Down
18 changes: 9 additions & 9 deletions src/containers/Proposal/Detail/Detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const ProposalDetail = ({ Main, match, history }) => {
proposalToken || tokenFromUrl
);
const areCommentsAllowed =
!isCensoredProposal(proposal) &&
!isVotingFinishedProposal(voteSummary) &&
!isAbandonedProposal(proposalSummary);
const areAuthorUpdatesAllowed = isActiveProposal(proposalSummary);
Expand Down Expand Up @@ -172,7 +173,12 @@ const ProposalDetail = ({ Main, match, history }) => {
const proposalComments = useMemo(
() => (
<>
{!(currentUser && isSingleThread) && (
{readOnly && (
<Message kind="blocked" title="Comments are not allowed">
{readOnlyReason}
</Message>
)}
{!(currentUser && isSingleThread) && !readOnly && (
<Card
className={classNames("container", styles.commentsHeaderWrapper)}
>
Expand All @@ -185,11 +191,6 @@ const ProposalDetail = ({ Main, match, history }) => {
}
>
<Or>
{readOnly && (
<Message kind="blocked" title="Comments are not allowed">
{readOnlyReason}
</Message>
)}
{!isPaid && paywallEnabled && currentUser && (
<Message kind="error">
<P>
Expand All @@ -200,7 +201,7 @@ const ProposalDetail = ({ Main, match, history }) => {
</P>
</Message>
)}
{!readOnly && !!identityError && <IdentityMessageError />}
{!!identityError && <IdentityMessageError />}
{areAuthorUpdatesAllowed && !isCurrentUserProposalAuthor && (
<Message>
Replies & upvotes/downvotes are allowed only on the latest
Expand Down Expand Up @@ -306,8 +307,7 @@ const ProposalDetail = ({ Main, match, history }) => {
</P>
</Message>
)}
{!isCensoredProposal(proposal) &&
!commentsLoading &&
{!commentsLoading &&
commentsFinishedLoading &&
proposalComments}
</>
Expand Down
7 changes: 6 additions & 1 deletion src/containers/Proposal/Detail/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
isAbandonedProposal,
isRejectedProposal,
isClosedProposal,
isCompletedProposal
isCompletedProposal,
isCensoredProposalSummary
} from "../helpers";

export const getCommentBlockedReason = (proposalSummary) => {
Expand All @@ -14,6 +15,10 @@ export const getCommentBlockedReason = (proposalSummary) => {
return "Voting has finished for this proposal. No additional changes are allowed.";
}

if (isCensoredProposalSummary(proposalSummary)) {
return "This proposal has been censored. No additional changes are allowed.";
}

if (isClosedProposal(proposalSummary)) {
return "Proposal is closed. No additional changes are allowed.";
}
Expand Down
12 changes: 12 additions & 0 deletions src/containers/Proposal/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
PROPOSAL_STATUS_CENSORED,
PROPOSAL_STATE_VETTED,
PROPOSAL_STATE_UNVETTED,
PROPOSAL_SUMMARY_STATUS_CENSORED,
PROPOSAL_SUMMARY_STATUS_CLOSED,
PROPOSAL_SUMMARY_STATUS_COMPLETED,
PROPOSAL_SUMMARY_STATUS_ACTIVE,
PROPOSAL_SUMMARY_STATUS_UNVETTED_ABANDONED,
PROPOSAL_SUMMARY_STATUS_UNVETTED_CENSORED,
PROPOSAL_SUMMARY_STATUS_ABANDONED,
PROPOSAL_SUMMARY_STATUS_REJECTED,
AUTHORIZED,
Expand Down Expand Up @@ -215,6 +217,16 @@ export const isAbandonedProposal = (proposalSummary) =>
(proposalSummary.status === PROPOSAL_SUMMARY_STATUS_ABANDONED ||
proposalSummary.status === PROPOSAL_SUMMARY_STATUS_UNVETTED_ABANDONED);

/**
* Returns true if the given proposal summary is censored
* @param {Object} proposalSummary
* @returns {Boolean} isCensored
*/
export const isCensoredProposalSummary = (proposalSummary) =>
!!proposalSummary &&
(proposalSummary.status === PROPOSAL_SUMMARY_STATUS_UNVETTED_CENSORED ||
proposalSummary.status === PROPOSAL_SUMMARY_STATUS_CENSORED);

/**
* Returns true if the given proposal is approved
* @param {Object} proposal
Expand Down
1 change: 1 addition & 0 deletions src/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ function PiPluginError(code, context) {
11: `Proposal domain is invalid, ${context}`,
15: `${context}`,
16: `${context}`,
17: "Comment replies are only allowed on the most recent author update thread",
18: "Author update title is missing"
};

Expand Down
14 changes: 8 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ export const isIdentityError = (error) => {
export function formatTimestampsFromMessage(msg) {
let newMsg = msg;
const timestamps = msg.match(/[0-9]+/g);
timestamps.forEach((t) => {
const formattedTime = formatDateToInternationalString(
formatUnixTimestampToObj(t)
);
newMsg = newMsg.replace(t, formattedTime);
});
if (timestamps) {
timestamps.forEach((t) => {
const formattedTime = formatDateToInternationalString(
formatUnixTimestampToObj(t)
);
newMsg = newMsg.replace(t, formattedTime);
});
}
return newMsg;
}

0 comments on commit 8bd4848

Please sign in to comment.