mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-02 02:07:10 +03:00
parsing recursive replies upto a certain selected level
This commit is contained in:
parent
8c058285eb
commit
8b40f91a36
@ -76,18 +76,39 @@ export const parsePost = (post, currentUserName, isPromoted, isList = false, isC
|
|||||||
|
|
||||||
|
|
||||||
export const parseCommentThreads = async (commentsMap:any, author:string, permlink:string) => {
|
export const parseCommentThreads = async (commentsMap:any, author:string, permlink:string) => {
|
||||||
|
const MAX_THREAD_LEVEL = 3;
|
||||||
|
const comments = [];
|
||||||
|
|
||||||
if(!commentsMap){
|
if(!commentsMap){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const comments = [];
|
|
||||||
|
//traverse map to curate threads
|
||||||
|
const parseReplies = (commentsMap:any, replies:any[], level:number) => {
|
||||||
|
if(replies && replies.length > 0 && MAX_THREAD_LEVEL > level){
|
||||||
|
return replies.map((pathKey)=>{
|
||||||
|
const comment = commentsMap[pathKey];
|
||||||
|
if(comment){
|
||||||
|
const parsedComment = parseComment(comment);
|
||||||
|
parsedComment.replies = parseReplies(commentsMap, parsedComment.replies, level + 1)
|
||||||
|
return parsedComment;
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
for(const key in commentsMap){
|
for(const key in commentsMap){
|
||||||
if(commentsMap.hasOwnProperty(key)){
|
if(commentsMap.hasOwnProperty(key)){
|
||||||
|
|
||||||
const comment = commentsMap[key];
|
const comment = parseComment(commentsMap[key]);
|
||||||
|
|
||||||
if(comment.parent_author === author && comment.parent_permlink === permlink){
|
if(comment && comment.parent_author === author && comment.parent_permlink === permlink){
|
||||||
|
//extract replies
|
||||||
|
comment.replies = parseReplies(commentsMap, comment.replies, 1)
|
||||||
comments.push(comment);
|
comments.push(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +118,8 @@ export const parseCommentThreads = async (commentsMap:any, author:string, permli
|
|||||||
return comments;
|
return comments;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const parseComments = async (comments:any[]) => {
|
export const parseComments = async (comments:any[]) => {
|
||||||
if(!comments){
|
if(!comments){
|
||||||
return null;
|
return null;
|
||||||
@ -105,9 +128,9 @@ export const parseComments = async (comments:any[]) => {
|
|||||||
return comments.map((comment)=>parseComment(comment));
|
return comments.map((comment)=>parseComment(comment));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseComment = async (comment:any) => {
|
export const parseComment = (comment:any) => {
|
||||||
comment.pending_payout_value = parseFloat(get(comment, 'pending_payout_value', 0)).toFixed(3);
|
comment.pending_payout_value = parseFloat(get(comment, 'pending_payout_value', 0)).toFixed(3);
|
||||||
comment.author_reputation = getReputation(get(comment, 'author_reputation'));
|
comment.author_reputation = parseReputation(get(comment, 'author_reputation'));
|
||||||
comment.avatar = getResizedAvatar(get(comment, 'author'));
|
comment.avatar = getResizedAvatar(get(comment, 'author'));
|
||||||
comment.markdownBody = get(comment, 'body');
|
comment.markdownBody = get(comment, 'body');
|
||||||
comment.body = renderPostBody(comment, true, webp);
|
comment.body = renderPostBody(comment, true, webp);
|
||||||
|
Loading…
Reference in New Issue
Block a user