File size: 608 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { filter, find, flatMap } from 'lodash';
import { deconstructStateKey, getErrorKey } from 'calypso/state/comments/utils';

import 'calypso/state/comments/init';

export function getCommentById( { state, commentId, siteId } ) {
	const errorKey = getErrorKey( siteId, commentId );
	if ( state.comments.errors[ errorKey ] ) {
		return state.comments.errors[ errorKey ];
	}

	const commentsForSite = flatMap(
		filter( state.comments.items, ( comment, key ) => {
			return deconstructStateKey( key ).siteId === siteId;
		} )
	);
	return find( commentsForSite, ( comment ) => commentId === comment.ID );
}