support for handling updated, created and markdownBody

This commit is contained in:
noumantahir 2022-01-29 23:11:43 +05:00
parent 2cb6cf7c93
commit 3fc343eb81
2 changed files with 27 additions and 6 deletions

View File

@ -1,3 +1,5 @@
import { renderPostBody } from '@ecency/render-helper';
import { Platform } from 'react-native';
import {
UPDATE_VOTE_CACHE,
PURGE_EXPIRED_CACHE,
@ -15,15 +17,32 @@ import { Comment, Vote } from '../reducers/cacheReducer';
})
export const updateCommentCache = (commentPath:string, comment:Comment) => {
export const updateCommentCache = (commentPath:string, comment:Comment, isUpdate:boolean = false) => {
comment.created = comment.created || new Date().toISOString();
comment.expiresAt = comment.expiresAt || new Date().getTime() + 600000;
console.log("body received:", comment.markdownBody);
const updated = new Date();
updated.setSeconds(updated.getSeconds() - 5); //make cache delayed by 5 seconds to avoid same updated stamp in post data
const updatedStamp = updated.toISOString().substring(0, 19); //server only return 19 character time string without timezone part
if(isUpdate && !comment.created){
throw new Error("For comment update, created prop must be provided from original comment data to update local cache");
}
comment.created = comment.created || updatedStamp; //created will be set only once for new comment;
comment.updated = comment.updated || updatedStamp;
comment.expiresAt = comment.expiresAt || updated.getTime() + 6000000;//600000;
comment.active_votes = comment.active_votes || [];
comment.net_rshares = comment.net_rshares || 0;
comment.author_reputation = comment.author_reputation || 25;
comment.total_payout = comment.total_payout || 0;
comment.body = renderPostBody({
author:comment.author,
permlink:comment.permlink,
last_update:comment.updated,
body:comment.markdownBody,
}, true, Platform.OS === 'android');
return ({
payload:{
commentPath,

View File

@ -13,18 +13,20 @@ export interface Comment {
permlink:string,
parent_author:string,
parent_permlink:string,
body:string,
body?:string,
markdownBody:string,
author_reputation?:number,
total_payout?:number,
net_rshares?:number,
active_votes?:Array<{rshares:number, voter:string}>,
created?:string,
created?:string, //handle created and updated separatly
updated?:string,
expiresAt?:number,
}
interface State {
votes:Map<string, Vote>
comments:Map<string, Comment>
comments:Map<string, Comment> //TODO: handle comment array per post, if parent is same
lastUpdate:{
postPath:string,
updatedAt:number,