File size: 1,328 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/**
* Returns last block in list of blocks with 'actions' property
*/
function getActionBlock( blocks ) {
return blocks.filter( ( block ) => block.hasOwnProperty( 'actions' ) ).slice( -1 )[ 0 ] || {};
}
/**
* Returns an object specifying which actions are enabled for a note and their values
* @param note
* @returns {Object}
*/
export function getActions( note ) {
return getActionBlock( note.body ).actions;
}
/**
* Returns an id for a type of reference in a note or null
* @param note
* @param {string} type can be 'post', 'comment', 'site', etc...
* @returns {number|null} null if no reference of type is found
*/
export function getReferenceId( note, type ) {
if ( ! ( note.meta && note.meta.ids && note.meta.ids[ type ] ) ) {
return null;
}
return note.meta.ids[ type ];
}
/**
* Returns the edit link for the note comment.
* It's a Calypso link for WP.com sites and
* Jetpack sites with the `edit_links_calypso_redirect` option set.
* It's a wp-admin link otherwise.
* @param note
* @returns {string}
*/
export function getEditCommentLink( note ) {
return getActionBlock( note.body ).edit_comment_link;
}
/**
* Returns the new post link for the note post.
* @param note
* @returns {string}
*/
export function getNewPostLink( note ) {
return getActionBlock( note.body ).new_post_link;
}
|