Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/apps/remark42/app/__stubs__/static-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ beforeEach(() => {
critical_score: -15,
low_score: -5,
edit_duration: 300,
admin_edit: false,
max_comment_size: 3000,
max_image_size: 5000,
positive_score: false,
Expand Down
1 change: 1 addition & 0 deletions frontend/apps/remark42/app/common/static-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const StaticStore: StaticStoreType = {
config: {
version: '',
edit_duration: 5000,
admin_edit: false,
max_comment_size: 5000,
admins: [],
admin_email: '',
Expand Down
1 change: 1 addition & 0 deletions frontend/apps/remark42/app/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface Config {
version: string;
auth_providers: Provider[];
edit_duration: number;
admin_edit: boolean;
max_comment_size: number;
admins: string[];
admin_email: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ export function CommentActions({
<Button kind="link" size="sm" onClick={onToggleEditing}>
{intl.formatMessage(editing ? messages.cancel : messages.edit)}
</Button>
<span
role="timer"
title={intl.formatMessage(messages.editCountdown)}
className={clsx('comment-actions-countdown', styles.countdown)}
>
<Countdown timestamp={editDeadline} onTimePassed={onDisableEditing} />
</span>
{Number.isFinite(editDeadline) && (
<span
role="timer"
title={intl.formatMessage(messages.editCountdown)}
className={clsx('comment-actions-countdown', styles.countdown)}
>
<Countdown timestamp={editDeadline} onTimePassed={onDisableEditing} />
</span>
)}
</>
)}
<div
Expand Down
19 changes: 13 additions & 6 deletions frontend/apps/remark42/app/components/comment/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ export class Comment extends Component<CommentProps, State> {

// set comment edit timer
if (this.isCurrentUser()) {
const editDuration = StaticStore.config.edit_duration;
const timeDiff = StaticStore.serverClientTimeDiff || 0;
const editDeadline = new Date(props.data.time).getTime() + timeDiff + editDuration * 1000;

newState.editDeadline = editDeadline > Date.now() ? editDeadline : undefined;
if (this.isAdmin() && StaticStore.config.admin_edit) {
newState.editDeadline = Infinity;
} else {
const editDuration = StaticStore.config.edit_duration;
const timeDiff = StaticStore.serverClientTimeDiff || 0;
const editDeadline = new Date(props.data.time).getTime() + timeDiff + editDuration * 1000;

newState.editDeadline = editDeadline > Date.now() ? editDeadline : undefined;
}
}

return newState;
Expand Down Expand Up @@ -488,7 +492,10 @@ export class Comment extends Component<CommentProps, State> {
copied={state.isCopied}
editing={isEditing}
replying={isReplying}
editable={props.repliesCount === 0 && state.editDeadline !== undefined}
editable={
state.editDeadline !== undefined &&
(props.repliesCount === 0 || (isAdmin && StaticStore.config.admin_edit))
}
editDeadline={state.editDeadline}
readOnly={props.post_info?.read_only}
onToggleReplying={this.toggleReplying}
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/api/clients/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Config {
version: string
auth_providers: Provider[]
edit_duration: number
admin_edit: boolean
max_comment_size: number
admins: string[]
admin_email: string
Expand Down Expand Up @@ -103,7 +104,7 @@ export function createPublicClient({ siteId: site, baseUrl }: ClientParams) {
async function getComments(url: string): Promise<CommentsTree>
async function getComments(params: GetUserCommentsParams): Promise<Comment[]>
async function getComments(
params: string | GetUserCommentsParams
params: string | GetUserCommentsParams,
): Promise<Comment[] | CommentsTree> {
if (typeof params === 'string') {
return fetcher.get('/comments', { url: params })
Expand Down