Skip to content

Commit

Permalink
Merge pull request #9251 from hicommonwealth/tim/decode-content-clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros authored Oct 9, 2024
2 parents 3eb23f2 + 0e65943 commit 270c485
Show file tree
Hide file tree
Showing 33 changed files with 48 additions and 505 deletions.
3 changes: 0 additions & 3 deletions libs/model/src/comment/CreateComment.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
emitEvent,
emitMentions,
parseUserMentions,
quillToPlain,
uniqueMentions,
} from '../utils';
import { getCommentDepth } from '../utils/getCommentDepth';
Expand Down Expand Up @@ -57,7 +56,6 @@ export function CreateComment(): Command<
}

const text = decodeContent(payload.text);
const plaintext = quillToPlain(text);
const mentions = uniqueMentions(parseUserMentions(text));

const { contentUrl } = await uploadIfLarge('comments', text);
Expand All @@ -71,7 +69,6 @@ export function CreateComment(): Command<
thread_id,
parent_id: parent_id ? parent_id.toString() : null, // TODO: change parent_id from string to number
text,
plaintext,
address_id: address.id!,
reaction_count: 0,
reaction_weights_sum: 0,
Expand Down
3 changes: 0 additions & 3 deletions libs/model/src/comment/UpdateComment.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
emitMentions,
findMentionDiff,
parseUserMentions,
quillToPlain,
uniqueMentions,
uploadIfLarge,
} from '../utils';
Expand All @@ -32,7 +31,6 @@ export function UpdateComment(): Command<

