Skip to content

Commit b79d676

Browse files
authored
Add command ACTIVEUSERS (#106)
* add ACTIVEUSERS command * docs
1 parent f9420af commit b79d676

File tree

2 files changed

+84
-22
lines changed

2 files changed

+84
-22
lines changed

docs/050-command-reference.md

+51-22
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is a directory of all of the supported commands in the SmartBlocks extensio
1616
- [Serendipity](#serendipity-commands)
1717
- [TODO](#todo-commands)
1818
- [Block Related](#block-related-commands)
19+
- [User Related](#user-related-commands)
1920
- [Logic Control](#logic-control-commands)
2021
- [Cursor](#cursor-commands)
2122
- [Commands With Effects](#commands-with-effects)
@@ -449,28 +450,6 @@ Special note: if you want a comma to be a part of the output, put a \ in front o
449450

450451
`<%CURRENTURL%>`
451452

452-
## CURRENTUSER
453-
454-
**Purpose:** Return the display name of the user.
455-
456-
**Parameters:** None
457-
458-
**Example:**
459-
460-
`<%CURRENTUSER%>`
461-
462-
## AUTHOR
463-
464-
**Purpose:** Returns the username of the user who created the block or page.
465-
466-
**Parameters:**
467-
468-
1. Page name or block ref
469-
470-
**Example:**
471-
472-
`<%AUTHOR:((BVJoEW-aq))%>`
473-
474453
## CURRENTBLOCKREF
475454

476455
**Purpose:** Gets the current block reference. Stores it in a variable if present.
@@ -637,6 +616,56 @@ Special note: if you want a comma to be a part of the output, put a \ in front o
637616

638617
- `<%PARENT:ref,varName%>`
639618

619+
# **User Related Commands**
620+
621+
## CURRENTUSER
622+
623+
**Purpose:** Return the display name of the user.
624+
625+
**Parameters:** None
626+
627+
**Example:**
628+
629+
`<%CURRENTUSER%>`
630+
631+
## AUTHOR
632+
633+
**Purpose:** Returns the username of the user who created the block or page.
634+
635+
**Parameters:**
636+
637+
1. Page name or block ref
638+
639+
**Example:**
640+
641+
`<%AUTHOR:((BVJoEW-aq))%>`
642+
643+
## ALLUSERS
644+
645+
**Purpose:** Returns all users in the graph.
646+
647+
**Parameters:** None
648+
649+
**Example:**
650+
651+
`<%ALLUSERS%>`
652+
653+
## ACTIVEUSERS
654+
655+
**Purpose:** Returns all users who created/edited a block.
656+
657+
Default is set to the last three month.
658+
659+
**Parameters:**
660+
661+
1. (Optional) NLP expression for date basis
662+
2. (Optional) Format of Output
663+
664+
**Example:**
665+
666+
- `<%ACTIVEUSERS%>`
667+
- `<%ACTIVEUSERS:this year,{text}%>`
668+
640669
# **Logic Control Commands**
641670

642671
Logic Control Commands are commands that facilitate control flow and decision points in the workflow.

src/utils/core.ts

+33
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,39 @@ export const COMMANDS: {
21212121
return users;
21222122
},
21232123
},
2124+
{
2125+
text: "ACTIVEUSERS",
2126+
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",
2127+
handler: (nlp = "three months ago", format = `[[{text}]]`) => {
2128+
const timestamp =
2129+
parseNlpDate(nlp, getDateBasisDate()).valueOf() ||
2130+
// chrono fails basic parsing requiring forward date if ambiguous
2131+
// https://github.com/wanasit/chrono/commit/4f264a9f21fbd04eb740bf48f5616f6e6e0e78b7
2132+
parseNlpDate(`in ${nlp}`, getDateBasisDate()).valueOf();
2133+
2134+
// [?block :edit/time ?time] assumes newly created blocks get an edit time
2135+
const activeUsers = (
2136+
window.roamAlphaAPI.data.fast.q(`
2137+
[
2138+
:find
2139+
(pull ?user-page [:node/title :block/uid])
2140+
:where
2141+
[?user :user/display-page ?user-page]
2142+
[?user-page :node/title ?user-title]
2143+
[?block :create/user ?user]
2144+
[?block :edit/time ?time]
2145+
[(< ${timestamp} ?time)]
2146+
]
2147+
`) as [PullBlock, PullBlock][]
2148+
).map(([user]) => {
2149+
return getFormatter(format)({
2150+
text: user[":node/title"],
2151+
uid: user[":block/uid"],
2152+
});
2153+
});
2154+
return activeUsers;
2155+
},
2156+
},
21242157
{
21252158
text: "AUTHOR",
21262159
help: "Returns the user who created the block or page \n\n1: Page name or UID.",

0 commit comments

Comments
 (0)