diff --git a/src/components/quickReplyModal/usePostSubmitter.ts b/src/components/quickReplyModal/usePostSubmitter.ts index 9b016584bb..b0ce005ea9 100644 --- a/src/components/quickReplyModal/usePostSubmitter.ts +++ b/src/components/quickReplyModal/usePostSubmitter.ts @@ -1,7 +1,7 @@ import { useDispatch } from "react-redux"; import { useAppSelector } from "../../hooks"; import { postComment } from "../../providers/hive/dhive"; -import { extractMetadata, generateReplyPermlink, makeJsonMetadata } from "../../utils/editor"; +import { extractMetadata, generateUniquePermlink, makeJsonMetadata } from "../../utils/editor"; import { Alert } from "react-native"; import { updateCommentCache } from "../../redux/actions/cacheActions"; import { toastNotification } from "../../redux/actions/uiAction"; @@ -10,6 +10,7 @@ import { useState } from "react"; import { useUserActivityMutation, wavesQueries } from "../../providers/queries"; import { PointActivityIds } from "../../providers/ecency/ecency.types"; import { usePublishWaveMutation } from "../../providers/queries/postQueries/wavesQueries"; +import { PostTypes } from "../../constants/postTypes"; export const usePostSubmitter = () => { @@ -27,9 +28,9 @@ export const usePostSubmitter = () => { // handle submit reply - const _submitReply = async (commentBody: string, parentPost: any) => { + const _submitReply = async (commentBody: string, parentPost: any, postType: PostTypes = PostTypes.COMMENT) => { if (!commentBody) { - return false ; + return false; } if (isSending) { return false; @@ -38,7 +39,11 @@ export const usePostSubmitter = () => { if (currentAccount) { setIsSending(true); - const permlink = generateReplyPermlink(parentPost.author); + const _prefix = postType === PostTypes.WAVE + ? postType + : `re-${parentPost.author.replace(/\./g, '')}` + const permlink = generateUniquePermlink(_prefix); + const author = currentAccount.name; const parentAuthor = parentPost.author; const parentPermlink = parentPost.permlink; @@ -48,8 +53,9 @@ export const usePostSubmitter = () => { //adding jsonmeta with image ratios here.... const meta = await extractMetadata({ - body:commentBody, - fetchRatios:true + body: commentBody, + fetchRatios: true, + postType }) const jsonMetadata = makeJsonMetadata(meta, parentTags || ['ecency']) @@ -91,7 +97,7 @@ export const usePostSubmitter = () => { ); // add comment cache entry - const _cacheCommentData = { + const _cacheCommentData = { author, permlink, url, @@ -100,7 +106,7 @@ export const usePostSubmitter = () => { markdownBody: commentBody, json_metadata: jsonMetadata } - + dispatch( updateCommentCache( `${author}/${permlink}`, @@ -137,15 +143,15 @@ export const usePostSubmitter = () => { //feteced lates wafves container and post wave to that container - const _submitWave = async (body:string) => { + const _submitWave = async (body: string) => { try { const _wavesHost = 'ecency.waves' //TODO: make waves host selection dynamic const latestWavesPost = await wavesQueries.fetchLatestWavesContainer(_wavesHost); - const _cacheCommentData = await _submitReply(body, latestWavesPost) + const _cacheCommentData = await _submitReply(body, latestWavesPost, PostTypes.WAVE) - if(_cacheCommentData){ + if (_cacheCommentData) { pusblishWaveMutation.mutate(_cacheCommentData) } diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index a0b340c743..ceec7996c2 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -26,7 +26,7 @@ import { default as ROUTES } from '../../../constants/routeNames'; // Utilities import { generatePermlink, - generateReplyPermlink, + generateUniquePermlink, makeJsonMetadata, makeOptions, extractMetadata, @@ -707,7 +707,9 @@ class EditorContainer extends Component { }); const { post } = this.state; - const permlink = generateReplyPermlink(post.author); + + const _prefix = `re-${post.author.replace(/\./g, '')}` + const permlink = generateUniquePermlink(_prefix); const parentAuthor = post.author; const parentPermlink = post.permlink; diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 0edd1ebcc7..aefc704d09 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -3,6 +3,7 @@ import { Image } from 'react-native'; import { diff_match_patch as diffMatchPatch } from 'diff-match-patch'; import VersionNumber from 'react-native-version-number'; import MimeTypes from 'mime-types'; +import { PostTypes } from '../constants/postTypes'; export const getWordsCount = (text) => text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0; @@ -80,8 +81,8 @@ export const extractWordAtIndex = (text: string, index: number) => { return word; }; -export const generateReplyPermlink = (toAuthor) => { - if (!toAuthor) { +export const generateUniquePermlink = (prefix) => { + if (!prefix) { return ''; } @@ -93,7 +94,7 @@ export const generateReplyPermlink = (toAuthor) => { .getSeconds() .toString()}${t.getMilliseconds().toString()}z`; - return `re-${toAuthor.replace(/\./g, '')}-${timeFormat}`; + return `${prefix}-${timeFormat}`; }; export const makeOptions = (postObj) => { @@ -214,10 +215,12 @@ export const extractMetadata = async ({ body, thumbUrl, fetchRatios, + postType, }: { body: string; thumbUrl?: string; fetchRatios?: boolean; + postType?: PostTypes; }) => { // NOTE: keepting regex to extract usernames as reference for later usage if any // const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim; @@ -254,6 +257,10 @@ export const extractMetadata = async ({ ); } + //setting post type, primary usecase for separating waves from other posts + out.type = postType || PostTypes.POST + + return out; };