feat(notifications): tell a new journey contributor they were added

Adding somebody to a journey was silent (#1669). The new journey_invite
event goes to the person added, in-app with a button to the journey and on
every channel they use, once: posting the same person again only changes
their role. The REST route and the MCP tool both go through
JourneyService.addContributor, so both send it; the send is fire and forget
like the trip and collection invites.

The event is listed while the Journey addon is on, with its label in the
notification settings, and its texts are translated in every locale.
This commit is contained in:
Maurice
2026-11-30 14:36:52 +01:00
parent 55fc5f6679
commit ea9d66868a
95 changed files with 326 additions and 5 deletions
@@ -1,11 +1,13 @@
import { Users } from '../../db/entities/Users.entity';
import { AddonsModule } from '../addons/addons.module';
import { AppConfigModule } from '../app-config/app-config.module';
import { UserLookupModule } from '../auth-core/user-lookup.module';
import { RateLimitModule } from '../common/rate-limit.module';
import { UserConnectionRepositoriesModule } from '../database/user-connection-repositories.module';
import { AllowedFileTypesModule } from '../files/allowed-file-types.module';
import { AllowedFileTypesService } from '../files/allowed-file-types.service';
import { MemoriesModule } from '../memories/memories.module';
import { NotificationsModule } from '../notifications/notifications.module';
import { buildStorageUploadOptions } from '../storage/storage-upload.factory';
import { StorageModule } from '../storage/storage.module';
import { StorageService } from '../storage/storage.service';
@@ -47,6 +49,10 @@ import { MulterModule } from '@nestjs/platform-express';
AddonsModule,
// The public unlock route counts wrong passwords per address and link (#2553).
RateLimitModule,
// journey_invite: the new contributor hears who added them (UserLookupService)
// through the notification service.
UserLookupModule,
NotificationsModule,
// RuntimeEnvService: the controller refuses the demo account's uploads in demo mode.
AppConfigModule,
MemoriesModule,
+40 -2
View File
@@ -1,9 +1,11 @@
import { ADDON_IDS } from '../../addons';
import { UserImmichRepository } from '../../db/repositories/UserImmich.repository';
import { AddonsService } from '../addons/addons.service';
import { UserLookupService } from '../auth-core/user-lookup.service';
import { ImmichService } from '../memories/immich.service';
import { PhotoProviderRegistry } from '../memories/photo-provider.registry';
import { PhotoResolverService } from '../memories/photo-resolver.service';
import { NotificationsService } from '../notifications/notifications.service';
import { JourneyDomainService } from './journey-domain.service';
import { JourneyMapService } from './journey-map.service';
import { JourneySettingsService } from './journey-settings.service';
@@ -30,6 +32,8 @@ export class JourneyService {
private readonly immichRepo: UserImmichRepository,
private readonly map: JourneyMapService,
private readonly settings: JourneySettingsService,
private readonly notifications: NotificationsService,
private readonly users: UserLookupService,
) {}
async journeyAddonEnabled(): Promise<boolean> {
@@ -133,8 +137,42 @@ export class JourneyService {
}
// Contributors
addContributor(id: number, userId: number, targetUserId: number, role: 'editor' | 'viewer') {
return this.journey.addContributor(id, userId, targetUserId, role);
/**
* Add a contributor, and tell them (journey_invite, #1669) when they are new
* to the journey. Both the REST route and the MCP tool come through here.
* Re-adding somebody who is already on it only changes their role, which is
* not news worth a notification.
*/
async addContributor(id: number, userId: number, targetUserId: number, role: 'editor' | 'viewer') {
const alreadyIn = (await this.journey.canAccessJourney(id, targetUserId)) !== null;
const added = await this.journey.addContributor(id, userId, targetUserId, role);
if (added && !alreadyIn) await this.notifyInvite(id, userId, targetUserId, role);
return added;
}
/**
* Fire-and-forget, like the trip and collection invites: a notification that
* fails never undoes the contributor who was just added.
*
* @txStandalone a notification, independent of the write it reports.
*/
private async notifyInvite(journeyId: number, actorId: number, targetUserId: number, role: 'editor' | 'viewer') {
const journey = await this.journey.canAccessJourney(journeyId, actorId);
const actor = await this.users.usernameAndEmail(actorId);
this.notifications
.send({
event: 'journey_invite',
actorId,
scope: 'user',
targetId: targetUserId,
params: {
actor: actor?.username ?? '',
journey: journey?.title ?? '',
journeyId: String(journeyId),
role,
},
})
.catch(() => {});
}
updateContributorRole(id: number, userId: number, targetUserId: number, role: 'editor' | 'viewer') {
return this.journey.updateContributorRole(id, userId, targetUserId, role);
@@ -38,6 +38,7 @@ export type NotifEventType =
| 'vacay_invite'
| 'vacay_share'
| 'collection_invite'
| 'journey_invite'
| 'photos_shared'
| 'collab_message'
| 'packing_tagged'
@@ -63,6 +64,7 @@ export const ALL_EVENT_TYPES: NotifEventType[] = [
'vacay_invite',
'vacay_share',
'collection_invite',
'journey_invite',
'photos_shared',
'collab_message',
'packing_tagged',
@@ -128,6 +128,8 @@ export class NotificationPreferencesService {
return on(ADDON_IDS.VACAY);
case 'collection_invite':
return on(ADDON_IDS.COLLECTIONS);
case 'journey_invite':
return on(ADDON_IDS.JOURNEY);
case 'collab_message':
return on(ADDON_IDS.COLLAB);
case 'packing_tagged':
@@ -238,6 +238,14 @@ const EVENT_NOTIFICATION_CONFIG: Record<string, EventNotifConfig> = {
navigateTextKey: 'notif.action.view_collection',
navigateTarget: (p) => (p.collectionId ? `/collections/${p.collectionId}` : '/collections'),
},
// Somebody added you to their journey (#1669): the button opens it.
journey_invite: {
inAppType: 'navigate',
titleKey: 'notif.journey_invite.title',
textKey: 'notif.journey_invite.text',
navigateTextKey: 'notif.action.view_journey',
navigateTarget: (p) => (p.journeyId ? `/journey/${p.journeyId}` : '/journey'),
},
photos_shared: {
inAppType: 'navigate',
titleKey: 'notif.photos_shared.title',
@@ -31,6 +31,7 @@ const NTFY_EVENT_META: Partial<Record<NotifEventType, { priority: 1 | 2 | 3 | 4
todo_due: { priority: 4, tags: ['ballot_box_with_check'] },
vacay_share: { priority: 3, tags: ['palm_tree'] },
collection_invite: { priority: 3, tags: ['bookmark'] },
journey_invite: { priority: 3, tags: ['notebook'] },
photos_shared: { priority: 3, tags: ['camera'] },
collab_message: { priority: 3, tags: ['speech_balloon'] },
packing_tagged: { priority: 3, tags: ['luggage'] },