From 3d9fc7720180e35df16bde22b29cfd0343f3ce8d Mon Sep 17 00:00:00 2001 From: Liosha84 Date: Sat, 7 Nov 2026 20:10:54 +0100 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B5=D0=B2=D0=B0=D1=8F=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BB=D1=8C:=20=D0=BA=D0=BE=D0=BC=D0=B1=D0=BE?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA=D1=81=20=D1=8F=D1=89=D0=B8=D0=BA=D0=BE=D0=B2?= =?UTF-8?q?;=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=8F=D1=89=D0=B8=D0=BA=D0=BE=D0=B2=20=E2=80=94=20?= =?UTF-8?q?=D0=B2=20=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8?= =?UTF-8?q?;=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=20=D1=86=D0=B2=D0=B5=D1=82=D0=B5=20=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MAILBOX: +
+
+ + + + ` +}) +export class MyMailboxesSection { + readonly state = inject(MailStateService); + private api = inject(ApiService); + private auth = inject(AuthService); + private dialogs = inject(DialogService); + private toasts = inject(ToastService); + + email = ''; + password = ''; + + constructor() { + this.state.refreshBoxes(); + } + + attach(): void { + const email = this.email.trim().toLowerCase(); + if (!email || !this.password) { this.toasts.error('Mailbox and its password'); return; } + this.api.attachMailbox(email, this.password).subscribe({ + next: b => { + this.email = this.password = ''; + this.toasts.ok(b.email + ' added — pick it in the MAILBOX list on the left'); + this.state.refreshBoxes(); + }, + error: e => this.toasts.error(errorText(e)) + }); + } + + leave(b: MailboxEntry): void { + this.dialogs.confirm(`Remove ${b.email}?`, b.shared + ? 'It disappears from your list. An administrator can give it back.' + : 'It disappears from your list. Add it again with its password.', 'Remove', true).subscribe(ok => { + if (ok === null) return; + this.api.leaveMailbox(b.email).subscribe({ + next: () => { + this.toasts.ok(b.email + ' removed'); + if (b.email === this.auth.email()) { + // removed the one we are in — back to the own mailbox + this.api.mailboxSession(this.state.boxes().find(x => x.kind === 'OWN')?.email ?? '').subscribe({ + next: session => { this.state.reset(); this.auth.switchTo(session); location.assign('/'); }, + error: () => location.assign('/') + }); + return; + } + this.state.refreshBoxes(); + }, + error: e => this.toasts.error(errorText(e)) + }); + }); + } +} diff --git a/frontend/src/app/pages/settings/settings.page.ts b/frontend/src/app/pages/settings/settings.page.ts index 4a73675..2c999da 100644 --- a/frontend/src/app/pages/settings/settings.page.ts +++ b/frontend/src/app/pages/settings/settings.page.ts @@ -9,11 +9,12 @@ import { THEMES, ThemeService } from '../../ui/theme.service'; import { ToastService } from '../../ui/toast.service'; import { MailboxesSection } from './mailboxes.section'; import { ListsSection } from './lists.section'; +import { MyMailboxesSection } from './my-mailboxes.section'; /** Profile name, password, storage, look. */ @Component({ selector: 'app-settings', - imports: [DatePipe, FormsModule, MatIconModule, MailboxesSection, ListsSection], + imports: [DatePipe, FormsModule, MatIconModule, MailboxesSection, ListsSection, MyMailboxesSection], changeDetection: ChangeDetectionStrategy.OnPush, template: `
@@ -93,7 +94,7 @@ import { ListsSection } from './lists.section';
@for (t of themes; track t.value) { }
@@ -112,6 +113,8 @@ import { ListsSection } from './lists.section';
+ + @if (state.profile()?.admin) { diff --git a/frontend/src/app/pages/shell/shell.component.ts b/frontend/src/app/pages/shell/shell.component.ts index 858e944..e46d81c 100644 --- a/frontend/src/app/pages/shell/shell.component.ts +++ b/frontend/src/app/pages/shell/shell.component.ts @@ -81,43 +81,15 @@ import { ToastService } from '../../ui/toast.service';