@yaks/notify 0.0.0-stage → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +101 -2
- package/_dist/attention.d.ts +4 -0
- package/_dist/attention.d.ts.map +1 -0
- package/_dist/mod.d.ts +23 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/tab.d.ts +30 -0
- package/_dist/tab.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/whereabouts.d.ts +84 -0
- package/_dist/whereabouts.d.ts.map +1 -0
- package/attention.js +61 -0
- package/attention.js.map +1 -0
- package/attention.ts +53 -0
- package/deno.json +1 -0
- package/mod.js +43 -0
- package/mod.js.map +1 -0
- package/mod.ts +49 -0
- package/package.json +35 -4
- package/tab.js +64 -0
- package/tab.js.map +1 -0
- package/tab.ts +97 -0
- package/vocab.js +16 -0
- package/vocab.js.map +1 -0
- package/vocab.json +250 -0
- package/vocab.ts +17 -0
- package/whereabouts.js +203 -0
- package/whereabouts.js.map +1 -0
- package/whereabouts.ts +338 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/notify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Defines graph components for notifications, watch/mute preferences, and open
|
|
4
|
+
chats. These are stored records, not a notification delivery service: the
|
|
5
|
+
application decides when to create a notification and how to display or send it.
|
|
6
|
+
|
|
7
|
+
## Stored data
|
|
8
|
+
|
|
9
|
+
An entity is a record identified by `entity.eid`; components are named objects
|
|
10
|
+
on that record.
|
|
11
|
+
|
|
12
|
+
- `knock{target, from}` records a nudge aimed at another entity, one that asks
|
|
13
|
+
for attention. Put its message in a `doc{body}` component from
|
|
14
|
+
[@yaks/doc](../doc) on the same record. `from` names whose act or words it
|
|
15
|
+
tells, where it tells someone's: the actor who finished a task, the person who
|
|
16
|
+
sent a text. A knock its writer says for itself leaves it out.
|
|
17
|
+
- `notification{to, about, from}` records words emitted, not said, telling `to`
|
|
18
|
+
what happened to `about` (either may live in another graph). `to` is a person,
|
|
19
|
+
or a space or project for everyone standing in it. `from` is the entry it was
|
|
20
|
+
written from, where its reader opens the conversation it came from. Its words
|
|
21
|
+
are its `doc{body}`. It is a thread of its own; @yaks/inbox lanes it as
|
|
22
|
+
Updates. It is not a letter, so it carries no [@yaks/mail](../mail) `deliver`.
|
|
23
|
+
- `reply{to}` records that a row's words answer words somebody said: `to` is the
|
|
24
|
+
entry, comment or letter it answers. A notification carrying it tells its
|
|
25
|
+
reader the answer to what they wrote, and is shown as its own words.
|
|
26
|
+
- `subscription{actor, target, mode}` records whether an actor watches (`watch`)
|
|
27
|
+
or mutes (`mute`) a target. The actor is the entity identifying the recipient.
|
|
28
|
+
An absent mode neither watches nor mutes. Personal `opened{at, by, via}` and
|
|
29
|
+
`archived{at, by, via}` marks from [@yaks/kernel](../kernel) sit on this row,
|
|
30
|
+
not on the target; clearing the mode preserves attention.
|
|
31
|
+
- `chat{actor, target}` records an open conversation with a target.
|
|
32
|
+
- `whereabouts{person, channel, place, state, at}` records where a person is
|
|
33
|
+
available on one channel, as it last changed: the Operator's page of the space
|
|
34
|
+
`place` (`here`, focused; `background`, open but hidden or unfocused; `away`),
|
|
35
|
+
an app's page or another yaks.app page (the same three, `place` the app),
|
|
36
|
+
Discord (`online`, `idle`, `dnd`, `offline`), and a text or an email (`used`).
|
|
37
|
+
One row per person, channel and place (`whereaboutsEid`).
|
|
38
|
+
|
|
39
|
+
## Whereabouts
|
|
40
|
+
|
|
41
|
+
`@yaks/notify/whereabouts` is pure. `noted(row, said, now)` is the write a
|
|
42
|
+
channel's say needs: none when nothing changed and the row is still fresh, so a
|
|
43
|
+
page saying "still here" every `BEAT` writes about once in three. A row older
|
|
44
|
+
than its channel's `FADE` says nothing, so a lost close never leaves someone
|
|
45
|
+
here for good. A page says its tab on its socket (`{tab: {visible, focused}}`,
|
|
46
|
+
which `tabSaid` reads), and `tabsState(tabs)` is a person's state on a page
|
|
47
|
+
across their tabs. `glance(rows, {place, now})` is what one Operator sees,
|
|
48
|
+
`whereaboutsLine(name, glance)` says it in one line ("Jeff: here, this tab ·
|
|
49
|
+
Discord online"), and `reachBy(glance)` says where something that needs them
|
|
50
|
+
reaches them: `tab`, `notification`, `discord` or `usual`.
|
|
51
|
+
|
|
52
|
+
`@yaks/notify/tab` is the page's half: `sayTab(page, say)` says a page's tab at
|
|
53
|
+
once, on each change of visibility or focus, and every `BEAT`, until the
|
|
54
|
+
function it returns is called. `browserPage()` is the browser's window, none on
|
|
55
|
+
any other runtime. @yaks/client says it on its socket by default (its `page`
|
|
56
|
+
option), as yaks.app's app pages' client does.
|
|
57
|
+
|
|
58
|
+
Both `subscription` and `chat` declare uniqueness for `(actor, target)`.
|
|
59
|
+
Deleting either referenced entity cascades to its subscriptions; deleting a
|
|
60
|
+
knock's target cascades to the knock, while a notification keeps its `to` and
|
|
61
|
+
`about`, and a knock its `from`. Chat references instead use `death: detach`,
|
|
62
|
+
clearing the reference when its target is deleted.
|
|
63
|
+
|
|
64
|
+
Email belongs to [@yaks/mail](../mail), and scheduled reminders belong to
|
|
65
|
+
[@yaks/wake](../wake). This package does not send either.
|
|
66
|
+
|
|
67
|
+
## Exports and example
|
|
68
|
+
|
|
69
|
+
The root import exports `notifyDoc`, the pure `threadOf` subject policy, and
|
|
70
|
+
`attention`, atomic mark replacement bundles. `@yaks/notify/attention` exports
|
|
71
|
+
`markAttention(graph, actor, target, mark)`, which reuses the actor/target row
|
|
72
|
+
and returns patches for its personal mark. `ancestry(graph, letter)` follows
|
|
73
|
+
`mail.reply_to` by eid or Message-ID and returns the letter followed by its
|
|
74
|
+
ancestors. It checks `mail.message_id` and `notified.message_id` where the graph
|
|
75
|
+
declares them, so an empty identity created for a Message-ID reference does not
|
|
76
|
+
become the thread root. `@yaks/notify/vocab` also exports `docs: [notifyDoc]`
|
|
77
|
+
for plugin loaders. There are no tools or effect handlers here.
|
|
78
|
+
|
|
79
|
+
To refresh the mark on an existing subscription, apply the bundles returned by
|
|
80
|
+
`attention` to that subscription's eid:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { attention } from '@yaks/notify'
|
|
84
|
+
import { equal } from '@yaks/testing'
|
|
85
|
+
|
|
86
|
+
const patches = attention('release-watch', 'opened')
|
|
87
|
+
equal(patches, [
|
|
88
|
+
{ entity: { eid: 'release-watch' }, opened: null },
|
|
89
|
+
{ entity: { eid: 'release-watch' }, opened: {} },
|
|
90
|
+
])
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The first patch clears the previous mark; the second gets a fresh server stamp.
|
|
94
|
+
When the subscription's eid is unknown, use
|
|
95
|
+
`await graph.apply(await markAttention(graph, reader, release, 'opened'))`. This
|
|
96
|
+
finds or creates the actor/target row while preserving its watch/mute mode.
|
|
97
|
+
|
|
98
|
+
## Compatibility
|
|
99
|
+
|
|
100
|
+
Deno, Node and browsers. The root exports are pure; the `./attention` boundary
|
|
101
|
+
reads a graph and returns patches for its caller to apply, and `./tab` listens
|
|
102
|
+
to a page.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Graph writes for a person's subscription attention. */ import type { Bundle, Graph } from "@yaks/graph";
|
|
2
|
+
/** A letter's ancestors, resolving both graph eids and mail Message-IDs. */ export declare let ancestry: (graph: Pick<Graph, 'get' | 'read' | 'vocab'>, letter: Bundle) => Promise<Bundle[]>;
|
|
3
|
+
/** Refresh one person's attention on their existing subscription row. */ export declare let markAttention: (graph: Pick<Graph, 'read'>, actor: string, target: string, mark: 'opened' | 'archived') => Promise<Bundle[]>;
|
|
4
|
+
//# sourceMappingURL=attention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attention.d.ts","sources":["../attention.ts"],"names":[],"mappings":"AAAA,wDAAwD,GACxD,cAAc,MAAM,EAAE,KAAK,2BAAgC;AAK3D,0EAA0E,GAC1E,OAAO,YAAI,WACT,OAAO,KAAK,OAAO,QAAQ,SAAS,UACpC,QAAQ,WACP,QAAQ,UAyBV;AAED,uEAAuE,GACvE,OAAO,YAAI,gBACT,OAAO,KAAK,OAAO,SACnB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,MAAM,WAAW,eAChB,QAAQ,UASV"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Being notified. A `knock` is a nudge aimed at an entity, with the message
|
|
3
|
+
* that came with it; a `notification` tells someone what happened, a thread
|
|
4
|
+
* of its own; a `subscription` records whether somebody watches or mutes
|
|
5
|
+
* that entity, with their archived/opened attention marks on the same row;
|
|
6
|
+
* and a `chat` is an open conversation between an actor and an
|
|
7
|
+
* entity.
|
|
8
|
+
*
|
|
9
|
+
* Pure thread subjects and the notification vocabulary. Graph writes live
|
|
10
|
+
* behind the ./attention boundary.
|
|
11
|
+
*/ export { notifyDoc } from "./vocab.js";
|
|
12
|
+
/** A thread's subject, following mail reply ancestry before its target. */ export declare let threadOf: (r: ThreadRow, who?: ThreadReader, byId?: Map<string, ThreadRow>, seen?: Set<string>) => string;
|
|
13
|
+
type ThreadRow = {
|
|
14
|
+
eid: string;
|
|
15
|
+
comps: Record<string, Record<string, unknown>>;
|
|
16
|
+
};
|
|
17
|
+
type ThreadReader = {
|
|
18
|
+
actor?: string;
|
|
19
|
+
session?: string;
|
|
20
|
+
scope?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Atomic replacement gives repeated marks a fresh server timestamp. */ export declare let attention: (eid: string, mark: 'archived' | 'opened') => any;
|
|
23
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,SAAS,SAAS,qBAAoB;AAEtC,yEAAyE,GACzE,OAAO,YAAI,WACT,GAAG,WACH,MAAM,cACN,OAAO,IAAI,MAAM,EAAE,YACnB,OAAM,IAAI,MAAM,MACf,MAAM,CAkBR;KAEI;EAAc,KAAK,MAAM;EAAE,OAAO,OAAO,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO;;KACvE;EAAiB,QAAQ,MAAM;EAAE,UAAU,MAAM;EAAE,QAAQ,MAAM;;AAGtE,sEAAsE,GACtE,OAAO,YAAI,YAAa,KAAK,MAAM,EAAE,MAAM,aAAa,iBAGvD"}
|
package/_dist/tab.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a page's person is: whether its tab is visible, focused, and has
|
|
3
|
+
* recent input. The page's half of whereabouts, which
|
|
4
|
+
* @yaks/client and the yaks.app app pages' client both say through.
|
|
5
|
+
*
|
|
6
|
+
* ```ts ignore
|
|
7
|
+
* import { browserPage, sayTab } from '@yaks/notify/tab'
|
|
8
|
+
*
|
|
9
|
+
* let page = browserPage()
|
|
10
|
+
* if (page) sayTab(page, (tab) => socket.send(JSON.stringify({ tab })))
|
|
11
|
+
* ```
|
|
12
|
+
*/ import { type Clock } from "@yaks/fp";
|
|
13
|
+
import { type Tab } from "./whereabouts.js";
|
|
14
|
+
/** How long input counts toward a tab's presence. */ export declare let IDLE: any;
|
|
15
|
+
/** The page a client says its tab from: a browser's `window`, by default. */ export type Page = {
|
|
16
|
+
document: {
|
|
17
|
+
visibilityState: string;
|
|
18
|
+
hasFocus: () => boolean;
|
|
19
|
+
addEventListener: (type: string, fn: () => void, capture?: boolean) => void;
|
|
20
|
+
removeEventListener: (type: string, fn: () => void, capture?: boolean) => void;
|
|
21
|
+
};
|
|
22
|
+
addEventListener: (type: string, fn: () => void) => void;
|
|
23
|
+
removeEventListener: (type: string, fn: () => void) => void;
|
|
24
|
+
setInterval: (fn: () => void, ms: number) => unknown;
|
|
25
|
+
clearInterval: (id: unknown) => void;
|
|
26
|
+
};
|
|
27
|
+
/** The browser's page, none on any other runtime. */ export declare let browserPage: () => Page | undefined;
|
|
28
|
+
/** Say the tab's changes and renew the legacy whereabouts timestamp every
|
|
29
|
+
* `BEAT`. The returned function stops both. */ export declare let sayTab: (page: Page, say: (tab: Tab) => void, clock?: Clock) => () => void;
|
|
30
|
+
//# sourceMappingURL=tab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab.d.ts","sources":["../tab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,SAAS,KAAK,KAAK,wBAAqC;AACxD,SAAe,KAAK,GAAG,2BAA0B;AAEjD,mDAAmD,GACnD,OAAO,YAAI,UAAiB;AAW5B,2EAA2E,GAC3E,YAAY;EACV;IACE,iBAAiB,MAAM;IACvB,gBAAgB,OAAO;IACvB,mBAAmB,MAAM,MAAM,EAAE,UAAU,IAAI,EAAE,UAAU,OAAO,KAAK,IAAI;IAC3E,sBACE,MAAM,MAAM,EACZ,UAAU,IAAI,EACd,UAAU,OAAO,KACd,IAAI;;EAEX,mBAAmB,MAAM,MAAM,EAAE,UAAU,IAAI,KAAK,IAAI;EACxD,sBAAsB,MAAM,MAAM,EAAE,UAAU,IAAI,KAAK,IAAI;EAC3D,cAAc,UAAU,IAAI,EAAE,IAAI,MAAM,KAAK,OAAO;EACpD,gBAAgB,IAAI,OAAO,KAAK,IAAI;;AAGtC,mDAAmD,GACnD,OAAO,YAAI,mBAAkB,OAAO,SAAS,CAK5C;AAED;6CAC6C,GAC7C,OAAO,YAAI,SACT,MAAM,MACN,MAAM,KAAK,QAAQ,IAAI,EACvB,QAAO,gBACA,IAAI,CAoCZ"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** The notify vocabulary, in the form `loadVocab` accepts. */ export declare let notifyDoc: VocabDoc;
|
|
3
|
+
/** What this package is: its manifest's description, the one place it is
|
|
4
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
5
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
6
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AAItD,4DAA4D,GAC5D,OAAO,YAAI,WAAW,SAA0B;AAEhD;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAwB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export type Channel = 'operator' | 'apps' | 'discord' | 'text' | 'email';
|
|
2
|
+
export type State = 'here' | 'background' | 'away' | 'open' | 'online' | 'idle' | 'dnd' | 'offline' | 'used';
|
|
3
|
+
/** What a channel said of a person: `place` is which Operator (its space)
|
|
4
|
+
* or which app, for the channels a person can have several of. */ export type Said = {
|
|
5
|
+
person: string;
|
|
6
|
+
channel: Channel;
|
|
7
|
+
place?: string;
|
|
8
|
+
state: State;
|
|
9
|
+
};
|
|
10
|
+
/** A `whereabouts` row as a host reads it. */ export type Row = {
|
|
11
|
+
entity: {
|
|
12
|
+
eid: string;
|
|
13
|
+
};
|
|
14
|
+
whereabouts?: Partial<Said> & {
|
|
15
|
+
at?: string;
|
|
16
|
+
live?: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/** How long a channel's last word stands. A page says its state again while
|
|
20
|
+
* it is open ({@link BEAT}), so a page whose close was lost fades in minutes;
|
|
21
|
+
* Discord says a change only when there is one, and resends every status
|
|
22
|
+
* when its bot reconnects; a text or an email is a moment, said as "texted
|
|
23
|
+
* 2h ago" for a day. */ export declare let FADE: Record<Channel, number>;
|
|
24
|
+
/** How often an open page says its state again. */ export declare let BEAT: number;
|
|
25
|
+
/** The row a person's whereabouts on `channel` (at `place`) is kept in. */ export declare let whereaboutsEid: (person: string, channel: Channel, place?: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* The write `said` needs, given the row it replaces: none when the state is
|
|
28
|
+
* unchanged and its row is still fresh (younger than a third of its fade),
|
|
29
|
+
* so a page saying "still here" every {@link BEAT} writes about once in
|
|
30
|
+
* three, and Discord's many identical updates write once. A person never
|
|
31
|
+
* seen there who is said to be away writes nothing.
|
|
32
|
+
*/ export declare let noted: (row: Row | undefined, said: Said, now?: number) => Row | undefined;
|
|
33
|
+
/** What a tab reports on its socket. Older clients omit the input signal. */ export type Tab = {
|
|
34
|
+
visible: boolean;
|
|
35
|
+
focused: boolean;
|
|
36
|
+
idle?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** The tab a socket's frame says, none for any other frame. */ export declare let tabSaid: (frame: unknown) => Tab | undefined;
|
|
39
|
+
/** The state of a page across a person's tabs on it: `here`
|
|
40
|
+
* when one is visible and focused, `background` when one is open, `away`
|
|
41
|
+
* when none is. */ export declare let tabsState: (tabs: Tab[]) => State;
|
|
42
|
+
/** The activity visible to friends across the person's open page tabs. */ export type Activity = 'active' | 'away' | 'offline';
|
|
43
|
+
export declare let tabActivity: (tabs: Tab[]) => Activity;
|
|
44
|
+
/** The durable timestamp of when a person's first page opened or last page closed. */ export declare let pageWord: (person: string, state: State, now: number) => Row;
|
|
45
|
+
/** Read the unplaced page's history with the tabs that are still connected.
|
|
46
|
+
* A disconnected page's timestamp still stands, even when its close was lost. */ export declare let pageWhereabouts: (history: Row[], person: string, tabs: Tab[], now: number) => Row[];
|
|
47
|
+
/** Activity as seen in the computed unplaced page row. */ export declare let pageActivity: (rows: Row[]) => Activity;
|
|
48
|
+
/** Whether a channel's last word still stands. A live page follows its socket. */ export declare let fresh: (p: NonNullable<Row['whereabouts']>, now: number) => boolean;
|
|
49
|
+
/** Where a person is, at a glance, as one Operator (of `place`) sees it. */ export type Glance = {
|
|
50
|
+
/** this Operator's page: focused, or open in a background tab */ tab?: 'here' | 'background';
|
|
51
|
+
/** another Operator's page or an app's page is open */ elsewhere?: boolean;
|
|
52
|
+
discord?: 'online' | 'idle' | 'dnd' | 'offline';
|
|
53
|
+
/** when they last texted, or emailed, within a day */ texted?: string;
|
|
54
|
+
emailed?: string;
|
|
55
|
+
now: number;
|
|
56
|
+
};
|
|
57
|
+
/** The rows still standing, read as one Operator's glance: `place` is its
|
|
58
|
+
* space. */ export declare let glance: (rows: Row[], {}: {
|
|
59
|
+
place?: string;
|
|
60
|
+
now?: number;
|
|
61
|
+
}) => Glance;
|
|
62
|
+
/** Where a person is on yaks.app now, as their friends see it: `building`
|
|
63
|
+
* while an Operator's page of theirs is open, else `online` while an app's
|
|
64
|
+
* page or another yaks.app page is; `spaces` and `apps` are the places those
|
|
65
|
+
* pages name, the Operator's space and the app. */ export type Presence = {
|
|
66
|
+
state: 'building' | 'online';
|
|
67
|
+
spaces: string[];
|
|
68
|
+
apps: string[];
|
|
69
|
+
};
|
|
70
|
+
/** The presence the rows still standing say, none when no page of the
|
|
71
|
+
* person's is open. Never stored: it is read off the rows each time. */ export declare let presence: (rows: Row[], now?: number) => Presence | undefined;
|
|
72
|
+
/** When a person was last active on yaks.app: the newest word any page of
|
|
73
|
+
* theirs, or a text or an email to their Operator, said of them, faded or
|
|
74
|
+
* not. Discord's status is not something they did here. None for someone
|
|
75
|
+
* never seen. */ export declare let lastSeen: (rows: Row[]) => string | undefined;
|
|
76
|
+
/** How long ago `at` was, as a person says it: 4m, 2h, 1d. */ export declare let ago: (at: string, now: number) => string;
|
|
77
|
+
/** The glance in one short line, for each of an Operator's turns:
|
|
78
|
+
* "Jeff: here, this tab · Discord online". */ export declare let whereaboutsLine: (name: string, g: Glance) => string;
|
|
79
|
+
/** Where something that needs the person reaches them now: in the tab they
|
|
80
|
+
* are looking at, a notification when that tab is in the background or they
|
|
81
|
+
* are elsewhere on yaks.app, Discord when they are on it and not on
|
|
82
|
+
* yaks.app, and otherwise their usual channel. */ export type Reach = 'tab' | 'notification' | 'discord' | 'usual';
|
|
83
|
+
export declare let reachBy: (g: Glance) => Reach;
|
|
84
|
+
//# sourceMappingURL=whereabouts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whereabouts.d.ts","sources":["../whereabouts.ts"],"names":[],"mappings":"AA8BA,YAAY,UAAU,aAAa,SAAS,YAAY,SAAS;AACjE,YAAY,QACR,SACA,eACA,SACA,SACA,WACA,SACA,QACA,YACA;AAEJ;gEACgE,GAChE,YAAY;EACV,QAAQ,MAAM;EACd,SAAS;EACT,QAAQ,MAAM;EACd,OAAO;;AAGT,4CAA4C,GAC5C,YAAY;EACV;IAAU,KAAK,MAAM;;EACrB,cAAc,QAAQ;IAAU,KAAK,MAAM;IAAE,OAAO,OAAO;;;AAM7D;;;;sBAIsB,GACtB,OAAO,YAAI,MAAM,OAAO,SAAS,MAAM,EAMtC;AAED,iDAAiD,GACjD,OAAO,YAAI,MAAM,MAAM,CAAa;AAKpC,yEAAyE,GACzE,OAAO,YAAI,iBACT,QAAQ,MAAM,EACd,SAAS,SACT,QAAQ,MAAM,KACb,MAAM,CAAiE;AAE1E;;;;;;CAMC,GACD,OAAO,YAAI,QACT,KAAK,MAAM,SAAS,EACpB,MAAM,MACN,MAAK,MAAM,KACV,MAAM,SAAS,CAkBjB;AAED,2EAA2E,GAC3E,YAAY;EAAQ,SAAS,OAAO;EAAE,SAAS,OAAO;EAAE,OAAO,OAAO;;AAEtE,6DAA6D,GAC7D,OAAO,YAAI,UAAW,OAAO,OAAO,KAAG,MAAM,SAAS,CASrD;AAED;;iBAEiB,GACjB,OAAO,YAAI,YAAa,MAAM,UAAQ,MAK1B;AAEZ,wEAAwE,GACxE,YAAY,WAAW,WAAW,SAAS;AAE3C,OAAO,YAAI,cAAe,MAAM,UAAQ,SAKzB;AAEf,oFAAoF,GACpF,OAAO,YAAI,WAAY,QAAQ,MAAM,EAAE,OAAO,OAAO,KAAK,MAAM,KAAG,IAQjE;AAEF;+EAC+E,GAC/E,OAAO,YAAI,kBACT,SAAS,OACT,QAAQ,MAAM,EACd,MAAM,OACN,KAAK,MAAM,KACV,MAkBF;AAED,wDAAwD,GACxD,OAAO,YAAI,eAAgB,MAAM,UAAQ,SAOxC;AAED,gFAAgF,GAChF,OAAO,YAAI,QAAS,GAAG,YAAY,IAAI,iBAAiB,KAAK,MAAM,KAAG,OAAO,CACC;AAE9E,0EAA0E,GAC1E,YAAY;EACV,+DAA+D,GAC/D,MAAM,SAAS;EACf,qDAAqD,GACrD,YAAY,OAAO;EACnB,UAAU,WAAW,SAAS,QAAQ;EACtC,oDAAoD,GACpD,SAAS,MAAM;EACf,UAAU,MAAM;EAChB,KAAK,MAAM;;AAGb;UACU,GACV,OAAO,YAAI,SACT,MAAM,OACN;EAA+B,QAAQ,MAAM;EAAE,MAAM,MAAM;CAAE,KAC5D,OAkBF;AAED;;;iDAGiD,GACjD,YAAY;EACV,OAAO,aAAa;EACpB,QAAQ,MAAM;EACd,MAAM,MAAM;;AAGd;sEACsE,GACtE,OAAO,YAAI,WACT,MAAM,OACN,MAAK,MAAM,KACV,WAAW,SAAS,CAiBtB;AAED;;;eAGe,GACf,OAAO,YAAI,WAAY,MAAM,UAAQ,MAAM,GAAG,SAAS,CAMtD;AAID,4DAA4D,GAC5D,OAAO,YAAI,MAAO,IAAI,MAAM,EAAE,KAAK,MAAM,KAAG,MAAM,CAOjD;AASD;4CAC4C,GAC5C,OAAO,YAAI,kBAAmB,MAAM,MAAM,EAAE,GAAG,WAAS,MAAM,CAc7D;AAED;;;gDAGgD,GAChD,YAAY,QAAQ,QAAQ,iBAAiB,YAAY;AACzD,OAAO,YAAI,UAAW,GAAG,WAAS,MAOrB"}
|
package/attention.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Graph writes for a person's subscription attention. */ import { mint } from "@yaks/graph/identity";
|
|
2
|
+
import { joined, line, sub } from "@yaks/query";
|
|
3
|
+
import { attention } from "./mod.js";
|
|
4
|
+
/** A letter's ancestors, resolving both graph eids and mail Message-IDs. */ export let ancestry = async (graph, letter)=>{
|
|
5
|
+
let found = [
|
|
6
|
+
letter
|
|
7
|
+
], seen = new Set([
|
|
8
|
+
letter.entity.eid
|
|
9
|
+
]);
|
|
10
|
+
let parent = async (ref)=>{
|
|
11
|
+
let [row] = await graph.get([
|
|
12
|
+
ref
|
|
13
|
+
], undefined, {
|
|
14
|
+
native: true
|
|
15
|
+
});
|
|
16
|
+
// A legacy Message-ID reference may have minted only an entity spine.
|
|
17
|
+
// The ancestor is a letter or sent notification, not that empty identity.
|
|
18
|
+
if (row?.mail || row?.notified) return row;
|
|
19
|
+
let paths = [
|
|
20
|
+
'mail.message_id',
|
|
21
|
+
'notified.message_id'
|
|
22
|
+
].filter((path)=>{
|
|
23
|
+
let [name, prop] = path.split('.');
|
|
24
|
+
return !!graph.vocab.comp(name) && graph.vocab.props(name).includes(prop);
|
|
25
|
+
});
|
|
26
|
+
if (!paths.length) return;
|
|
27
|
+
let q = joined(paths.map((path)=>line`.${path}=${ref}`), '|');
|
|
28
|
+
return (await graph.read(line`(${sub(q)})&*`, {
|
|
29
|
+
native: true
|
|
30
|
+
}))[0];
|
|
31
|
+
};
|
|
32
|
+
for(let current = letter;;){
|
|
33
|
+
let ref = String(current.mail?.reply_to ?? '');
|
|
34
|
+
if (!ref) break;
|
|
35
|
+
let up = await parent(ref);
|
|
36
|
+
if (!up || seen.has(up.entity.eid)) break;
|
|
37
|
+
seen.add(up.entity.eid);
|
|
38
|
+
found.push(up);
|
|
39
|
+
current = up;
|
|
40
|
+
}
|
|
41
|
+
return found;
|
|
42
|
+
};
|
|
43
|
+
/** Refresh one person's attention on their existing subscription row. */ export let markAttention = async (graph, actor, target, mark)=>{
|
|
44
|
+
let [had] = await graph.read(line`.subscription.actor=${actor}&.subscription.target=${target}&.fields=entity.eid`);
|
|
45
|
+
let eid = had?.entity.eid ?? mint();
|
|
46
|
+
return [
|
|
47
|
+
...had ? [] : [
|
|
48
|
+
{
|
|
49
|
+
entity: {
|
|
50
|
+
eid
|
|
51
|
+
},
|
|
52
|
+
subscription: {
|
|
53
|
+
actor,
|
|
54
|
+
target
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
...attention(eid, mark)
|
|
59
|
+
];
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=attention.js.map
|
package/attention.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attention.js","sources":["./attention.ts"],"names":[],"mappings":"AAAA,wDAAwD,GAExD,SAAS,IAAI,oCAAyC;AACtD,SAAS,MAAM,EAAE,IAAI,EAAE,GAAG,2BAAgC;AAC1D,SAAS,SAAS,mBAAkB;AAEpC,0EAA0E,GAC1E,OAAO,IAAI,WAAW,OACpB,OACA;EAEA,IAAI,QAAQ;IAAC;GAAO,EAAE,OAAO,IAAI,IAAI;IAAC,OAAO,MAAM,CAAC,GAAG;GAAC;EACxD,IAAI,SAAS,OAAO;IAClB,IAAI,CAAC,IAAI,GAAG,MAAM,MAAM,GAAG,CAAC;MAAC;KAAI,EAAE,WAAW;MAAE,QAAQ;IAAK;IAC7D,sEAAsE;IACtE,0EAA0E;IAC1E,IAAI,KAAK,QAAQ,KAAK,UAAU,OAAO;IACvC,IAAI,QAAQ;MAAC;MAAmB;KAAsB,CAAC,MAAM,CAAC,CAAC;MAC7D,IAAI,CAAC,MAAM,KAAK,GAAG,KAAK,KAAK,CAAC;MAC9B,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC;IACtE;IACA,IAAI,CAAC,MAAM,MAAM,EAAE;IACnB,IAAI,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,OAAS,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG;IAC3D,OAAO,CAAC,MAAM,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC,EAAE;MAAE,QAAQ;IAAK,EAAE,CAAC,CAAC,EAAE;EACrE;EACA,IAAK,IAAI,UAAU,SAAU;IAC3B,IAAI,MAAM,OAAO,AAAC,QAAQ,IAAI,EAA8B,YAAY;IACxE,IAAI,CAAC,KAAK;IACV,IAAI,KAAK,MAAM,OAAO;IACtB,IAAI,CAAC,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG;IACpC,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG;IACtB,MAAM,IAAI,CAAC;IACX,UAAU;EACZ;EACA,OAAO;AACT,EAAC;AAED,uEAAuE,GACvE,OAAO,IAAI,gBAAgB,OACzB,OACA,OACA,QACA;EAEA,IAAI,CAAC,IAAI,GAAG,MAAM,MAAM,IAAI,CAC1B,IAAI,CAAC,oBAAoB,EAAE,MAAM,sBAAsB,EAAE,OAAO,mBAAmB,CAAC;EAEtF,IAAI,MAAM,KAAK,OAAO,OAAO;EAC7B,OAAO;OACD,MAAM,EAAE,GAAG;MAAC;QAAE,QAAQ;UAAE;QAAI;QAAG,cAAc;UAAE;UAAO;QAAO;MAAE;KAAE;OAClE,UAAU,KAAK;GACnB;AACH,EAAC"}
|
package/attention.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Graph writes for a person's subscription attention. */
|
|
2
|
+
import type { Bundle, Graph } from 'jsr:@yaks/graph@0.2.36'
|
|
3
|
+
import { mint } from '@yaks/graph/identity'
|
|
4
|
+
import { joined, line, sub } from '@yaks/query'
|
|
5
|
+
import { attention } from './mod.js'
|
|
6
|
+
|
|
7
|
+
/** A letter's ancestors, resolving both graph eids and mail Message-IDs. */
|
|
8
|
+
export let ancestry = async (
|
|
9
|
+
graph: Pick<Graph, 'get' | 'read' | 'vocab'>,
|
|
10
|
+
letter: Bundle,
|
|
11
|
+
): Promise<Bundle[]> => {
|
|
12
|
+
let found = [letter], seen = new Set([letter.entity.eid])
|
|
13
|
+
let parent = async (ref: string): Promise<Bundle | undefined> => {
|
|
14
|
+
let [row] = await graph.get([ref], undefined, { native: true })
|
|
15
|
+
// A legacy Message-ID reference may have minted only an entity spine.
|
|
16
|
+
// The ancestor is a letter or sent notification, not that empty identity.
|
|
17
|
+
if (row?.mail || row?.notified) return row
|
|
18
|
+
let paths = ['mail.message_id', 'notified.message_id'].filter((path) => {
|
|
19
|
+
let [name, prop] = path.split('.')
|
|
20
|
+
return !!graph.vocab.comp(name) && graph.vocab.props(name).includes(prop)
|
|
21
|
+
})
|
|
22
|
+
if (!paths.length) return
|
|
23
|
+
let q = joined(paths.map((path) => line`.${path}=${ref}`), '|')
|
|
24
|
+
return (await graph.read(line`(${sub(q)})&*`, { native: true }))[0]
|
|
25
|
+
}
|
|
26
|
+
for (let current = letter;;) {
|
|
27
|
+
let ref = String((current.mail as Record<string, unknown>)?.reply_to ?? '')
|
|
28
|
+
if (!ref) break
|
|
29
|
+
let up = await parent(ref)
|
|
30
|
+
if (!up || seen.has(up.entity.eid)) break
|
|
31
|
+
seen.add(up.entity.eid)
|
|
32
|
+
found.push(up)
|
|
33
|
+
current = up
|
|
34
|
+
}
|
|
35
|
+
return found
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Refresh one person's attention on their existing subscription row. */
|
|
39
|
+
export let markAttention = async (
|
|
40
|
+
graph: Pick<Graph, 'read'>,
|
|
41
|
+
actor: string,
|
|
42
|
+
target: string,
|
|
43
|
+
mark: 'opened' | 'archived',
|
|
44
|
+
): Promise<Bundle[]> => {
|
|
45
|
+
let [had] = await graph.read(
|
|
46
|
+
line`.subscription.actor=${actor}&.subscription.target=${target}&.fields=entity.eid`,
|
|
47
|
+
)
|
|
48
|
+
let eid = had?.entity.eid ?? mint()
|
|
49
|
+
return [
|
|
50
|
+
...(had ? [] : [{ entity: { eid }, subscription: { actor, target } }]),
|
|
51
|
+
...attention(eid, mark),
|
|
52
|
+
]
|
|
53
|
+
}
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/notify","version":"0.2.36","license":"Apache-2.0","description":"How somebody is notified: a knock aimed at an entity, what they watch or mute, an open conversation, and where they are available right now.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./attention":"./attention.ts","./whereabouts":"./whereabouts.ts","./tab":"./tab.ts"},"imports":{"@yaks/notify":"./mod.ts","@yaks/notify/vocab":"./vocab.ts","@yaks/notify/attention":"./attention.ts","@yaks/notify/whereabouts":"./whereabouts.ts","@yaks/notify/tab":"./tab.ts"}}
|
package/mod.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Being notified. A `knock` is a nudge aimed at an entity, with the message
|
|
3
|
+
* that came with it; a `notification` tells someone what happened, a thread
|
|
4
|
+
* of its own; a `subscription` records whether somebody watches or mutes
|
|
5
|
+
* that entity, with their archived/opened attention marks on the same row;
|
|
6
|
+
* and a `chat` is an open conversation between an actor and an
|
|
7
|
+
* entity.
|
|
8
|
+
*
|
|
9
|
+
* Pure thread subjects and the notification vocabulary. Graph writes live
|
|
10
|
+
* behind the ./attention boundary.
|
|
11
|
+
*/ export { notifyDoc } from "./vocab.js";
|
|
12
|
+
/** A thread's subject, following mail reply ancestry before its target. */ export let threadOf = (r, who, byId, seen = new Set())=>{
|
|
13
|
+
let reply = str(r.comps.mail?.reply_to);
|
|
14
|
+
if (reply && byId?.has(reply) && !seen.has(r.eid)) {
|
|
15
|
+
seen.add(r.eid);
|
|
16
|
+
return threadOf(byId.get(reply), who, byId, seen);
|
|
17
|
+
}
|
|
18
|
+
let target = r.comps.mail && who && [
|
|
19
|
+
who.actor,
|
|
20
|
+
who.session,
|
|
21
|
+
who.scope
|
|
22
|
+
].includes(str(r.comps.mail.target)) ? '' : String(r.comps.comment?.target ?? r.comps.mail?.target ?? r.comps.knock?.target ?? '');
|
|
23
|
+
// A question is a thread of its own, even said as a line of a
|
|
24
|
+
// conversation: it waits on whom it asks, apart from what was said there.
|
|
25
|
+
if (r.comps.decision) return target || r.eid;
|
|
26
|
+
return target || str(r.comps.entry?.session ?? r.comps.commit?.target) || r.eid;
|
|
27
|
+
};
|
|
28
|
+
let str = (v)=>String(v ?? '');
|
|
29
|
+
/** Atomic replacement gives repeated marks a fresh server timestamp. */ export let attention = (eid, mark)=>[
|
|
30
|
+
{
|
|
31
|
+
entity: {
|
|
32
|
+
eid
|
|
33
|
+
},
|
|
34
|
+
[mark]: null
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
entity: {
|
|
38
|
+
eid
|
|
39
|
+
},
|
|
40
|
+
[mark]: {}
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
//# sourceMappingURL=mod.js.map
|