File size: 632 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import { get } from 'lodash';
/**
* @param {Object} ancestor potential ancestor comment
* @param {Object} child potential child comment
* @param {Object} commentsTree commentsTree for a post, see associated getPostCommentsTree selector
* @returns {boolean} return true if parent is an ancestor of child
*/
export const isAncestor = ( ancestor, child, commentsTree ) => {
if ( ! ancestor || ! child || ! child.parent || ! commentsTree ) {
return false;
}
const nextParent = get( commentsTree, [ child.parent.ID, 'data' ] );
return child.parent.ID === ancestor.ID || isAncestor( ancestor, nextParent, commentsTree );
};
|