feat: decouple manual image sharing from automation gating
The "Share a saved image" panel was wired to the automated exchange engine, so an operator could only share an image right after an inbound image request, limited to assets the auto-exchanger would itself pick. Add a manual path that offers any enabled, unused library image at any point (no request detection, tier, seller, or boundary gating) and sends it with no reciprocal "your turn" text. Safety flags now surface as a non-blocking warning instead of disabling the panel. The automated auto-send path keeps all its guardrails; the shared image-delivery step is extracted into a helper used by both paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e984bf20ac
commit
c8689af04d
9 files changed
+192
-67
No files matched your search
@@ -129,6 +129,49 @@ describe('MediaLibraryExchangeService', () => {
|
||||
expect(chat.sendChatMessage).toHaveBeenCalledOnce();
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('manually shares any enabled image with no request gating and no reciprocal text', async () => {
|
||||
const db = createTestDb();
|
||||
const repository = new MediaLibraryRepository(db);
|
||||
await addAsset(repository, directory, 'selfie', ['selfie'], 'sfw', 1);
|
||||
await addAsset(repository, directory, 'topless', ['topless'], 'nsfw', 2);
|
||||
const chat = {
|
||||
sendChatImage: vi.fn().mockResolvedValue({ eventId: '$img', mxcUri: 'mxc://img' }),
|
||||
sendChatMessage: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
const service = new MediaLibraryExchangeService(repository, chat, logger(), 'account', directory);
|
||||
|
||||
// No image request in the conversation, yet every enabled image is offered.
|
||||
expect(service.listShareableManual('room').map((asset) => asset.id).sort()).toEqual(['selfie', 'topless']);
|
||||
|
||||
const result = await service.shareManual('room', 'topless');
|
||||
expect(result).toMatchObject({ kind: 'sent', assetId: 'topless' });
|
||||
expect(chat.sendChatImage).toHaveBeenCalledOnce();
|
||||
expect(chat.sendChatMessage).not.toHaveBeenCalled();
|
||||
|
||||
// The shared image leaves the manual list; re-sharing it is idempotent and re-sends nothing.
|
||||
expect(service.listShareableManual('room').map((asset) => asset.id)).toEqual(['selfie']);
|
||||
expect(await service.shareManual('room', 'topless')).toMatchObject({ kind: 'sent', assetId: 'topless' });
|
||||
expect(chat.sendChatImage).toHaveBeenCalledOnce();
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('refuses a manual share of an unknown or disabled image', async () => {
|
||||
const db = createTestDb();
|
||||
const repository = new MediaLibraryRepository(db);
|
||||
await addAsset(repository, directory, 'selfie', ['selfie'], 'sfw', 1);
|
||||
repository.update('selfie', ['selfie'], 'sfw', false);
|
||||
const chat = {
|
||||
sendChatImage: vi.fn().mockResolvedValue({ eventId: '$img', mxcUri: 'mxc://img' }),
|
||||
sendChatMessage: vi.fn().mockResolvedValue(true),
|
||||
};
|
||||
const service = new MediaLibraryExchangeService(repository, chat, logger(), 'account', directory);
|
||||
|
||||
expect(await service.shareManual('room', 'does-not-exist')).toMatchObject({ kind: 'human-required' });
|
||||
expect(await service.shareManual('room', 'selfie')).toMatchObject({ kind: 'human-required' });
|
||||
expect(chat.sendChatImage).not.toHaveBeenCalled();
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
|
||||
async function addAsset(
|
||||
|
||||
Reference in new issue
Block a user