pi-roundtable-web 0.23.1 → 0.23.2

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.
@@ -23,6 +23,11 @@ export interface PushServiceOptions {
23
23
  logger: Logger;
24
24
  /** The clock, in milliseconds; default `Date.now`. */
25
25
  now?: () => number;
26
+ /**
27
+ * Whether a moment, in milliseconds, is in the quiet hours: an agent's post and a notice are
28
+ * not pushed then, while a card is. Default never.
29
+ */
30
+ quiet?: (at: number) => boolean;
26
31
  }
27
32
 
28
33
  /** What a trigger says; the service shapes it into a notification. */
@@ -49,7 +54,8 @@ export function previewOf(text: string): string {
49
54
  /**
50
55
  * Decides when an owner's devices are pushed and what is said. Each trigger pushes only while no
51
56
  * page of an owner is in view, and only to owners: a device whose person is no owner any more is
52
- * skipped. Delivery never throws into the code that raised the trigger.
57
+ * skipped. In the quiet hours an agent's post and a notice wait for the owner to look; a card,
58
+ * which holds up work, is still pushed. Delivery never throws into the code that raised the trigger.
53
59
  */
54
60
  export class PushService {
55
61
  readonly #options: PushServiceOptions;
@@ -72,7 +78,8 @@ export class PushService {
72
78
 
73
79
  /** An agent posted in a room, such as a finished job's report or an answer nobody was watching for. */
74
80
  reply(room: string, author: string, text: string): Promise<void> {
75
- const now = (this.#options.now ?? Date.now)();
81
+ const now = this.#now();
82
+ if (this.#options.quiet?.(now)) return Promise.resolve();
76
83
  const last = this.#repliedAt.get(room);
77
84
  if (last !== undefined && now - last < REPLY_QUIET_MS)
78
85
  return Promise.resolve();
@@ -88,6 +95,7 @@ export class PushService {
88
95
 
89
96
  /** A notice for one person, from the `notify` tool. */
90
97
  notice(principalId: string, text: string, room?: string): Promise<void> {
98
+ if (this.#options.quiet?.(this.#now())) return Promise.resolve();
91
99
  return this.#push({
92
100
  kind: "notice",
93
101
  title: "Notice",
@@ -98,6 +106,10 @@ export class PushService {
98
106
  });
99
107
  }
100
108
 
109
+ #now(): number {
110
+ return (this.#options.now ?? Date.now)();
111
+ }
112
+
101
113
  async #push(event: Event): Promise<void> {
102
114
  const { logger, preview } = this.#options;
103
115
  try {
package/src/web-plugin.ts CHANGED
@@ -153,6 +153,10 @@ async function build(settings: ResolvedOptions, context: Context) {
153
153
  vapid,
154
154
  subject: settings.push.subject,
155
155
  preview: settings.push.preview,
156
+ ...(settings.push.quietHours
157
+ ? { quietHours: settings.push.quietHours }
158
+ : {}),
159
+ timeZone: env.timeZone,
156
160
  endpointHosts: settings.push.endpointHosts,
157
161
  ...(settings.push.fetch ? { fetch: settings.push.fetch } : {}),
158
162
  urlOf: (room) =>