mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 00:46:27 +03:00
Merge pull request #2761 from ecency/nt/wave-post-data
Nt/wave post data
This commit is contained in:
commit
369fe36f4d
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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<EditorContainerProps, any> {
|
||||
});
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user