mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 00:35:56 +08:00
[CORL-1230] corrects logic for editing comments with media attachments (#3063)
* correctly attach media to edited comments * ensure media can be removed in edits * fix: updates to support repeat post Co-authored-by: Kim Gardner <kgardnr@gmail.com> Co-authored-by: Wyatt Johnson <wyattjoh@gmail.com>
This commit is contained in:
@@ -16,6 +16,8 @@ import {
|
||||
|
||||
export const repeatPost: IntermediateModerationPhase = async ({
|
||||
mongo,
|
||||
comment,
|
||||
action,
|
||||
bodyText,
|
||||
tenant,
|
||||
author,
|
||||
@@ -44,6 +46,12 @@ export const repeatPost: IntermediateModerationPhase = async ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "EDIT" && comment.id && comment.id === lastComment.id) {
|
||||
// The last comment written is this comment because we're editing, so no
|
||||
// need to compare against.
|
||||
return;
|
||||
}
|
||||
|
||||
const lastCommentRevision = getLatestRevision(lastComment);
|
||||
const lastCommentBodyText = getHTMLPlainText(lastCommentRevision.body);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ export interface ModerationPhaseContextInput {
|
||||
comment: RequireProperty<
|
||||
Partial<Omit<CreateCommentInput, "media">>,
|
||||
"body" | "ancestorIDs"
|
||||
>;
|
||||
> & {
|
||||
/**
|
||||
* id is used to provide the comment ID in the event this is a EDIT action.
|
||||
*/
|
||||
id?: string;
|
||||
};
|
||||
author: User;
|
||||
now: Date;
|
||||
action: "NEW" | "EDIT";
|
||||
|
||||
@@ -14,6 +14,7 @@ import { createCommentModerationAction } from "coral-server/models/action/modera
|
||||
import {
|
||||
editComment,
|
||||
EditCommentInput,
|
||||
getLatestRevision,
|
||||
GiphyMedia,
|
||||
retrieveComment,
|
||||
TwitterMedia,
|
||||
@@ -110,10 +111,22 @@ export default async function edit(
|
||||
throw new StoryNotFoundError(originalStaleComment.storyID);
|
||||
}
|
||||
|
||||
const lastRevision = getLatestRevision(originalStaleComment);
|
||||
|
||||
let media: GiphyMedia | TwitterMedia | YouTubeMedia | undefined;
|
||||
|
||||
// attach a new media object from input IF:
|
||||
// input.media is defined AND EITHER:
|
||||
// - previous revision has no media OR
|
||||
// - previous revision has media with a different URL
|
||||
// otherwise, attach previous revision media if present
|
||||
|
||||
if (input.media) {
|
||||
// TODO: (wyattjoh) check to see if the media is the same.
|
||||
media = await attachMedia(tenant, input.media, input.body);
|
||||
if (!lastRevision.media || lastRevision.media.url !== input.media.url) {
|
||||
media = await attachMedia(tenant, input.media, input.body);
|
||||
} else if (lastRevision.media) {
|
||||
media = lastRevision.media;
|
||||
}
|
||||
}
|
||||
|
||||
// Run the comment through the moderation phases.
|
||||
|
||||
Reference in New Issue
Block a user