refactor: stricer domain: notifications

This commit is contained in:
2026-04-11 14:23:50 +02:00
parent 98ed8eeb68
commit db7e683504
30 changed files with 953 additions and 71 deletions

View File

@@ -7,7 +7,8 @@ Handles file sharing between peers over WebRTC data channels. Files are announce
```
attachment/
├── application/
│ ├── attachment.facade.ts Thin entry point, delegates to manager
│ ├── facades/
│ │ └── attachment.facade.ts Thin entry point, delegates to manager
│ └── services/
│ ├── attachment-manager.service.ts Orchestrates lifecycle, auto-download, peer listeners
│ ├── attachment-transfer.service.ts P2P file transfer protocol (announce/request/chunk/cancel)
@@ -16,17 +17,20 @@ attachment/
│ └── attachment-runtime.store.ts In-memory signal-based state (Maps for attachments, chunks, pending)
├── domain/
│ ├── attachment.logic.ts isAttachmentMedia, shouldAutoRequestWhenWatched, shouldPersistDownloadedAttachment
│ ├── logic/
│ │ └── attachment.logic.ts isAttachmentMedia, shouldAutoRequestWhenWatched, shouldPersistDownloadedAttachment
│ ├── models/
│ │ ├── attachment.models.ts Attachment type extending AttachmentMeta with runtime state
│ │ └── attachment-transfer.models.ts Protocol event types (file-announce, file-chunk, file-request, ...)
│ │ ├── attachment.model.ts Attachment type extending AttachmentMeta with runtime state
│ │ └── attachment-transfer.model.ts Protocol event types (file-announce, file-chunk, file-request, ...)
│ └── constants/
│ ├── attachment.constants.ts MAX_AUTO_SAVE_SIZE_BYTES = 10 MB
│ └── attachment-transfer.constants.ts FILE_CHUNK_SIZE_BYTES = 64 KB, EWMA weights, error messages
├── infrastructure/
│ ├── attachment-storage.service.ts Electron filesystem access (save / read / delete)
│ └── attachment-storage.util.ts sanitizeAttachmentRoomName, resolveAttachmentStorageBucket
│ ├── services/
│ └── attachment-storage.service.ts Electron filesystem access (save / read / delete)
│ └── util/
│ └── attachment-storage.util.ts sanitizeAttachmentRoomName, resolveAttachmentStorageBucket
└── index.ts Barrel exports
```
@@ -57,15 +61,15 @@ graph TD
Persistence --> Store
Storage --> Helpers[attachment-storage.util]
click Facade "application/attachment.facade.ts" "Thin entry point" _blank
click Facade "application/facades/attachment.facade.ts" "Thin entry point" _blank
click Manager "application/services/attachment-manager.service.ts" "Orchestrates lifecycle" _blank
click Transfer "application/services/attachment-transfer.service.ts" "P2P file transfer protocol" _blank
click Transport "application/services/attachment-transfer-transport.service.ts" "Base64 encode/decode, chunked streaming" _blank
click Persistence "application/services/attachment-persistence.service.ts" "DB + filesystem persistence" _blank
click Store "application/services/attachment-runtime.store.ts" "In-memory signal-based state" _blank
click Storage "infrastructure/attachment-storage.service.ts" "Electron filesystem access" _blank
click Helpers "infrastructure/attachment-storage.util.ts" "Path helpers" _blank
click Logic "domain/attachment.logic.ts" "Pure decision functions" _blank
click Storage "infrastructure/services/attachment-storage.service.ts" "Electron filesystem access" _blank
click Helpers "infrastructure/util/attachment-storage.util.ts" "Path helpers" _blank
click Logic "domain/logic/attachment.logic.ts" "Pure decision functions" _blank
```
## File transfer protocol

View File

@@ -1,5 +1,5 @@
import { Injectable, inject } from '@angular/core';
import { AttachmentManagerService } from './services/attachment-manager.service';
import { AttachmentManagerService } from '../services/attachment-manager.service';
@Injectable({ providedIn: 'root' })
export class AttachmentFacade {

View File

@@ -7,15 +7,15 @@ import { NavigationEnd, Router } from '@angular/router';
import { RealtimeSessionFacade } from '../../../../core/realtime';
import { DatabaseService } from '../../../../infrastructure/persistence';
import { ROOM_URL_PATTERN } from '../../../../core/constants';
import { shouldAutoRequestWhenWatched } from '../../domain/attachment.logic';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.models';
import { shouldAutoRequestWhenWatched } from '../../domain/logic/attachment.logic';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
import type {
FileAnnouncePayload,
FileCancelPayload,
FileChunkPayload,
FileNotFoundPayload,
FileRequestPayload
} from '../../domain/models/attachment-transfer.models';
} from '../../domain/models/attachment-transfer.model';
import { AttachmentPersistenceService } from './attachment-persistence.service';
import { AttachmentRuntimeStore } from './attachment-runtime.store';
import { AttachmentTransferService } from './attachment-transfer.service';

View File

@@ -4,7 +4,7 @@ import { Store } from '@ngrx/store';
import { selectCurrentRoomName } from '../../../../store/rooms/rooms.selectors';
import { DatabaseService } from '../../../../infrastructure/persistence';
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.models';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../../domain/constants/attachment.constants';
import { LEGACY_ATTACHMENTS_STORAGE_KEY } from '../../domain/constants/attachment-transfer.constants';
import { AttachmentRuntimeStore } from './attachment-runtime.store';

View File

@@ -1,5 +1,5 @@
import { Injectable, signal } from '@angular/core';
import type { Attachment } from '../../domain/models/attachment.models';
import type { Attachment } from '../../domain/models/attachment.model';
@Injectable({ providedIn: 'root' })
export class AttachmentRuntimeStore {

View File

@@ -2,7 +2,7 @@ import { Injectable, inject } from '@angular/core';
import { RealtimeSessionFacade } from '../../../../core/realtime';
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
import { FILE_CHUNK_SIZE_BYTES } from '../../domain/constants/attachment-transfer.constants';
import { FileChunkEvent } from '../../domain/models/attachment-transfer.models';
import { FileChunkEvent } from '../../domain/models/attachment-transfer.model';
@Injectable({ providedIn: 'root' })
export class AttachmentTransferTransportService {

View File

@@ -3,8 +3,8 @@ import { recordDebugNetworkFileChunk } from '../../../../infrastructure/realtime
import { RealtimeSessionFacade } from '../../../../core/realtime';
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../../domain/constants/attachment.constants';
import { shouldPersistDownloadedAttachment } from '../../domain/attachment.logic';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.models';
import { shouldPersistDownloadedAttachment } from '../../domain/logic/attachment.logic';
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
import {
ATTACHMENT_TRANSFER_EWMA_CURRENT_WEIGHT,
ATTACHMENT_TRANSFER_EWMA_PREVIOUS_WEIGHT,
@@ -23,7 +23,7 @@ import {
type FileRequestEvent,
type FileRequestPayload,
type LocalFileWithPath
} from '../../domain/models/attachment-transfer.models';
} from '../../domain/models/attachment-transfer.model';
import { AttachmentPersistenceService } from './attachment-persistence.service';
import { AttachmentRuntimeStore } from './attachment-runtime.store';
import { AttachmentTransferTransportService } from './attachment-transfer-transport.service';

View File

@@ -1,5 +1,5 @@
import { MAX_AUTO_SAVE_SIZE_BYTES } from './constants/attachment.constants';
import type { Attachment } from './models/attachment.models';
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../constants/attachment.constants';
import type { Attachment } from '../models/attachment.model';
export function isAttachmentMedia(attachment: Pick<Attachment, 'mime'>): boolean {
return attachment.mime.startsWith('image/') ||

View File

@@ -1,3 +1,3 @@
export * from './application/attachment.facade';
export * from './application/facades/attachment.facade';
export * from './domain/constants/attachment.constants';
export * from './domain/models/attachment.models';
export * from './domain/models/attachment.model';

View File

@@ -1,6 +1,6 @@
import { Injectable, inject } from '@angular/core';
import { ElectronBridgeService } from '../../../../core/platform/electron/electron-bridge.service';
import type { Attachment } from '../../domain/models/attachment.models';
import type { Attachment } from '../../domain/models/attachment.model';
import {
resolveAttachmentStorageBucket,
resolveAttachmentStoredFilename,