mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-30 17:14:22 +03:00
updated post update functions
This commit is contained in:
parent
0bfe671f70
commit
1351507f5c
@ -1,4 +1,3 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { Client, PrivateKey } from 'dsteem';
|
||||
import steemConnect from 'steemconnect';
|
||||
import Config from 'react-native-config';
|
||||
@ -348,19 +347,6 @@ export const getPurePost = async (author, permlink) => {
|
||||
}
|
||||
};
|
||||
|
||||
// export const deleteComment = (author, permlink) => {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// client.database
|
||||
// .call('delete_comment', [author, permlink])
|
||||
// .then((response) => {
|
||||
// resolve(response);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// reject(error);
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
|
||||
export const deleteComment = (currentAccount, pin, permlink) => {
|
||||
const { name: author } = currentAccount;
|
||||
const digitPinCode = getDigitPinCode(pin);
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
makeOptions,
|
||||
extractMetadata,
|
||||
makeJsonMetadataReply,
|
||||
makeJsonMetadataForUpdate,
|
||||
createPatch,
|
||||
} from '../../../utils/editor';
|
||||
// import { generateSignature } from '../../../utils/image';
|
||||
@ -153,8 +154,6 @@ class EditorContainer extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
// Media select functions <- START ->
|
||||
|
||||
_handleOpenImagePicker = () => {
|
||||
ImagePicker.openPicker({
|
||||
includeBase64: true,
|
||||
@ -424,38 +423,39 @@ class EditorContainer extends Component {
|
||||
const { post } = this.state;
|
||||
if (currentAccount) {
|
||||
this.setState({ isPostSending: true });
|
||||
|
||||
const { tags, body, title } = fields;
|
||||
const {
|
||||
body: oldBody,
|
||||
parent_permlink: parentPermlink,
|
||||
permlink,
|
||||
parent_author: parentAuthor,
|
||||
json_metadata: oldMeta,
|
||||
json_metadata: jsonMetadata,
|
||||
} = post;
|
||||
|
||||
let newBody = fields.body;
|
||||
let _oldMeta = oldMeta;
|
||||
let newBody = body;
|
||||
const patch = createPatch(oldBody, newBody.trim());
|
||||
|
||||
if (patch && patch.length < Buffer.from(oldBody, 'utf-8').length) {
|
||||
newBody = patch;
|
||||
}
|
||||
|
||||
if (typeof _oldMeta === 'string') {
|
||||
_oldMeta = JSON.parse(_oldMeta);
|
||||
}
|
||||
|
||||
const meta = extractMetadata(fields.body);
|
||||
const metadata = Object.assign({}, _oldMeta, meta);
|
||||
const jsonMeta = makeJsonMetadata(metadata, fields.tags);
|
||||
|
||||
let jsonMeta = {};
|
||||
|
||||
try {
|
||||
const oldJson = JSON.parse(jsonMetadata);
|
||||
jsonMeta = makeJsonMetadataForUpdate(oldJson, meta, tags);
|
||||
} catch (e) {
|
||||
jsonMeta = makeJsonMetadata(meta, tags);
|
||||
}
|
||||
|
||||
await postContent(
|
||||
currentAccount,
|
||||
pinCode,
|
||||
parentAuthor || '',
|
||||
'',
|
||||
parentPermlink,
|
||||
permlink,
|
||||
fields.title,
|
||||
title,
|
||||
newBody,
|
||||
jsonMeta,
|
||||
)
|
||||
|
@ -1,5 +1,8 @@
|
||||
import getSlug from 'speakingurl';
|
||||
import { diff_match_patch } from 'diff-match-patch';
|
||||
import { diff_match_patch as diffMatchPatch } from 'diff-match-patch';
|
||||
import PackageJson from '../../../../package.json';
|
||||
|
||||
const { version } = PackageJson;
|
||||
|
||||
export const getWordsCount = text => (text && typeof text === 'string' ? text.replace(/^\s+|\s+$/g, '').split(/\s+/).length : 0);
|
||||
|
||||
@ -86,18 +89,25 @@ export const makeOptions = (author, permlink, operationType) => {
|
||||
|
||||
export const makeJsonMetadataReply = tags => ({
|
||||
tags,
|
||||
app: 'esteem/2.0.0-mobile',
|
||||
app: `esteem/${version}-mobile`,
|
||||
format: 'markdown+html',
|
||||
community: 'esteem.app',
|
||||
});
|
||||
|
||||
export const makeJsonMetadata = (meta, tags) => Object.assign({}, meta, {
|
||||
tags,
|
||||
app: 'esteem/2.0.0-mobile',
|
||||
app: `esteem/${version}-mobile`,
|
||||
format: 'markdown+html',
|
||||
community: 'esteem.app',
|
||||
});
|
||||
|
||||
export const makeJsonMetadataForUpdate = (oldJson, meta, tags) => {
|
||||
const { meta: oldMeta } = oldJson;
|
||||
const mergedMeta = Object.assign({}, oldMeta, meta);
|
||||
|
||||
return Object.assign({}, oldJson, mergedMeta, { tags });
|
||||
};
|
||||
|
||||
export const extractMetadata = (body) => {
|
||||
const urlReg = /(\b(https?|ftp):\/\/[A-Z0-9+&@#/%?=~_|!:,.;-]*[-A-Z0-9+&@#/%=~_|])/gim;
|
||||
const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim;
|
||||
@ -146,7 +156,7 @@ export const extractMetadata = (body) => {
|
||||
export const createPatch = (text1, text2) => {
|
||||
if (!text1 && text1 === '') return undefined;
|
||||
|
||||
const dmp = new diff_match_patch();
|
||||
const dmp = new diffMatchPatch();
|
||||
const patches = dmp.patch_make(text1, text2);
|
||||
const patch = dmp.patch_toText(patches);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user