Skip to content

Commit

Permalink
thread creation + edit without encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros committed Sep 11, 2024
1 parent 5b6bd90 commit de2d6a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
11 changes: 2 additions & 9 deletions libs/model/src/thread/CreateThread.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ import { verifyThreadSignature } from '../middleware/canvas';
import { mustBeAuthorized } from '../middleware/guards';
import { getThreadSearchVector } from '../models/thread';
import { tokenBalanceCache } from '../services';
import {
emitMentions,
parseUserMentions,
quillToPlain,
sanitizeQuillText,
uniqueMentions,
} from '../utils';
import { emitMentions, parseUserMentions, uniqueMentions } from '../utils';

export const CreateThreadErrors = {
InsufficientTokenBalance: 'Insufficient token balance',
Expand Down Expand Up @@ -112,8 +106,7 @@ export function CreateThread(): Command<
checkContestLimits(activeContestManagers, actor.address!);
}

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

// == mutation transaction boundary ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const buildCreateThreadInput = async ({
community_id: communityId,
topic_id: topic.id,
title: encodeURIComponent(title),
body: encodeURIComponent(body ?? ''),
body: body ?? '',
kind,
stage,
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const editThread = async ({
jwt: userStore.getState().jwt,
// for edit profile
...(url && { url }),
...(newBody && { body: encodeURIComponent(newBody) }),
...(newBody && { body: newBody }),
...(newTitle && { title: encodeURIComponent(newTitle) }),
...(authorProfile && { author: JSON.stringify(authorProfile) }),
// for editing thread locked status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { openConfirmation } from 'views/modals/confirmation_modal';
import type Thread from '../../../models/Thread';
import { CWButton } from '../../components/component_kit/new_designs/CWButton';
import { ReactQuillEditor } from '../../components/react_quill_editor';
import { deserializeDelta } from '../../components/react_quill_editor/utils';
import {
deserializeDelta,
serializeDelta,
} from '../../components/react_quill_editor/utils';
import { clearEditingLocalStorage } from '../discussions/CommentTree/helpers';

type EditBodyProps = {
Expand Down Expand Up @@ -93,7 +96,7 @@ export const EditBody = (props: EditBodyProps) => {
try {
const newBody = JSON.stringify(contentDelta);
await editThread({
newBody: JSON.stringify(contentDelta) || thread.body,
newBody: serializeDelta(contentDelta) || thread.body,
newTitle: title || thread.title,
threadId: thread.id,
authorProfile: user.activeAccount?.profile,
Expand Down

0 comments on commit de2d6a1

Please sign in to comment.