if (currentVersion?.text !== payload.text) {
const text = decodeContent(payload.text);
const plaintext = quillToPlain(text);
const mentions = findMentionDiff(
parseUserMentions(currentVersion?.text),
uniqueMentions(parseUserMentions(text)),
Expand All @@ -46,7 +44,6 @@ export function UpdateComment(): Command<
// TODO: text should be set to truncatedBody once client renders content_url
{
text,
plaintext,
search: getCommentSearchVector(text),
content_url: contentUrl,
},
Expand Down
2 changes: 0 additions & 2 deletions libs/model/src/globalActivityCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export async function getActivityFeed(models: DB, id = 0) {
json_build_object(
'id', T.id,
'body', T.body,
'plaintext', T.plaintext,
'title', T.title,
'numberOfComments', T.comment_count,
'created_at', T.created_at,
Expand Down Expand Up @@ -63,7 +62,6 @@ export async function getActivityFeed(models: DB, id = 0) {
'id', C.id,
'address', A.address,
'text', C.text,
'plainText', C.plainText,
'created_at', C.created_at::text,
'updated_at', C.updated_at::text,
'deleted_at', C.deleted_at::text,
Expand Down
1 change: 0 additions & 1 deletion libs/model/src/models/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default (
address_id: { type: Sequelize.INTEGER, allowNull: true },
created_by: { type: Sequelize.STRING, allowNull: true },
text: { type: Sequelize.TEXT, allowNull: false },
plaintext: { type: Sequelize.TEXT, allowNull: true },

// canvas-related columns
canvas_signed_data: { type: Sequelize.JSONB, allowNull: true },
Expand Down
1 change: 0 additions & 1 deletion libs/model/src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default (
created_by: { type: Sequelize.STRING, allowNull: true },
title: { type: Sequelize.TEXT, allowNull: false },
body: { type: Sequelize.TEXT, allowNull: true },
plaintext: { type: Sequelize.TEXT, allowNull: true },
kind: { type: Sequelize.STRING, allowNull: false },
stage: {
type: Sequelize.TEXT,
Expand Down
4 changes: 0 additions & 4 deletions libs/model/src/tester/e2eSeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ export const e2eTestEntities = async function (
community_id: 'cmntest',
topic_id: -1,
kind: 'discussion',
plaintext: 'text',
stage: 'discussion',
view_count: 0,
reaction_count: 0,
Expand Down Expand Up @@ -231,7 +230,6 @@ export const e2eTestEntities = async function (
community_id: 'cmntest',
topic_id: -2,
kind: 'discussion',
plaintext: 'text',
stage: 'discussion',
view_count: 0,
reaction_count: 0,
Expand Down Expand Up @@ -277,7 +275,6 @@ export const e2eTestEntities = async function (
address_id: -1,
text: '',
thread_id: -1,
plaintext: '',
reaction_count: 0,
search: getCommentSearchVector(''),
},
Expand All @@ -300,7 +297,6 @@ export const e2eTestEntities = async function (
address_id: -2,
text: '',
thread_id: -2,
plaintext: '',
reaction_count: 0,
search: getCommentSearchVector(''),
},
Expand Down
3 changes: 0 additions & 3 deletions libs/model/src/thread/CreateThread.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
decodeContent,
emitMentions,
parseUserMentions,
quillToPlain,
uniqueMentions,
uploadIfLarge,
} from '../utils';
Expand Down Expand Up @@ -114,7 +113,6 @@ export function CreateThread(): Command<
}

const body = decodeContent(payload.body);
const plaintext = kind === 'discussion' ? quillToPlain(body) : body;
const mentions = uniqueMentions(parseUserMentions(body));

const { contentUrl } = await uploadIfLarge('threads', body);
Expand All @@ -130,7 +128,6 @@ export function CreateThread(): Command<
topic_id,
kind,
body,
plaintext,
view_count: 0,
comment_count: 0,
reaction_count: 0,
Expand Down
4 changes: 0 additions & 4 deletions libs/model/src/thread/UpdateThread.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
emitMentions,
findMentionDiff,
parseUserMentions,
quillToPlain,
sanitizeQuillText,
uploadIfLarge,
} from '../utils';

Expand Down Expand Up @@ -50,7 +48,6 @@ function getContentPatch(

if (typeof body !== 'undefined' && thread.kind === 'discussion') {
patch.body = decodeContent(body);
patch.plaintext = quillToPlain(sanitizeQuillText(body));
}

typeof url !== 'undefined' && thread.kind === 'link' && (patch.url = url);
Expand Down Expand Up @@ -355,7 +352,6 @@ export function UpdateThread(): Command<
'id',
'address_id',
'text',
['plaintext', 'plainText'],
'created_at',
'updated_at',
'deleted_at',
Expand Down
4 changes: 1 addition & 3 deletions libs/model/test/util-tests/getCommentDepth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ describe('getCommentDepth', () => {
});
const thread = await models.Thread.create({
community_id,
// @ts-expect-error StrictNullChecks
address_id: address.id,
address_id: address!.id!,
title: 'Testing',
plaintext: '',
kind: 'discussion',
search: getThreadSearchVector('Testing', ''),
});
Expand Down
1 change: 0 additions & 1 deletion libs/schemas/src/entities/comment.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const Comment = z.object({
thread_id: PG_INT,
address_id: PG_INT,
text: z.string(),
plaintext: z.string(),
parent_id: z.string().nullish(),
content_url: z.string().nullish(),

Expand Down
1 change: 0 additions & 1 deletion libs/schemas/src/entities/notification.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const CommentSubscription = z.object({
created_at: true,
updated_at: true,
text: true,
plaintext: true,
})
.merge(
z.object({
Expand Down
11 changes: 5 additions & 6 deletions libs/schemas/src/entities/thread.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ export const Thread = z.object({
address_id: PG_INT,
title: z.string(),
kind: z.string(),
stage: z.string(),
stage: z.string().optional(),
body: z.string().nullish(),
plaintext: z.string().nullish(),
url: z.string().nullish(),
topic_id: PG_INT.nullish(),
pinned: z.boolean().nullish(),
community_id: z.string(),
view_count: PG_INT,
view_count: PG_INT.optional(),
links: z.object(linksSchema).array().nullish(),
content_url: z.string().nullish(),

Expand All @@ -49,9 +48,9 @@ export const Thread = z.object({
discord_meta: DiscordMetaSchema.nullish(),

//counts
reaction_count: PG_INT,
reaction_weights_sum: PG_INT,
comment_count: PG_INT,
reaction_count: PG_INT.optional(),
reaction_weights_sum: PG_INT.optional(),
comment_count: PG_INT.optional().optional(),

activity_rank_date: z.coerce.date().nullish(),

Expand Down
1 change: 0 additions & 1 deletion libs/schemas/src/queries/thread.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const BulkThread = z.object({
collaborators: z.any().array(),
has_poll: z.boolean().nullable().optional(),
last_commented_on: z.date().nullable().optional(),
plaintext: z.string().nullable().optional(),
Address: z.object({
id: PG_INT,
address: z.string(),
Expand Down
3 changes: 0 additions & 3 deletions packages/commonwealth/client/scripts/models/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class Comment<T extends IUniqueId> {
public readonly author: string;
public readonly Address: AddressInfo;
public readonly text: string;
public readonly plaintext: string;
public reactions: Reaction[];
public reactionWeightsSum: number;
public readonly id: number;
Expand Down Expand Up @@ -49,7 +48,6 @@ export class Comment<T extends IUniqueId> {
Address,
thread_id,
parent_id,
plaintext,
reactions,
reaction_weights_sum,
created_at,
Expand All @@ -66,7 +64,6 @@ export class Comment<T extends IUniqueId> {
this.communityId = community_id;
this.author = Address?.address || author;
this.text = deleted_at?.length > 0 ? '[deleted]' : getDecodedString(text);
this.plaintext = deleted_at?.length > 0 ? '[deleted]' : plaintext;
this.versionHistory = versionHistory;
this.threadId = thread_id;
this.id = id;
Expand Down
7 changes: 0 additions & 7 deletions packages/commonwealth/client/scripts/models/Thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ type RecentComment = {
id: number;
address: string;
text: string;
plainText: string;
created_at: string;
updated_at: string;
marked_as_spam_at?: string;
Expand Down Expand Up @@ -233,7 +232,6 @@ export class Thread implements IUniqueId {
public readonly authorCommunity: string;
public readonly title: string;
public readonly body: string;
public readonly plaintext: string;
public pinned: boolean;
public readonly kind: ThreadKind;
public stage: ThreadStage;
Expand Down Expand Up @@ -289,7 +287,6 @@ export class Thread implements IUniqueId {
community_id,
read_only,
body,
plaintext,
url,
pinned,
collaborators,
Expand Down Expand Up @@ -336,7 +333,6 @@ export class Thread implements IUniqueId {
links?: Link[];
canvas_signed_data?: string;
canvas_msg_id?: string;
plaintext?: string;
collaborators?: any[];
last_edited: string;
locked_at: string;
Expand Down Expand Up @@ -375,8 +371,6 @@ export class Thread implements IUniqueId {
this.title = getDecodedString(title);
// @ts-expect-error StrictNullChecks
this.body = getDecodedString(body);
// @ts-expect-error StrictNullChecks
this.plaintext = plaintext;
this.id = id;
this.identifier = `${id}`;
this.createdAt = moment(created_at);
Expand Down Expand Up @@ -444,7 +438,6 @@ export class Thread implements IUniqueId {
author: rc?.address,
last_edited: rc?.updated_at ? moment(rc.updated_at) : null,
created_at: rc?.created_at ? moment(rc?.created_at) : null,
plaintext: rc?.plainText,
text: rc?.text,
Address: {
user_id: rc?.user_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const useDeleteCommentMutation = ({
id: response.comment_id,
deleted: true,
text: '[deleted]',
plaintext: '[deleted]',
versionHistory: [],
canvas_signed_data: response.canvas_signed_data,
canvas_msg_id: response.canvas_msg_id,
Expand Down
2 changes: 0 additions & 2 deletions packages/commonwealth/client/scripts/state/api/feeds/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type ActivityResponse = {
thread: {
id: number;
body: string;
plaintext: string;
title: string;
numberOfComments: number;
created_at: string;
Expand Down Expand Up @@ -54,7 +53,6 @@ export function formatActivityResponse(response: AxiosResponse<any, any>) {
body: x.thread.body,
discord_meta: x.thread.discord_meta,
numberOfComments: x.thread.numberOfComments,
plaintext: x.thread.plaintext,
read_only: x.thread.read_only,
archived_at: x.thread.archived_at,
// @ts-expect-error <StrictNullChecks/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const CommentSubscriptionEntry = (

<div className="SubscriptionFooter">
<CWThreadAction
label={pluralize(thread.comment_count, 'Comment')}
label={pluralize(thread.comment_count!, 'Comment')}
action="comment"
onClick={(e) => {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const ThreadSubscriptionEntry = (

<div className="SubscriptionFooter">
<CWThreadAction
label={pluralize(thread.comment_count, 'Comment')}
label={pluralize(thread.comment_count!, 'Comment')}
action="comment"
onClick={(e) => {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export const NewSnapshotProposalForm = ({
useEffect(() => {
const init = async () => {
const initialForm: ThreadForm = {
name: !thread ? '' : thread.title,
body: !thread ? '' : thread.plaintext,
name: thread?.title || '',
body: thread?.body || '',
choices: ['Yes', 'No'],
range: '5d',
start: new Date().getTime(),
Expand All @@ -121,13 +121,10 @@ export const NewSnapshotProposalForm = ({

const linkMarkdown = `${linkText}[here](${linkUrl})`;

const delta = createDeltaFromText(
thread.plaintext + linkMarkdown,
true,
);
const delta = createDeltaFromText(thread.body + linkMarkdown, true);
setContentDelta(delta);
} else {
const delta = createDeltaFromText(thread.plaintext);
const delta = createDeltaFromText(thread.body);
setContentDelta(delta);
}
}
Expand Down
Loading

0 comments on commit 270c485

Please sign in to comment.