inboxer 0.4.0 → 0.4.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.
- package/dist/core/mail.d.ts +8 -0
- package/dist/core/mail.js +17 -8
- package/dist/ui/routes.js +33 -7
- package/dist/ui/static/app.js +2 -7
- package/dist/ui/strings.d.ts +1 -0
- package/dist/ui/strings.js +1 -0
- package/dist/ui/views.d.ts +7 -2
- package/dist/ui/views.js +31 -26
- package/package.json +1 -1
- package/src/core/mail.ts +18 -8
- package/src/ui/routes.ts +30 -7
- package/src/ui/static/app.js +2 -7
- package/src/ui/strings.ts +1 -0
- package/src/ui/views.ts +33 -27
package/dist/core/mail.d.ts
CHANGED
|
@@ -126,6 +126,14 @@ export declare class Mail {
|
|
|
126
126
|
archived?: boolean;
|
|
127
127
|
}, actor: Actor): Promise<number>;
|
|
128
128
|
createDraft(input: CreateDraftInput, actor: Actor): Promise<Message>;
|
|
129
|
+
/** Who a reply to `replyToId` goes to and its subject, without creating anything. */
|
|
130
|
+
replyTo(replyToId: string, replyAll: boolean, scope: Scope): Promise<{
|
|
131
|
+
mailbox: string;
|
|
132
|
+
to: string[];
|
|
133
|
+
cc: string[];
|
|
134
|
+
subject: string;
|
|
135
|
+
}>;
|
|
136
|
+
private replyDefaults;
|
|
129
137
|
private createDraftUnlocked;
|
|
130
138
|
private requireDraft;
|
|
131
139
|
/**
|
package/dist/core/mail.js
CHANGED
|
@@ -333,6 +333,17 @@ export class Mail {
|
|
|
333
333
|
createDraft(input, actor) {
|
|
334
334
|
return this.store.serialize(() => this.createDraftUnlocked(input, actor));
|
|
335
335
|
}
|
|
336
|
+
/** Who a reply to `replyToId` goes to and its subject, without creating anything. */
|
|
337
|
+
async replyTo(replyToId, replyAll, scope) {
|
|
338
|
+
return this.replyDefaults(await this.requireMessage(replyToId, scope), {}, replyAll);
|
|
339
|
+
}
|
|
340
|
+
replyDefaults(original, given, replyAll) {
|
|
341
|
+
const mailbox = given.mailbox ?? original.mailbox;
|
|
342
|
+
const to = given.to ?? (original.direction === "in" ? (original.reply_to.length ? original.reply_to : [original.from]) : original.to);
|
|
343
|
+
const already = new Set([bareAddress(this.sendingMailbox(mailbox).address), ...to.map(bareAddress)]);
|
|
344
|
+
const cc = replyAll ? [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a))) : [];
|
|
345
|
+
return { mailbox, to, cc, subject: replySubject(original.subject) };
|
|
346
|
+
}
|
|
336
347
|
async createDraftUnlocked(input, actor) {
|
|
337
348
|
const now = new Date().toISOString();
|
|
338
349
|
let mailbox;
|
|
@@ -344,14 +355,12 @@ export class Mail {
|
|
|
344
355
|
let threadId;
|
|
345
356
|
if (input.replyToId) {
|
|
346
357
|
const original = await this.requireMessage(input.replyToId, actor.scope);
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
to =
|
|
350
|
-
if (
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
subject = input.subject ?? replySubject(original.subject);
|
|
358
|
+
const defaults = this.replyDefaults(original, input, !!input.replyAll && !input.cc);
|
|
359
|
+
mailbox = defaults.mailbox;
|
|
360
|
+
to = defaults.to;
|
|
361
|
+
if (!input.cc)
|
|
362
|
+
cc = defaults.cc;
|
|
363
|
+
subject = input.subject ?? defaults.subject;
|
|
355
364
|
inReplyTo = original.message_id;
|
|
356
365
|
references = original.message_id ? [...original.references, original.message_id] : original.references;
|
|
357
366
|
threadId = original.thread_id;
|
package/dist/ui/routes.js
CHANGED
|
@@ -221,16 +221,42 @@ export function registerUi(app, mail, access, cfg) {
|
|
|
221
221
|
return page(c, thread.subject || S.navInbox, V.inboxPage(await threadList(c, id), view), "inbox", 200, true);
|
|
222
222
|
});
|
|
223
223
|
/** Replies to the latest message; a reply sent from here gets the same undo window as a draft. */
|
|
224
|
-
/**
|
|
225
|
-
app.
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
const { messages } = await mail.getThread(
|
|
224
|
+
/** The reply box's full form, for Cc, subject and files; nothing is created until it is posted. */
|
|
225
|
+
app.get("/threads/:id/reply/full", async (c) => {
|
|
226
|
+
const id = c.req.param("id");
|
|
227
|
+
const scope = c.get("session").scope;
|
|
228
|
+
const { messages } = await mail.getThread(id, scope);
|
|
229
229
|
const latest = messages.filter(m => m.status !== "draft").at(-1);
|
|
230
230
|
if (!latest)
|
|
231
231
|
throw new InvalidRequestError("nothing to reply to");
|
|
232
|
-
const
|
|
233
|
-
|
|
232
|
+
const reply = await mail.replyTo(latest.id, c.req.query("reply_all") === "1", scope);
|
|
233
|
+
const fields = { to: reply.to.join(", "), cc: reply.cc.join(", "), subject: reply.subject, text: c.req.query("text") ?? "" };
|
|
234
|
+
return c.html(V.replyForm(id, V.inboxQuery(inboxFilter(c)), latest.id, fields));
|
|
235
|
+
});
|
|
236
|
+
app.post("/threads/:id/reply/full", async (c) => {
|
|
237
|
+
const actor = uiActor(c.get("session"));
|
|
238
|
+
const body = await c.req.parseBody({ all: true });
|
|
239
|
+
const { files, error } = uploads(body);
|
|
240
|
+
if (error)
|
|
241
|
+
return page(c, S.reply, V.message([error]), "inbox", 400);
|
|
242
|
+
try {
|
|
243
|
+
const draft = await mail.createDraft({
|
|
244
|
+
replyToId: String(body.reply_to_id ?? ""),
|
|
245
|
+
to: splitAddresses(String(body.to ?? "")),
|
|
246
|
+
cc: splitAddresses(String(body.cc ?? "")),
|
|
247
|
+
subject: String(body.subject ?? ""),
|
|
248
|
+
text: String(body.text ?? ""),
|
|
249
|
+
}, actor);
|
|
250
|
+
await attachAll(draft.id, files, actor);
|
|
251
|
+
if (body.action === "send")
|
|
252
|
+
await mail.schedule(draft.id, "send", actor);
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
if (err instanceof InvalidRequestError)
|
|
256
|
+
return page(c, S.reply, V.message([err.message]), "inbox", 400);
|
|
257
|
+
throw err;
|
|
258
|
+
}
|
|
259
|
+
return c.redirect(`/threads/${c.req.param("id")}?${V.inboxQuery(inboxFilter(c))}`, 303);
|
|
234
260
|
});
|
|
235
261
|
app.post("/threads/:id/reply", async (c) => {
|
|
236
262
|
const id = c.req.param("id");
|
package/dist/ui/static/app.js
CHANGED
|
@@ -23,14 +23,9 @@ document.addEventListener("htmx:afterSwap", event => {
|
|
|
23
23
|
sheet.querySelector("textarea")?.focus();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
// Closing the sheet on a reply started from the reply box shows its new draft in the thread.
|
|
27
|
-
document.addEventListener("close", event => {
|
|
28
|
-
if (event.target.id === "edit-sheet" && event.target.querySelector("[data-reload-on-close]")) location.reload();
|
|
29
|
-
}, true);
|
|
30
|
-
|
|
31
26
|
document.addEventListener("change", event => {
|
|
32
|
-
if (event.target.
|
|
33
|
-
|
|
27
|
+
if (event.target.matches("[data-file-names]")) {
|
|
28
|
+
event.target.closest("form").querySelector(".sheet-files").textContent = [...event.target.files].map(f => f.name).join(", ");
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
|
package/dist/ui/strings.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare const S: {
|
|
|
38
38
|
readonly newMail: "New mail";
|
|
39
39
|
readonly saveDraft: "Save draft";
|
|
40
40
|
readonly reply: "Reply";
|
|
41
|
+
readonly fullReply: "Reply with Cc and attachments";
|
|
41
42
|
readonly replyAll: "Reply all";
|
|
42
43
|
readonly today: "Today";
|
|
43
44
|
readonly yesterday: "Yesterday";
|
package/dist/ui/strings.js
CHANGED
package/dist/ui/views.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface LayoutOptions {
|
|
|
19
19
|
fullScreen?: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare function layout(title: string, body: View, opts: LayoutOptions): View;
|
|
22
|
+
/** A reply opened from the reply box, shown in the edit sheet; nothing is saved until Save or Send. */
|
|
23
|
+
export declare function replyForm(threadId: string, query: string, replyToId: string, fields: {
|
|
24
|
+
to: string;
|
|
25
|
+
cc: string;
|
|
26
|
+
subject: string;
|
|
27
|
+
text: string;
|
|
28
|
+
}): View;
|
|
22
29
|
export declare function message(lines: string[]): View;
|
|
23
30
|
export declare function signIn(token: string, valid: boolean): View;
|
|
24
31
|
/** Image types a browser renders without running code; SVG is left out on purpose. */
|
|
@@ -39,8 +46,6 @@ export interface DraftForm {
|
|
|
39
46
|
}
|
|
40
47
|
/** The edit sheet's content; one draft is edited at a time. */
|
|
41
48
|
export declare function draftEditor(d: Message, form: DraftForm, conflict: Message | null): View;
|
|
42
|
-
/** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
|
|
43
|
-
export declare function newReplyEditor(d: Message): View;
|
|
44
49
|
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
45
50
|
export declare function draftFiles(d: Message, error: string | null): View;
|
|
46
51
|
export declare function draftDone(id: string, text: string): View;
|
package/dist/ui/views.js
CHANGED
|
@@ -102,38 +102,47 @@ ${when(opts.signedIn, () => h `<dialog class="sheet" id="edit-sheet" aria-label=
|
|
|
102
102
|
}
|
|
103
103
|
/** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
|
|
104
104
|
function composeDialog(senders) {
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const from = senders.length > 1
|
|
106
|
+
? h `<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h `<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
107
|
+
: h `<input type="hidden" name="mailbox" value="${senders[0].id}"><output id="compose-from">${senders[0].address}</output>`;
|
|
108
|
+
return h `<dialog class="sheet" id="compose" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
|
|
109
|
+
head: h `<div class="field compact"><label for="compose-from">${S.from}</label>${from}</div>`, to: "", cc: "", subject: "", text: "",
|
|
110
|
+
})}</dialog>`;
|
|
111
|
+
}
|
|
112
|
+
/** A reply opened from the reply box, shown in the edit sheet; nothing is saved until Save or Send. */
|
|
113
|
+
export function replyForm(threadId, query, replyToId, fields) {
|
|
114
|
+
return mailForm("reply", `/threads/${threadId}/reply/full?${query}`, {
|
|
115
|
+
...fields,
|
|
116
|
+
head: h `<input type="hidden" name="reply_to_id" value="${replyToId}"><div class="sheet-head"></div>`,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** New mail and the full reply: recipients, subject, body and files, saved or sent in one post. */
|
|
120
|
+
function mailForm(id, action, f) {
|
|
121
|
+
return h `<form method="post" action="${action}" enctype="multipart/form-data" data-drop>
|
|
107
122
|
<div class="grabber" aria-hidden="true"></div>
|
|
108
123
|
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
109
|
-
|
|
110
|
-
<label for="compose-from">${S.from}</label>
|
|
111
|
-
${senders.length > 1
|
|
112
|
-
? h `<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h `<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
113
|
-
: h `<input type="hidden" name="mailbox" value="${senders[0].id}"><output id="compose-from">${senders[0].address}</output>`}
|
|
114
|
-
</div>
|
|
124
|
+
${f.head}
|
|
115
125
|
<div class="field">
|
|
116
|
-
<label for="
|
|
117
|
-
<input id="
|
|
118
|
-
|
|
126
|
+
<label for="${id}-to">${S.to}</label>
|
|
127
|
+
<input id="${id}-to" name="to" value="${f.to}" autocomplete="off" required>
|
|
128
|
+
${when(!f.cc, () => h `<button type="button" class="link" onclick="this.remove();var r=document.getElementById('${id}-cc-row');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
119
129
|
</div>
|
|
120
|
-
<div class="field" id="
|
|
121
|
-
<label for="
|
|
122
|
-
<input id="
|
|
130
|
+
<div class="field" id="${id}-cc-row" ${raw(f.cc ? "" : "hidden")}>
|
|
131
|
+
<label for="${id}-cc">${S.cc}</label>
|
|
132
|
+
<input id="${id}-cc" name="cc" value="${f.cc}" autocomplete="off">
|
|
123
133
|
</div>
|
|
124
134
|
<div class="field">
|
|
125
|
-
<label for="
|
|
126
|
-
<input id="
|
|
135
|
+
<label for="${id}-subject">${S.subject}</label>
|
|
136
|
+
<input id="${id}-subject" name="subject" value="${f.subject}" required>
|
|
127
137
|
</div>
|
|
128
|
-
<textarea name="text" aria-label="${S.body}" required
|
|
138
|
+
<textarea name="text" aria-label="${S.body}" required>${f.text}</textarea>
|
|
129
139
|
<div class="sheet-actions">
|
|
130
|
-
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files"
|
|
131
|
-
<output class="sheet-files"
|
|
140
|
+
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden data-file-names></label>
|
|
141
|
+
<output class="sheet-files"></output>
|
|
132
142
|
<button type="submit" name="action" value="save">${S.saveDraft}</button>
|
|
133
143
|
<button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
|
|
134
144
|
</div>
|
|
135
|
-
</form
|
|
136
|
-
</dialog>`;
|
|
145
|
+
</form>`;
|
|
137
146
|
}
|
|
138
147
|
export function message(lines) {
|
|
139
148
|
return h `<div class="centered">${join(lines.map(l => h `<p>${l}</p>`))}</div>`;
|
|
@@ -287,10 +296,6 @@ export function draftEditor(d, form, conflict) {
|
|
|
287
296
|
</div>
|
|
288
297
|
</form>`;
|
|
289
298
|
}
|
|
290
|
-
/** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
|
|
291
|
-
export function newReplyEditor(d) {
|
|
292
|
-
return h `<div data-reload-on-close hidden></div>${draftEditor(d, { to: d.to.join(", "), cc: d.cc.join(", "), subject: d.subject, text: d.text }, null)}`;
|
|
293
|
-
}
|
|
294
299
|
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
295
300
|
export function draftFiles(d, error) {
|
|
296
301
|
return h `<div class="draft-files" id="files-${d.id}">
|
|
@@ -388,7 +393,7 @@ export function threadView(thread, entries, ctx, opts) {
|
|
|
388
393
|
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
389
394
|
${when(opts.reply.allowed, () => h `<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
390
395
|
${when(opts.reply.replyAll, () => h `<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
391
|
-
<button type="button" class="icon-btn" aria-label="${S.
|
|
396
|
+
<button type="button" class="icon-btn" aria-label="${S.fullReply}" title="${S.fullReply}" hx-get="/threads/${thread.id}/reply/full?${query}" hx-include="closest form" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("plus")}</button>
|
|
392
397
|
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
393
398
|
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
394
399
|
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inboxer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "A self-hosted mail layer for agents: persists every inbound and outbound email, exposes an MCP server, and ships a minimal UI to review drafts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/core/mail.ts
CHANGED
|
@@ -409,6 +409,19 @@ export class Mail {
|
|
|
409
409
|
return this.store.serialize(() => this.createDraftUnlocked(input, actor));
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
/** Who a reply to `replyToId` goes to and its subject, without creating anything. */
|
|
413
|
+
async replyTo(replyToId: string, replyAll: boolean, scope: Scope): Promise<{ mailbox: string; to: string[]; cc: string[]; subject: string }> {
|
|
414
|
+
return this.replyDefaults(await this.requireMessage(replyToId, scope), {}, replyAll);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private replyDefaults(original: Message, given: { mailbox?: string; to?: string[] }, replyAll: boolean) {
|
|
418
|
+
const mailbox = given.mailbox ?? original.mailbox;
|
|
419
|
+
const to = given.to ?? (original.direction === "in" ? (original.reply_to.length ? original.reply_to : [original.from]) : original.to);
|
|
420
|
+
const already = new Set([bareAddress(this.sendingMailbox(mailbox).address), ...to.map(bareAddress)]);
|
|
421
|
+
const cc = replyAll ? [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a))) : [];
|
|
422
|
+
return { mailbox, to, cc, subject: replySubject(original.subject) };
|
|
423
|
+
}
|
|
424
|
+
|
|
412
425
|
private async createDraftUnlocked(input: CreateDraftInput, actor: Actor): Promise<Message> {
|
|
413
426
|
const now = new Date().toISOString();
|
|
414
427
|
let mailbox: string;
|
|
@@ -421,14 +434,11 @@ export class Mail {
|
|
|
421
434
|
|
|
422
435
|
if (input.replyToId) {
|
|
423
436
|
const original = await this.requireMessage(input.replyToId, actor.scope);
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
to =
|
|
427
|
-
if (input.
|
|
428
|
-
|
|
429
|
-
cc = [...original.to, ...original.cc].filter(a => !already.has(bareAddress(a)));
|
|
430
|
-
}
|
|
431
|
-
subject = input.subject ?? replySubject(original.subject);
|
|
437
|
+
const defaults = this.replyDefaults(original, input, !!input.replyAll && !input.cc);
|
|
438
|
+
mailbox = defaults.mailbox;
|
|
439
|
+
to = defaults.to;
|
|
440
|
+
if (!input.cc) cc = defaults.cc;
|
|
441
|
+
subject = input.subject ?? defaults.subject;
|
|
432
442
|
inReplyTo = original.message_id;
|
|
433
443
|
references = original.message_id ? [...original.references, original.message_id] : original.references;
|
|
434
444
|
threadId = original.thread_id;
|
package/src/ui/routes.ts
CHANGED
|
@@ -240,15 +240,38 @@ export function registerUi(app: Hono<UiEnv>, mail: Mail, access: Access, cfg: In
|
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
/** Replies to the latest message; a reply sent from here gets the same undo window as a draft. */
|
|
243
|
-
/**
|
|
244
|
-
app.
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
const { messages } = await mail.getThread(
|
|
243
|
+
/** The reply box's full form, for Cc, subject and files; nothing is created until it is posted. */
|
|
244
|
+
app.get("/threads/:id/reply/full", async c => {
|
|
245
|
+
const id = c.req.param("id");
|
|
246
|
+
const scope = c.get("session").scope;
|
|
247
|
+
const { messages } = await mail.getThread(id, scope);
|
|
248
248
|
const latest = messages.filter(m => m.status !== "draft").at(-1);
|
|
249
249
|
if (!latest) throw new InvalidRequestError("nothing to reply to");
|
|
250
|
-
const
|
|
251
|
-
|
|
250
|
+
const reply = await mail.replyTo(latest.id, c.req.query("reply_all") === "1", scope);
|
|
251
|
+
const fields = { to: reply.to.join(", "), cc: reply.cc.join(", "), subject: reply.subject, text: c.req.query("text") ?? "" };
|
|
252
|
+
return c.html(V.replyForm(id, V.inboxQuery(inboxFilter(c)), latest.id, fields));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
app.post("/threads/:id/reply/full", async c => {
|
|
256
|
+
const actor = uiActor(c.get("session"));
|
|
257
|
+
const body = await c.req.parseBody({ all: true });
|
|
258
|
+
const { files, error } = uploads(body);
|
|
259
|
+
if (error) return page(c, S.reply, V.message([error]), "inbox", 400);
|
|
260
|
+
try {
|
|
261
|
+
const draft = await mail.createDraft({
|
|
262
|
+
replyToId: String(body.reply_to_id ?? ""),
|
|
263
|
+
to: splitAddresses(String(body.to ?? "")),
|
|
264
|
+
cc: splitAddresses(String(body.cc ?? "")),
|
|
265
|
+
subject: String(body.subject ?? ""),
|
|
266
|
+
text: String(body.text ?? ""),
|
|
267
|
+
}, actor);
|
|
268
|
+
await attachAll(draft.id, files, actor);
|
|
269
|
+
if (body.action === "send") await mail.schedule(draft.id, "send", actor);
|
|
270
|
+
} catch (err) {
|
|
271
|
+
if (err instanceof InvalidRequestError) return page(c, S.reply, V.message([err.message]), "inbox", 400);
|
|
272
|
+
throw err;
|
|
273
|
+
}
|
|
274
|
+
return c.redirect(`/threads/${c.req.param("id")}?${V.inboxQuery(inboxFilter(c))}`, 303);
|
|
252
275
|
});
|
|
253
276
|
|
|
254
277
|
app.post("/threads/:id/reply", async c => {
|
package/src/ui/static/app.js
CHANGED
|
@@ -23,14 +23,9 @@ document.addEventListener("htmx:afterSwap", event => {
|
|
|
23
23
|
sheet.querySelector("textarea")?.focus();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
// Closing the sheet on a reply started from the reply box shows its new draft in the thread.
|
|
27
|
-
document.addEventListener("close", event => {
|
|
28
|
-
if (event.target.id === "edit-sheet" && event.target.querySelector("[data-reload-on-close]")) location.reload();
|
|
29
|
-
}, true);
|
|
30
|
-
|
|
31
26
|
document.addEventListener("change", event => {
|
|
32
|
-
if (event.target.
|
|
33
|
-
|
|
27
|
+
if (event.target.matches("[data-file-names]")) {
|
|
28
|
+
event.target.closest("form").querySelector(".sheet-files").textContent = [...event.target.files].map(f => f.name).join(", ");
|
|
34
29
|
}
|
|
35
30
|
});
|
|
36
31
|
|
package/src/ui/strings.ts
CHANGED
package/src/ui/views.ts
CHANGED
|
@@ -138,38 +138,49 @@ ${when(opts.signedIn, () => h`<dialog class="sheet" id="edit-sheet" aria-label="
|
|
|
138
138
|
|
|
139
139
|
/** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
|
|
140
140
|
function composeDialog(senders: Mailbox[]): View {
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
const from = senders.length > 1
|
|
142
|
+
? h`<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h`<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
143
|
+
: h`<input type="hidden" name="mailbox" value="${senders[0]!.id}"><output id="compose-from">${senders[0]!.address}</output>`;
|
|
144
|
+
return h`<dialog class="sheet" id="compose" aria-label="${S.newMail}">${mailForm("compose", "/compose", {
|
|
145
|
+
head: h`<div class="field compact"><label for="compose-from">${S.from}</label>${from}</div>`, to: "", cc: "", subject: "", text: "",
|
|
146
|
+
})}</dialog>`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** A reply opened from the reply box, shown in the edit sheet; nothing is saved until Save or Send. */
|
|
150
|
+
export function replyForm(threadId: string, query: string, replyToId: string, fields: { to: string; cc: string; subject: string; text: string }): View {
|
|
151
|
+
return mailForm("reply", `/threads/${threadId}/reply/full?${query}`, {
|
|
152
|
+
...fields,
|
|
153
|
+
head: h`<input type="hidden" name="reply_to_id" value="${replyToId}"><div class="sheet-head"></div>`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** New mail and the full reply: recipients, subject, body and files, saved or sent in one post. */
|
|
158
|
+
function mailForm(id: string, action: string, f: { head: View; to: string; cc: string; subject: string; text: string }): View {
|
|
159
|
+
return h`<form method="post" action="${action}" enctype="multipart/form-data" data-drop>
|
|
143
160
|
<div class="grabber" aria-hidden="true"></div>
|
|
144
161
|
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
145
|
-
|
|
146
|
-
<label for="compose-from">${S.from}</label>
|
|
147
|
-
${senders.length > 1
|
|
148
|
-
? h`<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h`<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
149
|
-
: h`<input type="hidden" name="mailbox" value="${senders[0]!.id}"><output id="compose-from">${senders[0]!.address}</output>`}
|
|
150
|
-
</div>
|
|
162
|
+
${f.head}
|
|
151
163
|
<div class="field">
|
|
152
|
-
<label for="
|
|
153
|
-
<input id="
|
|
154
|
-
|
|
164
|
+
<label for="${id}-to">${S.to}</label>
|
|
165
|
+
<input id="${id}-to" name="to" value="${f.to}" autocomplete="off" required>
|
|
166
|
+
${when(!f.cc, () => h`<button type="button" class="link" onclick="this.remove();var r=document.getElementById('${id}-cc-row');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
155
167
|
</div>
|
|
156
|
-
<div class="field" id="
|
|
157
|
-
<label for="
|
|
158
|
-
<input id="
|
|
168
|
+
<div class="field" id="${id}-cc-row" ${raw(f.cc ? "" : "hidden")}>
|
|
169
|
+
<label for="${id}-cc">${S.cc}</label>
|
|
170
|
+
<input id="${id}-cc" name="cc" value="${f.cc}" autocomplete="off">
|
|
159
171
|
</div>
|
|
160
172
|
<div class="field">
|
|
161
|
-
<label for="
|
|
162
|
-
<input id="
|
|
173
|
+
<label for="${id}-subject">${S.subject}</label>
|
|
174
|
+
<input id="${id}-subject" name="subject" value="${f.subject}" required>
|
|
163
175
|
</div>
|
|
164
|
-
<textarea name="text" aria-label="${S.body}" required
|
|
176
|
+
<textarea name="text" aria-label="${S.body}" required>${f.text}</textarea>
|
|
165
177
|
<div class="sheet-actions">
|
|
166
|
-
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files"
|
|
167
|
-
<output class="sheet-files"
|
|
178
|
+
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden data-file-names></label>
|
|
179
|
+
<output class="sheet-files"></output>
|
|
168
180
|
<button type="submit" name="action" value="save">${S.saveDraft}</button>
|
|
169
181
|
<button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
|
|
170
182
|
</div>
|
|
171
|
-
</form
|
|
172
|
-
</dialog>`;
|
|
183
|
+
</form>`;
|
|
173
184
|
}
|
|
174
185
|
|
|
175
186
|
export function message(lines: string[]): View {
|
|
@@ -345,11 +356,6 @@ export function draftEditor(d: Message, form: DraftForm, conflict: Message | nul
|
|
|
345
356
|
</form>`;
|
|
346
357
|
}
|
|
347
358
|
|
|
348
|
-
/** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
|
|
349
|
-
export function newReplyEditor(d: Message): View {
|
|
350
|
-
return h`<div data-reload-on-close hidden></div>${draftEditor(d, { to: d.to.join(", "), cc: d.cc.join(", "), subject: d.subject, text: d.text }, null)}`;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
359
|
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
354
360
|
export function draftFiles(d: Message, error: string | null): View {
|
|
355
361
|
return h`<div class="draft-files" id="files-${d.id}">
|
|
@@ -464,7 +470,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
|
|
|
464
470
|
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
465
471
|
${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
466
472
|
${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
467
|
-
<button type="button" class="icon-btn" aria-label="${S.
|
|
473
|
+
<button type="button" class="icon-btn" aria-label="${S.fullReply}" title="${S.fullReply}" hx-get="/threads/${thread.id}/reply/full?${query}" hx-include="closest form" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("plus")}</button>
|
|
468
474
|
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
469
475
|
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
470
476
|
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|