mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-07 06:23:05 +00:00
fix(push): stop after shutdown starts and keep eight title characters
This commit is contained in:
1 parent
79faf2933a
commit
2b150a7994
4 files changed
+47
-2
No files matched your search
@@ -560,6 +560,30 @@ describe('PushService while shutting down', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('PushService when shutdown starts mid-delivery', () => {
|
||||
const provider = new FakeProvider();
|
||||
const state = bootWith({ push: { enabled: true } }, provider);
|
||||
|
||||
it('sends nothing once its devices are read', async () => {
|
||||
const user = await makeUser(state.server);
|
||||
await registerDevice(state.server, user.id, `tok-${uuidv4()}`);
|
||||
const store = state.server.stores.pushDevice;
|
||||
const original = store.listForDelivery.bind(store);
|
||||
const listed = vi
|
||||
.spyOn(store, 'listForDelivery')
|
||||
.mockImplementation(async (...args) => {
|
||||
const devices = await original(...args);
|
||||
state.server.services.push.onServerPrepareShutdown();
|
||||
return devices;
|
||||
});
|
||||
await shareReceived(state.server, user.id);
|
||||
await vi.waitFor(() => expect(listed).toHaveBeenCalled());
|
||||
await settle();
|
||||
listed.mockRestore();
|
||||
expect(provider.calls).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PushService with push off', () => {
|
||||
const provider = new FakeProvider();
|
||||
const state = bootWith({}, provider);
|
||||
|
||||
@@ -156,7 +156,7 @@ export class PushService extends PuterService {
|
||||
limit: MAX_DEVICES_PER_PUSH,
|
||||
})
|
||||
).filter((device) => this.#providers.has(device.platform));
|
||||
if (devices.length === 0) return;
|
||||
if (devices.length === 0 || this.#stopping) return;
|
||||
|
||||
if (this.#inFlight >= MAX_IN_FLIGHT) {
|
||||
this.#noteSkipped();
|
||||
|
||||
@@ -272,6 +272,23 @@ describe('fitPushMessage', () => {
|
||||
expect(kept.split(family).every((part) => part === '')).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps at least eight title characters before the ellipsis', () => {
|
||||
const title = 'a long title that has to be cut';
|
||||
const kept = fitPushMessage({
|
||||
...base,
|
||||
title,
|
||||
data: { blob: 'd'.repeat(3707) },
|
||||
});
|
||||
expect(kept!.title).toBe(`${title.slice(0, 8)}…`);
|
||||
expect(
|
||||
fitPushMessage({
|
||||
...base,
|
||||
title,
|
||||
data: { blob: 'd'.repeat(3708) },
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('sends no push when the title would keep only a few characters', () => {
|
||||
expect(
|
||||
fitPushMessage({
|
||||
|
||||
@@ -216,6 +216,10 @@ export const fitPushMessage = (message: PushMessage): PushMessage | null => {
|
||||
const titleLen = longestFitting(titleChars.length, (n) =>
|
||||
build(n, 0, false),
|
||||
);
|
||||
if (titleLen < Math.min(MIN_TITLE_CHARS, titleChars.length)) return null;
|
||||
if (titleLen < 0) return null;
|
||||
// A cut title is `titleLen - 1` characters and the ellipsis.
|
||||
if (titleLen < titleChars.length && titleLen - 1 < MIN_TITLE_CHARS) {
|
||||
return null;
|
||||
}
|
||||
return build(titleLen, 0, false);
|
||||
};
|
||||
Reference in new issue
Block a user