forked from janek/mostr
Compare commits
246 Commits
taskprogre
...
main
Author | SHA1 | Date |
---|---|---|
xeruf | 00bd7a997a | |
xeruf | cb1d8ef8fb | |
xeruf | 7561bc0e2f | |
xeruf | 360b44e64e | |
xeruf | adcd35967f | |
xeruf | 2400f7c45b | |
xeruf | e186d034e5 | |
xeruf | 59b789d5ed | |
xeruf | 473f26d7a5 | |
xeruf | 43f8a3ebca | |
xeruf | 9a9c30dbb7 | |
xeruf | a0e411d2e9 | |
xeruf | ecc5b7686b | |
xeruf | d095c65b23 | |
xeruf | 6b8bf29b20 | |
xeruf | 2cec689bf1 | |
xeruf | 44feea9894 | |
xeruf | 3fa8df4eaa | |
xeruf | b9f1d461fb | |
xeruf | 7cedd980fb | |
xeruf | 55d42fc52c | |
xeruf | 15a2ffd7e6 | |
xeruf | 5f8a232bd5 | |
xeruf | 5dfd7a084b | |
xeruf | ca24693dbb | |
xeruf | ed72bcebcf | |
xeruf | 3749f72048 | |
xeruf | d1735476cc | |
xeruf | 5dbea00562 | |
xeruf | cc1e9d4d69 | |
xeruf | d5e6bd2578 | |
xeruf | 60b33b1dd3 | |
xeruf | 561fd9e1e5 | |
xeruf | 91b6047f9a | |
xeruf | 5294d9081f | |
xeruf | b81e5a27bf | |
xeruf | 8f0a169677 | |
xeruf | ae525c870f | |
xeruf | b9307b7b5d | |
xeruf | e9bee3c114 | |
xeruf | dc8df51e0f | |
xeruf | cc64c0f493 | |
xeruf | 5a8fa69e4c | |
xeruf | f33d890d7f | |
xeruf | dd78a2f460 | |
xeruf | 5303d0cb41 | |
xeruf | 2053f045b2 | |
xeruf | baf93bd788 | |
xeruf | d8eebcfb6a | |
xeruf | 7f33bdc9ab | |
xeruf | 306e0e0421 | |
xeruf | 49d8eef29c | |
xeruf | 74fff5a2b1 | |
xeruf | bdb8b6e814 | |
xeruf | b0c92e64fa | |
xeruf | 4e4ad7099f | |
xeruf | 613a8b3822 | |
xeruf | 1533676bff | |
xeruf | 52be8c53eb | |
xeruf | 5f25e116a1 | |
xeruf | d1720f89ae | |
xeruf | f6082f12f2 | |
xeruf | 3d389e8d52 | |
xeruf | 28d1f4c983 | |
xeruf | 93fde86169 | |
xeruf | 769b9578fe | |
xeruf | c27ccb8282 | |
xeruf | d744fb8457 | |
xeruf | c2f775e891 | |
xeruf | 617b1ea6d1 | |
xeruf | fd970b3709 | |
xeruf | c6de8daee9 | |
xeruf | a297f61363 | |
xeruf | 96ca945263 | |
xeruf | d4bca1c26f | |
xeruf | 516acadd4a | |
xeruf | 945eb6906a | |
xeruf | 34657540de | |
xeruf | afe3fa8670 | |
xeruf | 753afad2fd | |
xeruf | 7755967a7a | |
xeruf | cb75a5749f | |
xeruf | 0744e86922 | |
xeruf | ddb68f7107 | |
xeruf | 4b59b273f5 | |
xeruf | bb3bb1fd56 | |
xeruf | 593ebcddca | |
xeruf | 132ea048a5 | |
xeruf | ddc57dc36a | |
xeruf | 77bfc4cb7a | |
xeruf | 43e7a5cd10 | |
xeruf | 3942105764 | |
xeruf | 945e29b5ed | |
xeruf | 1297be43bc | |
xeruf | 5a62e8f99e | |
xeruf | 018357b21e | |
xeruf | d1ae0f5458 | |
xeruf | d4f544173a | |
xeruf | c2b106ea69 | |
xeruf | 003d1d6120 | |
xeruf | 039c390c66 | |
xeruf | b974957bc9 | |
xeruf | dd5aaf71d2 | |
xeruf | c5a2872534 | |
xeruf | 1a1f23007b | |
xeruf | 9eaf10006b | |
xeruf | 6492a22cc9 | |
xeruf | 13dac88ded | |
xeruf | 1263e39fb3 | |
xeruf | 714d4a4d5b | |
xeruf | 1d7d3eea74 | |
xeruf | 3cab294122 | |
xeruf | 01305c5a78 | |
xeruf | 14a1cbe09c | |
xeruf | 533378b24d | |
xeruf | a0f5d62c81 | |
xeruf | 84e46827ce | |
xeruf | 3c93e0aae7 | |
xeruf | c3d18e4494 | |
xeruf | 75a5f27843 | |
xeruf | 58126ba6e7 | |
xeruf | 9f14a0f3f9 | |
xeruf | f240413e2a | |
xeruf | 999068bdd9 | |
xeruf | f7f4bdc4f3 | |
xeruf | ed1f482707 | |
xeruf | 3dca6a4b23 | |
xeruf | 17b3334aea | |
xeruf | 77ba311bab | |
xeruf | 9da41db427 | |
xeruf | a67bd384ec | |
xeruf | ace365de38 | |
xeruf | 07bba314ec | |
xeruf | 126bd8cf81 | |
xeruf | b5b2ea9b71 | |
xeruf | f98486f012 | |
xeruf | ada3492487 | |
xeruf | efc0061390 | |
xeruf | 1b0f7dca09 | |
xeruf | f4cff3d702 | |
xeruf | f8a4777f71 | |
xeruf | 0296556bcd | |
xeruf | c64a1fa051 | |
xeruf | 721c200b97 | |
xeruf | 3b9fedd9a3 | |
xeruf | 12b7c909ab | |
xeruf | 5bc3509930 | |
xeruf | 629db66018 | |
xeruf | e0d241ec5a | |
xeruf | 506a73060a | |
xeruf | ebfe632497 | |
xeruf | a4f9398846 | |
xeruf | 416a7f195d | |
xeruf | f8375cf879 | |
xeruf | 8bf305d4d4 | |
xeruf | eaeeebca7b | |
xeruf | 2255abc1b8 | |
xeruf | 19d0fbb8fc | |
xeruf | 903536bd3b | |
xeruf | 86654c8348 | |
xeruf | d88cae4273 | |
xeruf | 9ad1243078 | |
xeruf | 2fac3fd8f8 | |
xeruf | 34540370c3 | |
xeruf | 43278a6631 | |
xeruf | 9c0a688297 | |
xeruf | fcd5e9c0c9 | |
xeruf | 3e056eb2b6 | |
xeruf | 930c6b9c38 | |
xeruf | c93b2f2d91 | |
xeruf | 0253b00c61 | |
xeruf | 957422f767 | |
xeruf | 3eefbad6d5 | |
xeruf | b544616801 | |
xeruf | 1e0cc319b8 | |
xeruf | 8588fb9a04 | |
xeruf | bbfbb2d8b0 | |
xeruf | f5aca3eca8 | |
xeruf | be582cb536 | |
xeruf | 68d5c101e9 | |
xeruf | 45b8f9cf0f | |
xeruf | ae4d315d87 | |
xeruf | 66af6af0ab | |
xeruf | a059ff1c3e | |
xeruf | 6cb2d47a8d | |
xeruf | 6d4666c12d | |
xeruf | c67ef3b119 | |
xeruf | 619bcfbbad | |
xeruf | 85b923edc8 | |
xeruf | 9f84fd7ef1 | |
xeruf | 67a19d61f2 | |
xeruf | 8f3552aeba | |
xeruf | b3d70ab0b7 | |
xeruf | c83d8a2f55 | |
xeruf | a7d02e60b2 | |
xeruf | 55792ca34f | |
xeruf | dda969e08b | |
xeruf | dcf333353b | |
xeruf | 15bd21059d | |
xeruf | 9fbe3e27cb | |
xeruf | 06bfe8e18a | |
xeruf | b74ac18e39 | |
xeruf | ae2172c8f2 | |
xeruf | b03ad00b6a | |
xeruf | ff74ac216b | |
xeruf | c48355e5da | |
xeruf | 7a8a048d6c | |
xeruf | c492d64d9e | |
xeruf | b62ec6fd39 | |
xeruf | 43c62bf742 | |
xeruf | 79b42b8df0 | |
xeruf | a3a732879f | |
xeruf | 6b7b6b91a8 | |
xeruf | 08b0ba48a3 | |
xeruf | 4180533844 | |
xeruf | fca9b1492b | |
xeruf | 50ac994d21 | |
xeruf | 65207a1de2 | |
xeruf | 6932e1f257 | |
xeruf | b66089fc94 | |
xeruf | f4f1b56f02 | |
xeruf | b5b57b7ac9 | |
xeruf | db4f9ee8cb | |
xeruf | d950c13098 | |
xeruf | a2505e94fb | |
xeruf | 8c2c279238 | |
xeruf | aa468f80c5 | |
xeruf | 55d856c75d | |
xeruf | e16e21a477 | |
xeruf | 9619435c03 | |
xeruf | bf802e3195 | |
xeruf | 03f9e60c6f | |
xeruf | 5b05c53947 | |
xeruf | 7f34a888f3 | |
xeruf | 256c86e06f | |
xeruf | a9509fd4f2 | |
xeruf | 36fe58d3f3 | |
xeruf | 14dcc8f0ff | |
xeruf | 486cbb1ab4 | |
xeruf | afd6f2f77a | |
xeruf | 03263840ac | |
xeruf | 5c7793f4a3 | |
xeruf | 484c05dbee | |
xeruf | e5953c63b4 | |
xeruf | 74464241ec | |
xeruf | 3652f0d39f |
|
@ -1,6 +1,7 @@
|
|||
/target
|
||||
/examples
|
||||
|
||||
/.idea
|
||||
relays
|
||||
keys
|
||||
*.html
|
||||
/src/bin
|
||||
*.html
|
File diff suppressed because it is too large
Load Diff
35
Cargo.toml
35
Cargo.toml
|
@ -5,19 +5,34 @@ repository = "https://forge.ftt.gmbh/janek/mostr"
|
|||
readme = "README.md"
|
||||
license = "GPL 3.0"
|
||||
authors = ["melonion"]
|
||||
version = "0.2.0"
|
||||
version = "0.6.0"
|
||||
rust-version = "1.82"
|
||||
edition = "2021"
|
||||
default-run = "mostr"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
xdg = "2.5.2"
|
||||
itertools = "0.12.1"
|
||||
log = "0.4.21"
|
||||
chrono = "0.4.38"
|
||||
colog = "1.3.0"
|
||||
colored = "2.1.0"
|
||||
nostr-sdk = "0.30"
|
||||
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
once_cell = "1.19.0"
|
||||
# Basics
|
||||
tokio = { version = "1.41", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
regex = "1.10.6"
|
||||
# System
|
||||
log = "0.4"
|
||||
env_logger = "0.11"
|
||||
colog = "1.3"
|
||||
colored = "2.1"
|
||||
rustyline = { git = "https://github.com/xeruf/rustyline", rev = "465b14d" }
|
||||
# OS-Specific Abstractions
|
||||
keyring = { version = "3", features = ["apple-native", "windows-native", "linux-native-sync-persistent", "crypto-rust"] }
|
||||
directories = "5.0"
|
||||
# Application Utils
|
||||
itertools = "0.12"
|
||||
chrono = "0.4"
|
||||
parse_datetime = "0.5.0"
|
||||
interim = { version = "0.1", features = ["chrono"] }
|
||||
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "e82bc787bdd8490ceadb034fe4483e4df1e91b2a" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.41", features = ["rt", "rt-multi-thread", "macros", "io-std"] }
|
||||
chrono-english = "0.1"
|
||||
linefeed = "0.6"
|
|
@ -0,0 +1,44 @@
|
|||
# Mostr Design & Internals
|
||||
|
||||
## Nostr Reference
|
||||
|
||||
All used nostr kinds are listed on the top of [kinds.rs](./src/kinds.rs)
|
||||
|
||||
Mostr mainly uses the following [NIPs](https://github.com/nostr-protocol/nips):
|
||||
|
||||
- Kind 1 for task descriptions and permanent tasks, can contain task property updates (tags, priority)
|
||||
- Issue Tracking: https://github.com/nostr-protocol/nips/blob/master/34.md
|
||||
+ Tasks have Kind 1621 (originally: git issue - currently no markdown support implemented)
|
||||
+ TBI: Kind 1622 for task comments
|
||||
+ Kind 1630-1633: Task Status (1630 Open, 1631 Done, 1632 Closed, 1633 Pending)
|
||||
- Own Kind 1650 for time-tracking
|
||||
|
||||
Considering to use Calendar: https://github.com/nostr-protocol/nips/blob/master/52.md
|
||||
|
||||
- Kind 31922 for GANTT, since it has only Date
|
||||
- Kind 31923 for Calendar, since it has a time
|
||||
|
||||
## Immutability
|
||||
|
||||
Apart from user-specific temporary utilities such as the Bookmark List (Kind 10003),
|
||||
all shared data is immutable, and modifications are recorded as separate events,
|
||||
providing full audit security.
|
||||
Deletions are not considered.
|
||||
|
||||
### Timestamps
|
||||
|
||||
Mostr provides convenient helpers to backdate an action to a limited extent.
|
||||
But when closing one task with `)10` at 10:00 of the current day
|
||||
and starting another with `(10` on the same day,
|
||||
depending on the order of the event ids,
|
||||
the started task would be terminated immediately
|
||||
due to the equal timestamp.
|
||||
|
||||
That is why I decided to subtract one second from the timestamp
|
||||
whenever timetracking is stopped,
|
||||
making sure that the stop event always happens before the start event
|
||||
when the same timestamp is provided in the interface.
|
||||
Since the user interface is anyways focused on comprehensible output
|
||||
and thus slightly fuzzy,
|
||||
I then also add one second to each timestamp displayed
|
||||
to make the displayed timestamps more intuitive.
|
323
README.md
323
README.md
|
@ -1,6 +1,12 @@
|
|||
# mostr
|
||||
|
||||
A nested task chat, powered by nostr!
|
||||
An immutable nested collaborative task manager, powered by nostr!
|
||||
|
||||
> Mostr is beta software.
|
||||
> Do not entrust it exclusively with your data unless you know what you are doing!
|
||||
|
||||
> Intermediate versions might not properly persist all changes.
|
||||
> A failed relay connection currently looses all intermediate changes.
|
||||
|
||||
## Quickstart
|
||||
|
||||
|
@ -8,88 +14,293 @@ First, start a nostr relay, such as
|
|||
- https://github.com/coracle-social/bucket for local development
|
||||
- https://github.com/rnostr/rnostr for production use
|
||||
|
||||
Run development build with:
|
||||
Install rust(up) and run a development build with:
|
||||
|
||||
cargo run
|
||||
|
||||
Creating a test task:
|
||||
`nostril --envelope --content "test task" --kind 1621 | websocat ws://localhost:4736`
|
||||
A `relay` list can be placed in a config file
|
||||
under `${XDG_CONFIG_HOME:-$HOME/.config}/mostr/`.
|
||||
Ideally any project with different collaborators has its own relay.
|
||||
If not saved, mostr will ask for a relay url
|
||||
(entering none is fine too, but your data will not be persisted between sessions)
|
||||
and a private key, alternatively generating one on the fly.
|
||||
The key is saved in the system keychain.
|
||||
|
||||
Install latest build:
|
||||
|
||||
cargo install --path . --offline
|
||||
cargo install --path .
|
||||
|
||||
## Principles
|
||||
This one-liner can help you stay on the latest version
|
||||
(optionally add a `cd` to your mostr-directory in front):
|
||||
|
||||
- active task is tracked automatically
|
||||
- progress through subdivision rather than guessing
|
||||
- TBI: show/hide closed/done tasks
|
||||
git pull && cargo install --path . && mostr
|
||||
|
||||
Recommendation: Flat hierarchy, using tags for filtering (TBI)
|
||||
Creating a test task externally:
|
||||
`nostril --envelope --content "test task" --kind 1621 | websocat ws://localhost:4736`
|
||||
|
||||
To exit the application, press `Ctrl-D`.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### Navigation and Nesting
|
||||
|
||||
Create tasks and navigate using the shortcuts below.
|
||||
Whichever task is active (selected)
|
||||
will be the parent task for newly created tasks
|
||||
and automatically has time-tracking running.
|
||||
To track task progress,
|
||||
simply subdivide the task -
|
||||
checking off tasks will automatically update the progress
|
||||
for all parent tasks.
|
||||
Generally a flat hierarchy is recommended
|
||||
with tags for filtering,
|
||||
since hierarchies cannot be changed.
|
||||
Filtering by a tag is just as easy
|
||||
as activating a task and more flexible.
|
||||
|
||||
Using subtasks has two main advantages:
|
||||
- ability to accumulate time tracked
|
||||
- swiftly navigate between related tasks
|
||||
|
||||
Managing a project with subtasks makes it continuously visible,
|
||||
which is helpful if you want to be able to track time on the project itself
|
||||
without a specific task,
|
||||
Thus subtasks can be very useful for specific contexts,
|
||||
for example a project or a specific place.
|
||||
|
||||
On the other hand, related tasks like chores
|
||||
should be grouped with a tag instead.
|
||||
Similarly for projects which are only sporadically worked on
|
||||
when a specific task comes up, so they do not clutter the list.
|
||||
|
||||
### Collaboration
|
||||
|
||||
Since everything in mostr is inherently immutable,
|
||||
live collaboration is easily possible.
|
||||
After every command,
|
||||
mostr checks if new updates arrived from the relay
|
||||
and updates its display accordingly.
|
||||
|
||||
If a relay has a lot of events,
|
||||
initial population of data can take a bit -
|
||||
but you can already start creating events without issues,
|
||||
updates will be fetched in the background.
|
||||
For that reason,
|
||||
it is recommended to leave mostr running
|
||||
as you work.
|
||||
|
||||
### Time-Tracking
|
||||
|
||||
The currently active task is automatically time-tracked.
|
||||
To stop time-tracking completely, simply move to the root of all tasks.
|
||||
Time-tracking by default recursively summarizes
|
||||
|
||||
### Priorities
|
||||
|
||||
Task priorities can be set as any natural number,
|
||||
with higher numbers denoting higher priorities.
|
||||
The syntax here allows for very convenient incremental usage:
|
||||
By default, using priorities between 1 and 9 is recommended,
|
||||
with an exemplary interpretation like this:
|
||||
|
||||
* 1 Ideas / "Someday"
|
||||
* 2 Later
|
||||
* 3 Soon
|
||||
* 4 Relevant
|
||||
* 5 Important
|
||||
* 9 DO NOW
|
||||
|
||||
Internally, when giving a single digit, a 0 is appended,
|
||||
so that the default priorities increment in steps of 10.
|
||||
So in case you need more than 10 priorities,
|
||||
instead of stacking them on top,
|
||||
you can granularly add them in between.
|
||||
For example, `12` is in between `1` and `2`
|
||||
which are equivalent to `10` and `20`,
|
||||
not above `9` but above `09`!
|
||||
|
||||
By default, only tasks with priority `35` and upward are shown
|
||||
so you can focus on what matters,
|
||||
but you can temporarily override that using `**PRIO`.
|
||||
|
||||
### Quick Access
|
||||
|
||||
Paper-based lists are often popular because you can quickly put down a bunch of items.
|
||||
Mostr offers three useful workflows depending on the use-case:
|
||||
If you want to TBC...
|
||||
|
||||
- temporary task with subtasks (especially handy for progression)
|
||||
- Filter by recently created
|
||||
- Pin to bookmarks
|
||||
- high priority
|
||||
|
||||
## Reference
|
||||
|
||||
### Command Syntax
|
||||
|
||||
`TASK` creation syntax: `NAME: TAG1 TAG2 ...`
|
||||
`TASK` creation syntax: `NAME #TAG *PRIO # TAG1 TAG2 ...`
|
||||
|
||||
- `TASK` - create task
|
||||
- `.` - clear filters and reload
|
||||
+ prefix with space if you want a task to start with a command character
|
||||
+ paste text with newlines to create one task per line
|
||||
- `.` - clear all filters
|
||||
- `.TASK`
|
||||
+ select task by id
|
||||
+ activate task by id
|
||||
+ match by task name prefix: if one or more tasks match, filter / activate (tries case-sensitive then case-insensitive)
|
||||
+ no match: create & activate task
|
||||
- `.2` - set view depth to `2`, which can be substituted for any number (how many subtask levels to show, default 1)
|
||||
- `.2` - set view depth to the given number (how many subtask levels to show, default is 1)
|
||||
- `/[TEXT]` - activate task or filter by smart-case substring match (empty: move to root)
|
||||
- `||TASK` - create and activate a new task procedure (where subtasks automatically depend on the previously created task)
|
||||
- `|[TASK]` - mark current task as procedure or create a sibling task depending on the current one and move up
|
||||
- sibling task shortcut?
|
||||
|
||||
Dots can be repeated to move to parent tasks
|
||||
Dot or slash can be repeated to move to parent tasks before acting.
|
||||
Append `@TIME` to any task creation or change command to record the action with the given time.
|
||||
|
||||
- `:[IND][COL]` - add / remove property column COL to IND or end
|
||||
- `>[TEXT]` - Complete active task and move to parent, with optional state description
|
||||
- `<[TEXT]` - Close active task and move to parent, with optional state description
|
||||
- `|TEXT` - Set state for current task from text (also aliased to `/` for now)
|
||||
- `-TEXT` - add text note (comment / description)
|
||||
- `:[IND][PROP]` - add property column PROP at IND or end,
|
||||
if it already exists remove property column PROP or IND; empty: list properties
|
||||
- `::[PROP]` - sort by property PROP (multiple space-separated values allowed)
|
||||
- `([TIME]` - list tracked times or insert timetracking with the specified offset (double to view all history)
|
||||
such as `-1d`, `-15 minutes`, `yesterday 17:20`, `in 2 fortnights`
|
||||
- `)[TIME]` - stop timetracking with optional offset - also convenience helper to move to root
|
||||
- `>[TEXT]` - complete active task and move up, with optional status description
|
||||
- `<[TEXT]` - close active task and move up, with optional status description
|
||||
- `!TEXT` - set status for current task from text and move up; empty: Open
|
||||
- `!TIME: REASON` - defer current task to date
|
||||
- `,[TEXT]` - list notes or add text (activity / task description)
|
||||
- TBI: `;[TEXT]` - list comments or comment on task
|
||||
- TBI: show status history and creation with attribution
|
||||
- `&` - revert
|
||||
- with string argument, find first matching task in history
|
||||
- with int argument, jump back X tasks in history
|
||||
- undo last action (moving in place or upwards confirms pending actions)
|
||||
- `*` - (un)bookmark current task or list all bookmarks
|
||||
- `wss://...` - switch or subscribe to relay (prefix with space to forcibly add a new one)
|
||||
|
||||
Property Filters:
|
||||
|
||||
- `#TAG` - filter by tag
|
||||
- `?STATE` - filter by state (type or description) - plain `?` to reset
|
||||
- `#TAG1 TAG2` - set tag filter
|
||||
- `+TAG` - add tag filter (empty: list all used tags)
|
||||
- `-TAG` - remove tag filters (by prefix)
|
||||
- `?STATUS` - set status filter (type or description) - plain `?` to reset, `??` to show all
|
||||
- `*INT` - set priority filter - `**` to reset
|
||||
- `@[AUTHOR|TIME]` - filter by time or author (pubkey, or `@` for self, TBI: id prefix, name prefix)
|
||||
|
||||
State descriptions can be used for example for Kanban columns.
|
||||
An active tag or state filter will also set that attribute for newly created tasks.
|
||||
Status descriptions can be used for example for Kanban columns or review flows.
|
||||
An active tag or status filter will also set that attribute for newly created tasks.
|
||||
|
||||
### Available Columns
|
||||
### Notes
|
||||
|
||||
- `id`
|
||||
- `parentid`
|
||||
- `name`
|
||||
- `state`
|
||||
- `hashtags`
|
||||
- `tags` - values of all nostr tags associated with the event, except event tags
|
||||
- `desc` - last note on the task
|
||||
- `description` - accumulated notes on the task
|
||||
- `path` - name including parent tasks
|
||||
- `rpath` - name including parent tasks up to active task
|
||||
- `time` - time tracked on this task
|
||||
- `rtime` - time tracked on this tasks and all recursive subtasks
|
||||
- `progress` - recursive subtask completion in percent
|
||||
- `subtasks` - how many direct subtasks are complete
|
||||
|
||||
For debugging: `props`, `alltags`, `descriptions`
|
||||
|
||||
TBI: Combined formatting and recursion specifiers -
|
||||
for example progress count/percentage and recursive or not.
|
||||
Subtask progress immediate/all/leafs.
|
||||
- TBI = To Be Implemented
|
||||
- `. TASK` - create and enter a new task even if the name matches an existing one
|
||||
|
||||
## Plans
|
||||
|
||||
- Relay Selection, fetch most recent tasks first
|
||||
- parse Hashtag tags from task name
|
||||
- Personal time tracking
|
||||
- Unified Filter object
|
||||
-> include sub
|
||||
- Time tracking: Active not as task state, ability to postpone task and add planned timestamps (calendar entry)
|
||||
- TUI - Clear terminal?
|
||||
- Expiry (no need to fetch potential years of history)
|
||||
- Offline caching
|
||||
- Web Interface, Messenger integrations
|
||||
- Relay: filter out task state updates within few seconds, also on client side
|
||||
- Handle event sending rejections (e.g. permissions)
|
||||
- Local Database Cache, Negentropy Reconciliation
|
||||
-> Offline Use!
|
||||
- Remove status filter when moving up?
|
||||
- Task markdown support? - colored
|
||||
- Calendar Events - make future time-tracking editable -> parametrised replaceable events
|
||||
- Speedup: Offline caching & Expiry (no need to fetch potential years of history)
|
||||
+ Fetch most recent tasks first
|
||||
+ Relay: compress tracked time for old tasks, filter closed tasks
|
||||
+ Relay: filter out task status updates within few seconds, also on client side
|
||||
|
||||
### Commands
|
||||
|
||||
- Open Command characters: `_^\=$%~'"`, `{}[]`
|
||||
- Remove colon from task creation syntax
|
||||
|
||||
### Conceptual
|
||||
|
||||
The following features are not ready to be implemented
|
||||
because they need conceptualization.
|
||||
Suggestions welcome!
|
||||
|
||||
- Queueing tasks
|
||||
- Allow adding new parent via description?
|
||||
- Special commands: help, exit, tutorial, change log level
|
||||
- Duplicate task (subtasks? timetracking?)
|
||||
- What if I want to postpone a procedure, i.e. make it pending, or move it across kanban, does this make sense?
|
||||
- Dependencies (change from tags to properties so they can be added later? or maybe as a status?)
|
||||
- Templates
|
||||
- Ownership
|
||||
- Combined formatting and recursion specifiers
|
||||
+ progress count/percentage and recursive or not
|
||||
+ Subtask progress immediate/all/leafs
|
||||
+ path full / leaf / top
|
||||
|
||||
### Interfaces & Integrations
|
||||
|
||||
- TUI: Clear Terminal? Refresh on empty prompt after timeout?
|
||||
- Kanban, GANTT, Calendar
|
||||
- n8n node
|
||||
- Webcal Feed: Scheduled (planning) / Tracked (events, timetracking) with args for how far back/forward
|
||||
|
||||
Interfaces:
|
||||
|
||||
- text-based REPL for terminal and messengers
|
||||
- interactive UI for web, mobile, desktop e.g. https://docs.slint.dev/latest/docs/slint/src/introduction/
|
||||
|
||||
## Exemplary Workflows - User Stories
|
||||
|
||||
- Freelancer
|
||||
- Family Chore Management
|
||||
- Inter-Disciplinary Project Team -> Company with multiple projects and multiple relays
|
||||
+ Permissions via status or assignment (reassignment?)
|
||||
+ Tasks can be blocked while having a status (e.g. kanban column)
|
||||
+ A meeting can be worked on (tracked) before it starts
|
||||
+ Schedule for multiple people
|
||||
- Tracking Daily Routines / Habits
|
||||
|
||||
### Freelancer
|
||||
|
||||
For a Freelancer, mostr can help structure work times
|
||||
across different projects
|
||||
because it can connect to multiple clients,
|
||||
using their mental state effectively (Mind Management not Time Management).
|
||||
It also enables transparency for clients
|
||||
by sharing the tracked time -
|
||||
but alternatively the freelancer
|
||||
can track times on their own auxiliary relay
|
||||
without problems.
|
||||
|
||||
### Family
|
||||
|
||||
With a mobile client implemented,
|
||||
mostr can track shopping lists and other chores for a family,
|
||||
and provide them context-dependently -
|
||||
allowing you to batch shopping and activities without mental effort.
|
||||
|
||||
### Project Team
|
||||
|
||||
sharing, assigning, stand-ups, communication
|
||||
|
||||
### Contexts
|
||||
|
||||
A context is a custom set of filters such as status, tags, assignee
|
||||
so that the visible tasks are always relevant
|
||||
and newly created tasks are less of a hassle to type out
|
||||
since they will automatically take on that context.
|
||||
By automating these contexts based on triggers, scripts or time,
|
||||
relevant tasks can be surfaced automatically.
|
||||
|
||||
#### Vision of Work-Life-Balance for Freelancer
|
||||
|
||||
In the morning, your groggy brain is good at divergent thinking,
|
||||
and you like to do sports in the morning.
|
||||
So for that time, mostr can show you tasks tagged for divergent thinking,
|
||||
since you are easily distracted filter out those that require the internet,
|
||||
as well as anything sportsy.
|
||||
After you come back from sports and had breakfast,
|
||||
for example detected through a period of inactivity on your device,
|
||||
you are ready for work, so the different work projects are shown and you delve into one.
|
||||
After 90 minutes you reach a natural low in your focus,
|
||||
so mostr surfaces break activities -
|
||||
such as a short walk, a small workout, some instrument practice
|
||||
or simply grabbing a snack and drink.
|
||||
After lunch you like to take an extended afternoon break,
|
||||
so your call list pops up -
|
||||
you can give a few people a call as you make a market run,
|
||||
before going for siesta.
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2024-11-09"
|
|
@ -0,0 +1,107 @@
|
|||
use std::cell::RefCell;
|
||||
use std::ops::Sub;
|
||||
|
||||
use nostr_sdk::prelude::*;
|
||||
use tokio::sync::mpsc::Sender;
|
||||
|
||||
use crate::kinds::TRACKING_KIND;
|
||||
use crate::tasks;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::Event;
|
||||
|
||||
const UNDO_DELAY: u64 = 60;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub(crate) enum MostrMessage {
|
||||
Flush,
|
||||
NewRelay(Url),
|
||||
AddTasks(Url, Vec<Event>),
|
||||
}
|
||||
|
||||
type Events = Vec<Event>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct EventSender {
|
||||
pub(crate) url: Option<Url>,
|
||||
pub(crate) tx: Sender<MostrMessage>,
|
||||
pub(crate) keys: Keys,
|
||||
pub(crate) queue: RefCell<Events>,
|
||||
}
|
||||
impl EventSender {
|
||||
pub(crate) fn from(url: Option<Url>, tx: &Sender<MostrMessage>, keys: &Keys) -> Self {
|
||||
EventSender {
|
||||
url,
|
||||
tx: tx.clone(),
|
||||
keys: keys.clone(),
|
||||
queue: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this direly needs testing
|
||||
pub(crate) fn submit(&self, event_builder: EventBuilder) -> Result<Event> {
|
||||
let min = Timestamp::now().sub(UNDO_DELAY);
|
||||
{
|
||||
// Always flush if oldest event older than a minute or newer than now
|
||||
let borrow = self.queue.borrow();
|
||||
if borrow
|
||||
.iter()
|
||||
.any(|e| e.created_at < min || e.created_at > Timestamp::now())
|
||||
{
|
||||
drop(borrow);
|
||||
debug!("Flushing event queue because it is older than a minute");
|
||||
self.force_flush();
|
||||
}
|
||||
}
|
||||
let mut queue = self.queue.borrow_mut();
|
||||
Ok(event_builder.sign_with_keys(&self.keys).inspect(|event| {
|
||||
if event.kind == TRACKING_KIND
|
||||
&& event.created_at > min
|
||||
&& event.created_at < tasks::now()
|
||||
{
|
||||
// Do not send redundant movements
|
||||
queue.retain(|e| e.kind != TRACKING_KIND);
|
||||
}
|
||||
queue.push(event.clone());
|
||||
})?)
|
||||
}
|
||||
/// Sends all pending events
|
||||
fn force_flush(&self) {
|
||||
debug!("Flushing {} events from queue", self.queue.borrow().len());
|
||||
let values = self.clear();
|
||||
self.url.as_ref().map(|url| {
|
||||
self.tx
|
||||
.try_send(MostrMessage::AddTasks(url.clone(), values))
|
||||
.err()
|
||||
.map(|e| {
|
||||
error!(
|
||||
"Nostr communication thread failure, changes will not be persisted: {}",
|
||||
e
|
||||
)
|
||||
})
|
||||
});
|
||||
}
|
||||
/// Sends all pending events if there is a non-tracking event
|
||||
pub(crate) fn flush(&self) {
|
||||
if self
|
||||
.queue
|
||||
.borrow()
|
||||
.iter()
|
||||
.any(|event| event.kind != TRACKING_KIND)
|
||||
{
|
||||
self.force_flush()
|
||||
}
|
||||
}
|
||||
pub(crate) fn clear(&self) -> Events {
|
||||
trace!("Cleared queue: {:?}", self.queue.borrow());
|
||||
self.queue.replace(Vec::with_capacity(3))
|
||||
}
|
||||
pub(crate) fn pubkey(&self) -> PublicKey {
|
||||
self.keys.public_key()
|
||||
}
|
||||
}
|
||||
impl Drop for EventSender {
|
||||
fn drop(&mut self) {
|
||||
self.force_flush();
|
||||
debug!("Dropped {:?}", self);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
use std::ops::Sub;
|
||||
|
||||
use chrono::LocalResult::Single;
|
||||
use chrono::{DateTime, Local, NaiveTime, TimeDelta, TimeZone, Utc};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::Timestamp;
|
||||
|
||||
pub const CHARACTER_THRESHOLD: usize = 3;
|
||||
|
||||
pub fn to_string_or_default(arg: Option<impl ToString>) -> String {
|
||||
arg.map(|arg| arg.to_string()).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn some_non_empty(str: &str) -> Option<String> {
|
||||
if str.is_empty() { None } else { Some(str.to_string()) }
|
||||
}
|
||||
|
||||
pub fn trim_start_count(str: &str, char: char) -> (&str, usize) {
|
||||
let len = str.len();
|
||||
let result = str.trim_start_matches(char);
|
||||
let dots = len - result.len();
|
||||
(result, dots)
|
||||
}
|
||||
|
||||
pub trait ToTimestamp {
|
||||
fn to_timestamp(&self) -> Timestamp;
|
||||
}
|
||||
impl<T: TimeZone> ToTimestamp for DateTime<T> {
|
||||
fn to_timestamp(&self) -> Timestamp {
|
||||
let stamp = self.to_utc().timestamp();
|
||||
if let Some(t) = 0u64.checked_add_signed(stamp) {
|
||||
Timestamp::from(t)
|
||||
} else { Timestamp::zero() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the hour from a plain number in the String,
|
||||
/// with max of max_future hours into the future.
|
||||
pub fn parse_hour(str: &str, max_future: i64) -> Option<DateTime<Local>> {
|
||||
str.parse::<u32>().ok().and_then(|hour| {
|
||||
let now = Local::now();
|
||||
#[allow(deprecated)]
|
||||
now.date().and_hms_opt(hour, 0, 0).map(|time| {
|
||||
if time - now > TimeDelta::hours(max_future) {
|
||||
time.sub(TimeDelta::days(1))
|
||||
} else {
|
||||
time
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_date(str: &str) -> Option<DateTime<Utc>> {
|
||||
// Using two libraries for better exhaustiveness, see https://github.com/uutils/parse_datetime/issues/84
|
||||
match interim::parse_date_string(str, Local::now(), interim::Dialect::Us) {
|
||||
Ok(date) => Some(date.to_utc()),
|
||||
Err(e) => {
|
||||
match parse_datetime::parse_datetime_at_date(Local::now(), str) {
|
||||
Ok(date) => Some(date.to_utc()),
|
||||
Err(_) => {
|
||||
warn!("Could not parse date from \"{str}\": {e}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}.map(|time| {
|
||||
// TODO properly map date without time to day start, also support intervals
|
||||
if str.chars().any(|c| c.is_numeric()) {
|
||||
time
|
||||
} else {
|
||||
#[allow(deprecated)]
|
||||
time.date().and_time(NaiveTime::default()).unwrap()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Turn a human-readable relative timestamp into a nostr Timestamp.
|
||||
/// - Plain number as hour, 18 hours back or 6 hours forward
|
||||
/// - Number with prefix as minute offset
|
||||
/// - Otherwise try to parse a relative date
|
||||
pub fn parse_tracking_stamp(str: &str) -> Option<Timestamp> {
|
||||
if let Some(num) = parse_hour(str, 6) {
|
||||
return Some(num.to_timestamp());
|
||||
}
|
||||
let stripped = str.trim().trim_start_matches('+').trim_start_matches("in ");
|
||||
if let Ok(num) = stripped.parse::<i64>() {
|
||||
return Some(Timestamp::from(Timestamp::now().as_u64().saturating_add_signed(num * 60)));
|
||||
}
|
||||
parse_date(str).and_then(|time| {
|
||||
let stamp = time.to_utc().timestamp();
|
||||
if stamp > 0 {
|
||||
Some(Timestamp::from(stamp as u64))
|
||||
} else {
|
||||
warn!("Can only track times after 1970!");
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Format DateTime easily comprehensible for human but unambiguous.
|
||||
/// Length may vary.
|
||||
pub fn format_datetime_relative(time: DateTime<Local>) -> String {
|
||||
let date = time.date_naive();
|
||||
let prefix =
|
||||
match Local::now()
|
||||
.date_naive()
|
||||
.signed_duration_since(date)
|
||||
.num_days() {
|
||||
-1 => "tomorrow ".into(),
|
||||
0 => "".into(),
|
||||
1 => "yesterday ".into(),
|
||||
//-3..=3 => date.format("%a ").to_string(),
|
||||
-10..=10 => date.format("%d. %a ").to_string(),
|
||||
-100..=100 => date.format("%a %b %d ").to_string(),
|
||||
_ => date.format("%y-%m-%d %a ").to_string(),
|
||||
};
|
||||
format!("{}{}", prefix, time.format("%H:%M"))
|
||||
}
|
||||
|
||||
/// Format a nostr timestamp with the given formatting function.
|
||||
pub fn format_as_datetime<F>(stamp: &Timestamp, formatter: F) -> String
|
||||
where
|
||||
F: Fn(DateTime<Local>) -> String,
|
||||
{
|
||||
match Local.timestamp_opt(stamp.as_u64() as i64 + 1, 0) {
|
||||
Single(time) => formatter(time),
|
||||
_ => stamp.to_human_datetime().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Format nostr Timestamp relative to local time
|
||||
/// with optional day specifier or full date depending on distance to today.
|
||||
pub fn format_timestamp_relative(stamp: &Timestamp) -> String {
|
||||
format_as_datetime(stamp, format_datetime_relative)
|
||||
}
|
||||
|
||||
/// Format nostr timestamp with the given format.
|
||||
pub fn format_timestamp(stamp: &Timestamp, format: &str) -> String {
|
||||
format_as_datetime(stamp, |time| time.format(format).to_string())
|
||||
}
|
||||
|
||||
/// Format nostr timestamp in a sensible comprehensive format with consistent length and consistent sorting.
|
||||
///
|
||||
/// Currently: 18 characters
|
||||
pub fn format_timestamp_local(stamp: &Timestamp) -> String {
|
||||
format_timestamp(stamp, "%y-%m-%d %a %H:%M")
|
||||
}
|
||||
|
||||
pub fn format_timestamp_relative_to(stamp: &Timestamp, reference: &Timestamp) -> String {
|
||||
// Rough difference in days
|
||||
match (stamp.as_u64() as i64 - reference.as_u64() as i64) / 80_000 {
|
||||
0 => format_timestamp(stamp, "%H:%M"),
|
||||
-3..=3 => format_timestamp(stamp, "%a %H:%M"),
|
||||
_ => format_timestamp_local(stamp),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
use crate::task::MARKER_PARENT;
|
||||
use crate::tasks::HIGH_PRIO;
|
||||
use itertools::Itertools;
|
||||
use nostr_sdk::{Alphabet, EventBuilder, EventId, Kind, Tag, TagKind, TagStandard};
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub const TASK_KIND: Kind = Kind::GitIssue;
|
||||
pub const PROCEDURE_KIND_ID: u16 = 1639;
|
||||
pub const PROCEDURE_KIND: Kind = Kind::Regular(PROCEDURE_KIND_ID);
|
||||
pub const TRACKING_KIND: Kind = Kind::Regular(1650);
|
||||
pub const BASIC_KINDS: [Kind; 4] = [
|
||||
Kind::Metadata,
|
||||
Kind::TextNote,
|
||||
TASK_KIND,
|
||||
Kind::Bookmarks,
|
||||
];
|
||||
pub const PROP_KINDS: [Kind; 6] = [
|
||||
TRACKING_KIND,
|
||||
Kind::GitStatusOpen,
|
||||
Kind::GitStatusApplied,
|
||||
Kind::GitStatusClosed,
|
||||
Kind::GitStatusDraft,
|
||||
PROCEDURE_KIND,
|
||||
];
|
||||
|
||||
pub type Prio = u16;
|
||||
pub const PRIO: &str = "priority";
|
||||
|
||||
// TODO: use formatting - bold / heading / italics - and generate from code
|
||||
/// Helper for available properties.
|
||||
pub const PROPERTY_COLUMNS: &str =
|
||||
"# Available Properties
|
||||
Immutable:
|
||||
- `id` - unique task id
|
||||
- `parentid` - unique task id of the parent, if any
|
||||
- `name` - initial name of the task
|
||||
- `created` - task creation timestamp
|
||||
- `author` - name or abbreviated key of the task creator
|
||||
Task:
|
||||
- `status` - pure task status
|
||||
- `hashtags` - list of hashtags set for the task
|
||||
- `tags` - values of all nostr tags associated with the event, except event tags
|
||||
- `desc` - last note on the task
|
||||
- `description` - accumulated notes on the task
|
||||
- `time` - time tracked on this task by you
|
||||
Utilities:
|
||||
- `state` - indicator of current progress
|
||||
- `rtime` - time tracked on this tasks and its subtree by everyone
|
||||
- `progress` - recursive subtask completion in percent
|
||||
- `subtasks` - how many direct subtasks are complete
|
||||
- `path` - name including parent tasks
|
||||
- `rpath` - name including parent tasks up to active task
|
||||
- TBI `depends` - list all tasks this task depends on before it becomes actionable
|
||||
Debugging: `kind`, `pubkey`, `props`, `alltags`, `descriptions`";
|
||||
|
||||
pub struct EventTag {
|
||||
pub id: EventId,
|
||||
pub marker: Option<String>,
|
||||
}
|
||||
|
||||
/// Return event tag if existing
|
||||
pub(crate) fn match_event_tag(tag: &Tag) -> Option<EventTag> {
|
||||
let mut vec = tag.as_slice().into_iter();
|
||||
if vec.next() == Some(&"e".to_string()) {
|
||||
if let Some(id) = vec.next().and_then(|v| EventId::parse(v).ok()) {
|
||||
vec.next();
|
||||
return Some(EventTag { id, marker: vec.next().cloned() });
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub(crate) fn build_tracking<I>(id: I) -> EventBuilder
|
||||
where
|
||||
I: IntoIterator<Item=EventId>,
|
||||
{
|
||||
EventBuilder::new(Kind::from(TRACKING_KIND), "")
|
||||
.tags(id.into_iter().map(Tag::event))
|
||||
}
|
||||
|
||||
pub fn join<'a, T>(tags: T) -> String
|
||||
where
|
||||
T: IntoIterator<Item=&'a Tag>,
|
||||
{
|
||||
tags.into_iter().map(format_tag).join(", ")
|
||||
}
|
||||
|
||||
/// Return Hashtags embedded in the string.
|
||||
pub(crate) fn extract_hashtags(input: &str) -> impl Iterator<Item=Tag> + '_ {
|
||||
input.split_ascii_whitespace()
|
||||
.filter(|s| s.starts_with('#'))
|
||||
.map(|s| s.trim_start_matches('#'))
|
||||
.map(to_hashtag)
|
||||
}
|
||||
|
||||
/// Extracts everything after a " # " as a list of tags
|
||||
/// as well as various embedded tags.
|
||||
///
|
||||
/// Expects sanitized input.
|
||||
pub(crate) fn extract_tags(input: &str) -> (String, Vec<Tag>) {
|
||||
let words = input.split_ascii_whitespace();
|
||||
let mut prio = None;
|
||||
let result = words.filter(|s| {
|
||||
if s.starts_with('*') {
|
||||
if s.len() == 1 {
|
||||
prio = Some(HIGH_PRIO);
|
||||
return false;
|
||||
}
|
||||
return match s[1..].parse::<Prio>() {
|
||||
Ok(num) => {
|
||||
prio = Some(num * (if s.len() > 2 { 1 } else { 10 }));
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
true
|
||||
}).collect_vec();
|
||||
let mut split = result.split(|e| { e == &"#" });
|
||||
let main = split.next().unwrap().join(" ");
|
||||
let mut tags = extract_hashtags(&main)
|
||||
.chain(split.flatten().map(|s| to_hashtag(&s)))
|
||||
.chain(prio.map(|p| to_prio_tag(p)))
|
||||
.collect_vec();
|
||||
tags.sort();
|
||||
tags.dedup();
|
||||
(main, tags)
|
||||
}
|
||||
|
||||
pub fn to_hashtag(tag: &str) -> Tag {
|
||||
TagStandard::Hashtag(tag.to_string()).into()
|
||||
}
|
||||
|
||||
fn format_tag(tag: &Tag) -> String {
|
||||
if let Some(et) = match_event_tag(tag) {
|
||||
return format!("{}: {:.8}",
|
||||
et.marker.as_ref().map(|m| m.to_string()).unwrap_or(MARKER_PARENT.to_string()),
|
||||
et.id);
|
||||
}
|
||||
match tag.as_standardized() {
|
||||
Some(TagStandard::PublicKey {
|
||||
public_key,
|
||||
alias,
|
||||
..
|
||||
}) => format!("Key{}: {:.8}", public_key, alias.as_ref().map(|s| format!(" {s}")).unwrap_or_default()),
|
||||
Some(TagStandard::Hashtag(content)) =>
|
||||
format!("#{content}"),
|
||||
_ => tag.as_slice().join(" ")
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_hashtag(tag: &Tag) -> bool {
|
||||
tag.single_letter_tag()
|
||||
.is_some_and(|letter| letter.character == Alphabet::T)
|
||||
}
|
||||
|
||||
pub(crate) fn to_prio_tag(value: Prio) -> Tag {
|
||||
Tag::custom(TagKind::Custom(Cow::from(PRIO)), [value.to_string()])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_tags() {
|
||||
assert_eq!(extract_tags("Hello from #mars with #greetings #yeah *4 # # yeah done-it"),
|
||||
("Hello from #mars with #greetings #yeah".to_string(),
|
||||
std::iter::once(Tag::custom(TagKind::Custom(Cow::from(PRIO)), [40.to_string()]))
|
||||
.chain(["done-it", "greetings", "mars", "yeah"].into_iter().map(to_hashtag)).collect()));
|
||||
assert_eq!(extract_tags("So tagless #"),
|
||||
("So tagless".to_string(), vec![]));
|
||||
}
|
931
src/main.rs
931
src/main.rs
File diff suppressed because it is too large
Load Diff
346
src/task.rs
346
src/task.rs
|
@ -1,36 +1,67 @@
|
|||
use fmt::Display;
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt;
|
||||
use std::ops::Div;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::iter::once;
|
||||
use std::string::ToString;
|
||||
|
||||
use colored::{ColoredString, Colorize};
|
||||
use itertools::Either::{Left, Right};
|
||||
use itertools::Itertools;
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, Kind, Tag, Timestamp};
|
||||
use nostr_sdk::{Alphabet, Event, EventId, Kind, Tag, Timestamp};
|
||||
|
||||
use crate::EventSender;
|
||||
use crate::helpers::{format_timestamp_local, some_non_empty};
|
||||
use crate::kinds::{is_hashtag, match_event_tag, Prio, PRIO, PROCEDURE_KIND, PROCEDURE_KIND_ID, TASK_KIND};
|
||||
use crate::tasks::now;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub static MARKER_PARENT: &str = "parent";
|
||||
pub static MARKER_DEPENDS: &str = "depends";
|
||||
pub static MARKER_PROPERTY: &str = "property";
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct Task {
|
||||
/// Event that defines this task
|
||||
pub(crate) event: Event,
|
||||
pub(crate) children: HashSet<EventId>,
|
||||
/// Cached sorted tags of the event with references removed
|
||||
tags: Option<BTreeSet<Tag>>,
|
||||
/// Task references derived from the event tags
|
||||
refs: Vec<(String, EventId)>,
|
||||
/// Events belonging to this task, such as state updates and notes
|
||||
pub(crate) props: BTreeSet<Event>,
|
||||
/// Cached sorted tags of the event
|
||||
pub(crate) tags: Option<BTreeSet<Tag>>,
|
||||
parents: Vec<EventId>,
|
||||
}
|
||||
|
||||
impl PartialOrd<Self> for Task {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.event.partial_cmp(&other.event)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for Task {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.event.cmp(&other.event)
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Task {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.event.id.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub(crate) fn new(event: Event) -> Task {
|
||||
let (parents, tags) = event.tags.iter().partition_map(|tag| match tag {
|
||||
Tag::Event { event_id, .. } => return Left(event_id),
|
||||
_ => Right(tag.clone()),
|
||||
let (refs, tags) = event.tags.iter().partition_map(|tag| if let Some(et) = match_event_tag(tag) {
|
||||
Left((et.marker.as_ref().map_or(MARKER_PARENT.to_string(), |m| m.to_string()), et.id))
|
||||
} else {
|
||||
Right(tag.clone())
|
||||
});
|
||||
// Separate refs for dependencies
|
||||
Task {
|
||||
children: Default::default(),
|
||||
props: Default::default(),
|
||||
tags: Some(tags).filter(|t: &BTreeSet<Tag>| !t.is_empty()),
|
||||
parents,
|
||||
refs,
|
||||
event,
|
||||
}
|
||||
}
|
||||
|
@ -39,59 +70,99 @@ impl Task {
|
|||
&self.event.id
|
||||
}
|
||||
|
||||
pub(crate) fn parent_id(&self) -> Option<EventId> {
|
||||
self.parents.first().cloned()
|
||||
pub(crate) fn find_refs<'a>(&'a self, marker: &'a str) -> impl Iterator<Item=&'a EventId> {
|
||||
self.refs.iter().filter_map(move |(str, id)| Some(id).filter(|_| str == marker))
|
||||
}
|
||||
|
||||
pub(crate) fn parent_id(&self) -> Option<&EventId> {
|
||||
self.find_refs(MARKER_PARENT).next()
|
||||
}
|
||||
|
||||
pub(crate) fn get_dependendees(&self) -> Vec<&EventId> {
|
||||
self.find_refs(MARKER_DEPENDS).collect()
|
||||
}
|
||||
|
||||
/// Trimmed event content or stringified id
|
||||
pub(crate) fn get_title(&self) -> String {
|
||||
Some(self.event.content.trim().to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
some_non_empty(self.event.content.trim())
|
||||
.unwrap_or_else(|| self.get_id().to_string())
|
||||
}
|
||||
|
||||
pub(crate) fn descriptions(&self) -> impl Iterator<Item = &String> + '_ {
|
||||
self.props.iter().filter_map(|event| {
|
||||
if event.kind == Kind::TextNote {
|
||||
Some(&event.content)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
pub(crate) fn get_filter_title(&self) -> String {
|
||||
self.event.content.trim().trim_start_matches('#').to_string()
|
||||
}
|
||||
|
||||
fn states(&self) -> impl Iterator<Item = TaskState> + '_ {
|
||||
pub(crate) fn description_events(&self) -> impl Iterator<Item=&Event> + '_ {
|
||||
self.props.iter().filter(|event| event.kind == Kind::TextNote)
|
||||
}
|
||||
|
||||
pub(crate) fn descriptions(&self) -> impl Iterator<Item=&String> + '_ {
|
||||
self.description_events().map(|e| &e.content)
|
||||
}
|
||||
|
||||
pub(crate) fn is_task_kind(&self) -> bool {
|
||||
self.event.kind == TASK_KIND
|
||||
}
|
||||
|
||||
/// Whether this is an actionable task - false if stateless activity
|
||||
pub(crate) fn is_task(&self) -> bool {
|
||||
self.is_task_kind() ||
|
||||
self.props.iter().any(|event| State::try_from(event.kind).is_ok())
|
||||
}
|
||||
|
||||
pub(crate) fn priority(&self) -> Option<Prio> {
|
||||
self.priority_raw().and_then(|s| s.parse().ok())
|
||||
}
|
||||
|
||||
pub(crate) fn priority_raw(&self) -> Option<&str> {
|
||||
self.props.iter()
|
||||
.chain(once(&self.event))
|
||||
.find_map(|p| {
|
||||
p.tags.iter().find_map(|t|
|
||||
t.content().take_if(|_| { t.kind().to_string() == PRIO }))
|
||||
})
|
||||
}
|
||||
|
||||
fn states(&self) -> impl DoubleEndedIterator<Item=TaskState> + '_ {
|
||||
self.props.iter().filter_map(|event| {
|
||||
event.kind.try_into().ok().map(|s| TaskState {
|
||||
name: Some(event.content.clone()).filter(|c| !c.is_empty()),
|
||||
name: some_non_empty(&event.content),
|
||||
state: s,
|
||||
time: event.created_at.clone(),
|
||||
time: event.created_at,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn last_state_update(&self) -> Timestamp {
|
||||
self.state().map(|s| s.time).unwrap_or(self.event.created_at)
|
||||
}
|
||||
|
||||
pub(crate) fn state(&self) -> Option<TaskState> {
|
||||
self.states().max_by_key(|t| t.time)
|
||||
let now = now();
|
||||
// TODO do not iterate constructed state objects
|
||||
let state = self.states().take_while_inclusive(|ts| ts.time > now);
|
||||
state.last().map(|ts| {
|
||||
if ts.time <= now {
|
||||
ts
|
||||
} else {
|
||||
self.default_state()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn pure_state(&self) -> State {
|
||||
self.state().map_or(State::Open, |s| s.state)
|
||||
}
|
||||
|
||||
pub(crate) fn set_state(
|
||||
&mut self,
|
||||
sender: &EventSender,
|
||||
state: State,
|
||||
comment: &str,
|
||||
) -> Option<Event> {
|
||||
sender
|
||||
.submit(EventBuilder::new(
|
||||
state.kind(),
|
||||
comment,
|
||||
vec![Tag::event(self.event.id)],
|
||||
))
|
||||
.inspect(|e| {
|
||||
self.props.insert(e.clone());
|
||||
})
|
||||
pub(crate) fn state_or_default(&self) -> TaskState {
|
||||
self.state().unwrap_or_else(|| self.default_state())
|
||||
}
|
||||
|
||||
/// Returns None for activities.
|
||||
pub(crate) fn state_label(&self) -> Option<ColoredString> {
|
||||
self.state()
|
||||
.or_else(|| Some(self.default_state()).filter(|_| self.is_task()))
|
||||
.map(|state| state.get_colored_label())
|
||||
}
|
||||
|
||||
fn default_state(&self) -> TaskState {
|
||||
|
@ -102,68 +173,57 @@ impl Task {
|
|||
}
|
||||
}
|
||||
|
||||
/// Total time this task has been active.
|
||||
/// TODO: Consider caching
|
||||
pub(crate) fn time_tracked(&self) -> u64 {
|
||||
let mut total = 0;
|
||||
let mut start: Option<Timestamp> = None;
|
||||
for state in self.states() {
|
||||
match state.state {
|
||||
State::Active => start = start.or(Some(state.time)),
|
||||
_ => {
|
||||
if let Some(stamp) = start {
|
||||
total += (state.time - stamp).as_u64();
|
||||
start = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(start) = start {
|
||||
total += (Timestamp::now() - start).as_u64();
|
||||
}
|
||||
total
|
||||
pub(crate) fn get_hashtags(&self) -> impl Iterator<Item=&Tag> {
|
||||
self.tags().filter(|t| is_hashtag(t))
|
||||
}
|
||||
|
||||
fn filter_tags<P>(&self, predicate: P) -> Option<String>
|
||||
fn tags(&self) -> impl Iterator<Item=&Tag> {
|
||||
self.tags.iter().flatten().chain(
|
||||
self.props.iter().flat_map(|e| e.tags.iter()
|
||||
.filter(|t| t.single_letter_tag().is_none_or(|s| s.character != Alphabet::E)))
|
||||
)
|
||||
}
|
||||
|
||||
fn join_tags<P>(&self, predicate: P) -> String
|
||||
where
|
||||
P: FnMut(&&Tag) -> bool,
|
||||
{
|
||||
self.tags.as_ref().map(|tags| {
|
||||
tags.into_iter()
|
||||
.filter(predicate)
|
||||
.map(|t| format!("{}", t.content().unwrap()))
|
||||
.collect::<Vec<String>>()
|
||||
.join(" ")
|
||||
})
|
||||
self.tags()
|
||||
.filter(predicate)
|
||||
.map(|t| t.content().unwrap().to_string())
|
||||
.sorted_unstable()
|
||||
.dedup()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
pub(crate) fn get(&self, property: &str) -> Option<String> {
|
||||
match property {
|
||||
// Static
|
||||
"id" => Some(self.event.id.to_string()),
|
||||
"parentid" => self.parent_id().map(|i| i.to_string()),
|
||||
"state" => self.state().map(|s| s.to_string()),
|
||||
"name" => Some(self.event.content.clone()),
|
||||
"time" => Some(self.time_tracked().div(60))
|
||||
.filter(|t| t > &0)
|
||||
.map(|t| format!("{}m", t)),
|
||||
"key" | "pubkey" => Some(self.event.pubkey.to_string()),
|
||||
"created" => Some(format_timestamp_local(&self.event.created_at)),
|
||||
"kind" => Some(self.event.kind.to_string()),
|
||||
// Dynamic
|
||||
"priority" => self.priority_raw().map(|c| c.to_string()),
|
||||
"status" => self.state_label().map(|c| c.to_string()),
|
||||
"desc" => self.descriptions().last().cloned(),
|
||||
"description" => Some(self.descriptions().join(" ")),
|
||||
"hashtags" => self.filter_tags(|tag| {
|
||||
tag.single_letter_tag()
|
||||
.is_some_and(|sltag| sltag.character == Alphabet::T)
|
||||
}),
|
||||
"tags" => self.filter_tags(|_| true),
|
||||
"hashtags" => Some(self.join_tags(|tag| { is_hashtag(tag) })),
|
||||
"tags" => Some(self.join_tags(|_| true)), // TODO test these!
|
||||
"alltags" => Some(format!("{:?}", self.tags)),
|
||||
"refs" => Some(format!("{:?}", self.refs.iter().map(|re| format!("{}: {}", re.0, re.1)).collect_vec())),
|
||||
"props" => Some(format!(
|
||||
"{:?}",
|
||||
self.props
|
||||
.iter()
|
||||
.map(|e| format!("{} kind {} '{}'", e.created_at, e.kind, e.content))
|
||||
.collect::<Vec<String>>()
|
||||
.map(|e| format!("{} kind {} \"{}\"", e.created_at, e.kind, e.content))
|
||||
.collect_vec()
|
||||
)),
|
||||
"descriptions" => Some(format!(
|
||||
"{:?}",
|
||||
self.descriptions().collect::<Vec<&String>>()
|
||||
self.descriptions().collect_vec()
|
||||
)),
|
||||
_ => {
|
||||
warn!("Unknown task property {}", property);
|
||||
|
@ -174,20 +234,22 @@ impl Task {
|
|||
}
|
||||
|
||||
pub(crate) struct TaskState {
|
||||
state: State,
|
||||
pub(crate) state: State,
|
||||
name: Option<String>,
|
||||
pub(crate) time: Timestamp,
|
||||
}
|
||||
impl TaskState {
|
||||
pub(crate) fn get_label_for(state: &State, comment: &str) -> String {
|
||||
some_non_empty(comment).unwrap_or_else(|| state.to_string())
|
||||
}
|
||||
pub(crate) fn get_label(&self) -> String {
|
||||
self.name.clone().unwrap_or_else(|| self.state.to_string())
|
||||
}
|
||||
pub(crate) fn get_colored_label(&self) -> ColoredString {
|
||||
self.state.colorize(&self.get_label())
|
||||
}
|
||||
pub(crate) fn matches_label(&self, label: &str) -> bool {
|
||||
self.state == State::Active
|
||||
|| self
|
||||
.name
|
||||
.as_ref()
|
||||
.is_some_and(|n| n.eq_ignore_ascii_case(label))
|
||||
self.name.as_ref().is_some_and(|n| n.eq_ignore_ascii_case(label))
|
||||
|| self.state.to_string().eq_ignore_ascii_case(label)
|
||||
}
|
||||
}
|
||||
|
@ -206,45 +268,109 @@ impl Display for TaskState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Ord, PartialOrd, Eq)]
|
||||
pub(crate) enum State {
|
||||
Closed,
|
||||
Open,
|
||||
Active,
|
||||
/// Actionable
|
||||
Open = 1630,
|
||||
/// Completed
|
||||
Done,
|
||||
/// Not Actionable (anymore)
|
||||
Closed,
|
||||
/// Temporarily not actionable
|
||||
Pending,
|
||||
/// Actionable ordered task list
|
||||
Procedure = PROCEDURE_KIND_ID as isize,
|
||||
}
|
||||
impl TryFrom<&str> for State {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match value.to_ascii_lowercase().as_str() {
|
||||
"closed" => Ok(State::Closed),
|
||||
"done" => Ok(State::Done),
|
||||
"pending" => Ok(State::Pending),
|
||||
"proc" | "procedure" | "list" => Ok(State::Procedure),
|
||||
"open" => Ok(State::Open),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl TryFrom<Kind> for State {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: Kind) -> Result<Self, Self::Error> {
|
||||
match value.as_u32() {
|
||||
1630 => Ok(State::Open),
|
||||
1631 => Ok(State::Done),
|
||||
1632 => Ok(State::Closed),
|
||||
1633 => Ok(State::Active),
|
||||
_ => Err(()),
|
||||
match value {
|
||||
Kind::GitStatusOpen => Ok(State::Open),
|
||||
Kind::GitStatusApplied => Ok(State::Done),
|
||||
Kind::GitStatusClosed => Ok(State::Closed),
|
||||
Kind::GitStatusDraft => Ok(State::Pending),
|
||||
_ => {
|
||||
if value == PROCEDURE_KIND {
|
||||
Ok(State::Procedure)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
impl State {
|
||||
pub(crate) fn is_open(&self) -> bool {
|
||||
match self {
|
||||
State::Open | State::Active => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, State::Open | State::Pending | State::Procedure)
|
||||
}
|
||||
|
||||
pub(crate) fn kind(&self) -> Kind {
|
||||
pub(crate) fn kind(self) -> u16 {
|
||||
self as u16
|
||||
}
|
||||
|
||||
pub(crate) fn colorize(&self, str: &str) -> ColoredString {
|
||||
match self {
|
||||
State::Open => Kind::from(1630),
|
||||
State::Done => Kind::from(1631),
|
||||
State::Closed => Kind::from(1632),
|
||||
State::Active => Kind::from(1633),
|
||||
State::Open => str.green(),
|
||||
State::Done => str.bright_black(),
|
||||
State::Closed => str.magenta(),
|
||||
State::Pending => str.yellow(),
|
||||
State::Procedure => str.blue(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<State> for Kind {
|
||||
fn from(value: State) -> Self {
|
||||
Kind::from(value.kind())
|
||||
}
|
||||
}
|
||||
impl Display for State {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tasks_test {
|
||||
use super::*;
|
||||
use nostr_sdk::{EventBuilder, Keys};
|
||||
|
||||
#[test]
|
||||
fn test_state() {
|
||||
let keys = Keys::generate();
|
||||
let mut task = Task::new(
|
||||
EventBuilder::new(TASK_KIND, "task").tags([Tag::hashtag("tag1")])
|
||||
.sign_with_keys(&keys).unwrap());
|
||||
assert_eq!(task.pure_state(), State::Open);
|
||||
assert_eq!(task.get_hashtags().count(), 1);
|
||||
task.props.insert(
|
||||
EventBuilder::new(State::Done.into(), "")
|
||||
.sign_with_keys(&keys).unwrap());
|
||||
assert_eq!(task.pure_state(), State::Done);
|
||||
task.props.insert(
|
||||
EventBuilder::new(State::Open.into(), "").tags([Tag::hashtag("tag2")])
|
||||
.custom_created_at(Timestamp::from(Timestamp::now() - 2))
|
||||
.sign_with_keys(&keys).unwrap());
|
||||
assert_eq!(task.pure_state(), State::Done);
|
||||
assert_eq!(task.get_hashtags().count(), 2);
|
||||
task.props.insert(
|
||||
EventBuilder::new(State::Closed.into(), "")
|
||||
.custom_created_at(Timestamp::from(Timestamp::now() + 1))
|
||||
.sign_with_keys(&keys).unwrap());
|
||||
assert_eq!(task.pure_state(), State::Closed);
|
||||
}
|
||||
}
|
||||
|
|
2330
src/tasks.rs
2330
src/tasks.rs
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue