@sanity/desk-tool
Version:
Tool for managing all sorts of content in a structured manner
24 lines (23 loc) • 827 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.collectLatestAuthorAnnotations = collectLatestAuthorAnnotations;
var _diff = require("@sanity/field/diff");
function collectLatestAuthorAnnotations(diff) {
var authorMap = new Map();
(0, _diff.visitDiff)(diff, child => {
if (child.action === 'unchanged' || !('annotation' in child) || !child.annotation) {
return true;
}
var _child$annotation = child.annotation,
author = _child$annotation.author,
timestamp = _child$annotation.timestamp;
var previous = authorMap.get(author);
if (!previous || previous.timestamp < timestamp) {
authorMap.set(author, child.annotation);
}
return true;
});
return Array.from(authorMap.values()).sort((a, b) => a.timestamp < b.timestamp ? 1 : -1);
}