mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
fix(mail-ingest): send mailInbox:settings, and give both events their client place
The settings event was registered with no sender; renewing or revoking an address and changing the switches now send it. The client lists both events as not yet shown, which keeps the registry-parity test green until the mail screens move them to their listener.
This commit is contained in:
@@ -161,6 +161,9 @@ export const HANDLED_OUTSIDE_TRIP_STORE = [
|
||||
export const IGNORED_WS_EVENTS: Partial<Record<TrekWsEventName, string>> = {
|
||||
'todo:assignees':
|
||||
'No screen shows who looks after a todo category (todoApi.getCategoryAssignees has no caller), so there is nothing to refresh.',
|
||||
// The mail import's inbox and settings card come with its client screens, which move these to their listener.
|
||||
'mailInbox:changed': 'No screen shows the mail inbox or its open count yet, so there is nothing to refresh.',
|
||||
'mailInbox:settings': 'No screen shows the mail import settings card yet, so there is nothing to read again.',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,7 @@ import { DomainError } from '../common/domain-error';
|
||||
import { MailReadService } from '../llm-parse/mail-read.service';
|
||||
import { MailIngestAddressService } from './mail-ingest-address.service';
|
||||
import { MailIngestIntakeService, type MailIntakeRefusal } from './mail-ingest-intake.service';
|
||||
import { MailIngestNotifyService } from './mail-ingest-notify.service';
|
||||
import { MailIngestProcessJob } from './mail-ingest-process.job';
|
||||
import { MailIngestSettingsService } from './mail-ingest-settings.service';
|
||||
import { candidateView, messageView } from './mail-ingest-views';
|
||||
@@ -57,6 +58,7 @@ export class MailIngestInboxService {
|
||||
private readonly intake: MailIngestIntakeService,
|
||||
private readonly reader: MailReadService,
|
||||
private readonly job: MailIngestProcessJob,
|
||||
private readonly notify: MailIngestNotifyService,
|
||||
) {}
|
||||
|
||||
/** The settings card. Where the import is off or not part of the plan it says so, and nothing else. */
|
||||
@@ -77,13 +79,16 @@ export class MailIngestInboxService {
|
||||
async updatePrefs(userId: number, update: MailIngestPrefsUpdateRequest): Promise<MailIngestSettingsResponse> {
|
||||
await this.requireAvailable();
|
||||
await this.settings.updatePrefs(userId, update);
|
||||
this.notify.settingsChanged(userId);
|
||||
return this.settingsOf(userId);
|
||||
}
|
||||
|
||||
/** A new own address; the old one stops taking mail at once. */
|
||||
async renewOwnAddress(userId: number): Promise<MailIngestAddressResponse> {
|
||||
await this.requireAvailable();
|
||||
return { address: await this.addresses.renewOwn(userId) };
|
||||
const address = await this.addresses.renewOwn(userId);
|
||||
this.notify.settingsChanged(userId);
|
||||
return { address };
|
||||
}
|
||||
|
||||
async tripAddress(userId: number, tripId: number): Promise<MailIngestAddressResponse> {
|
||||
@@ -94,12 +99,15 @@ export class MailIngestInboxService {
|
||||
/** The person's address for the trip, made now or renewed. */
|
||||
async renewTripAddress(userId: number, tripId: number): Promise<MailIngestAddressResponse> {
|
||||
await this.requireAvailable();
|
||||
return { address: await this.addresses.renewTripAddress(userId, tripId) };
|
||||
const address = await this.addresses.renewTripAddress(userId, tripId);
|
||||
this.notify.settingsChanged(userId);
|
||||
return { address };
|
||||
}
|
||||
|
||||
async revokeTripAddress(userId: number, tripId: number): Promise<void> {
|
||||
await this.requireAvailable();
|
||||
await this.addresses.revokeTripAddress(userId, tripId);
|
||||
this.notify.settingsChanged(userId);
|
||||
}
|
||||
|
||||
/** One page of the inbox, newest first, each entry with the mail it came from. */
|
||||
|
||||
@@ -33,6 +33,11 @@ export class MailIngestNotifyService {
|
||||
this.realtime.broadcastToUser(userId, { type: 'mailInbox:changed', pending });
|
||||
}
|
||||
|
||||
/** Tells the person's open clients that their address or switches changed, so the settings card reads them again. */
|
||||
settingsChanged(userId: number): void {
|
||||
this.realtime.broadcastToUser(userId, { type: 'mailInbox:settings' });
|
||||
}
|
||||
|
||||
/** @txStandalone a notice reports a write that committed; a failed one undoes nothing. */
|
||||
async bookingAdded(forwarder: MailIngestPersonRow, booking: AddedBooking): Promise<void> {
|
||||
const params = {
|
||||
|
||||
@@ -64,13 +64,15 @@ describe('MailIngestNotifyService', () => {
|
||||
expect(trip).toMatchObject({ scope: 'trip', targetId: 7, actorId: 3, params: { role: 'traveller', actor: 'mia' } });
|
||||
});
|
||||
|
||||
it('sends one note for waiting bookings, and survives a failed send', async () => {
|
||||
it('sends one note for waiting bookings, survives a failed send, and tells clients of new settings', async () => {
|
||||
notifications.send.mockRejectedValue(new Error('smtp down'));
|
||||
await expect(notify.bookingsPending(3, 2)).resolves.toBeUndefined();
|
||||
expect(notifications.send).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ event: 'mail_booking_pending', params: { count: '2' } }),
|
||||
);
|
||||
expect(realtime.broadcastToUser).toHaveBeenCalledWith(3, { type: 'mailInbox:changed', pending: 2 });
|
||||
notify.settingsChanged(3);
|
||||
expect(realtime.broadcastToUser).toHaveBeenCalledWith(3, { type: 'mailInbox:settings' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user