diff --git a/package-lock.json b/package-lock.json index 9456a3d..490e832 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "smartblocks", - "version": "1.12.1", + "version": "1.12.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "smartblocks", - "version": "1.12.1", + "version": "1.12.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 884d965..5917cab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smartblocks", - "version": "1.12.1", + "version": "1.12.2", "description": "Create custom and programmable templates from within Roam!", "main": "./build/main.js", "scripts": { diff --git a/src/utils/core.ts b/src/utils/core.ts index 0d50b50..d8abdef 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -2300,8 +2300,12 @@ export const COMMANDS: { }, { text: "ACTIVEUSERS", - help: "Gets all users who created/edited a block.\n\nDefault is set to the last three month.\n\n1: (Optional) NLP expression for date basis\n\n2: (Optional) Format of Output", - handler: (nlp = "three months ago", format = `[[{text}]]`) => { + help: "Gets all users who created/edited a block.\n\nDefault is set to the last three month.\n\n1: (Optional) NLP expression for date basis\n\n2: (Optional) Format of Output\n\n3: (Optional) Sort (ASC,DESC,NONE)", + handler: ( + nlp = "three months ago", + format = `[[{text}]]`, + sort = "NONE" + ) => { const timestamp = parseNlpDate(nlp, getDateBasisDate()).valueOf() || // chrono fails basic parsing requiring forward date if ambiguous @@ -2322,13 +2326,19 @@ export const COMMANDS: { [(< ${timestamp} ?time)] ] `) as [PullBlock, PullBlock][] - ).map(([user]) => { - return getFormatter(format)({ - text: user[":node/title"], - uid: user[":block/uid"], - }); - }); - return activeUsers; + ).map(([user]) => ({ + text: user[":node/title"] || user[":block/uid"] || "", + uid: user[":block/uid"], + })); + const sortedUsers = + sort === "NONE" + ? activeUsers + : activeUsers.sort( + sort === "DESC" + ? (a, b) => b.text.localeCompare(a.text) + : (a, b) => a.text.localeCompare(b.text) + ); + return sortedUsers.map((user) => getFormatter(format)(user)); }, }, {