@marcoappio/marco-config 2.0.460 → 2.0.461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAEhE,MAAM,MAAM,sBAAsB,GAAG;KAClC,CAAC,IAAI,MAAM,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAC1C,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAC1D,OAAO,CAAC,IAAI,CAAC;CACnB,CAAA;AAED,eAAO,MAAM,cAAc,OACrB,WAAW,CAAC,eAAe,CAAC,YACtB,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,kBAAkB,EAAE,CAoE9B,CAAA;AAED,eAAO,MAAM,oBAAoB,cACpB,QAAQ,GAAG,SAAS,cACnB,sBAAsB,KACjC,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAEhE,MAAM,MAAM,sBAAsB,GAAG;KAClC,CAAC,IAAI,MAAM,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAC1C,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAC1D,OAAO,CAAC,IAAI,CAAC;CACnB,CAAA;AAED,eAAO,MAAM,cAAc,OACrB,WAAW,CAAC,eAAe,CAAC,YACtB,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,kBAAkB,EAAE,CAoE9B,CAAA;AAED,eAAO,MAAM,oBAAoB,cACpB,QAAQ,GAAG,SAAS,cACnB,sBAAsB,KACjC,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAqLxC,CAAA"}
|
|
@@ -167,6 +167,19 @@ export const createThreadMutators = (_authData, callbacks) => ({
|
|
|
167
167
|
callbacks?.setInbox?.({ ...args, sourceLocations: allSourceLocations });
|
|
168
168
|
},
|
|
169
169
|
setSeen: async (tx, args) => {
|
|
170
|
+
const threadLabels = await tx.query.threadLabel.where('threadId', 'IN', args.threadIds).run();
|
|
171
|
+
const uniqueLabelIds = [...new Set(threadLabels.map(x => x.labelId))];
|
|
172
|
+
if (uniqueLabelIds.length > 0) {
|
|
173
|
+
const labels = await tx.query.accountLabel.where('id', 'IN', uniqueLabelIds).run();
|
|
174
|
+
const delta = args.seen ? -1 : 1;
|
|
175
|
+
for (const label of labels.filter(x => x.specialUse === 'INBOX')) {
|
|
176
|
+
const threadCount = new Set(threadLabels.filter(x => x.labelId === label.id).map(x => x.threadId)).size;
|
|
177
|
+
await tx.mutate.accountLabel.update({
|
|
178
|
+
id: label.id,
|
|
179
|
+
unreadCount: Math.max(0, (label.unreadCount ?? 0) + delta * threadCount),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
170
183
|
for (const threadId of args.threadIds) {
|
|
171
184
|
await tx.mutate.thread.update({
|
|
172
185
|
id: threadId,
|
|
@@ -322,15 +322,35 @@ describe('threadMutators', () => {
|
|
|
322
322
|
});
|
|
323
323
|
});
|
|
324
324
|
describe('setSeen', () => {
|
|
325
|
-
it('sets thread seen status', async () => {
|
|
325
|
+
it('sets thread seen status and updates unread count', async () => {
|
|
326
326
|
const threadUpdate = mock(async () => { });
|
|
327
|
+
const labelUpdate = mock(async () => { });
|
|
328
|
+
const threadLabels = [
|
|
329
|
+
{ labelId: 'test-inbox-label-id', threadId: 'test-thread-id-1' },
|
|
330
|
+
{ labelId: 'test-inbox-label-id', threadId: 'test-thread-id-2' },
|
|
331
|
+
];
|
|
332
|
+
const labels = [{ id: 'test-inbox-label-id', specialUse: 'INBOX', unreadCount: 5 }];
|
|
333
|
+
const runThreadLabels = mock(async () => threadLabels);
|
|
334
|
+
const whereThreadLabel = mock(() => ({ run: runThreadLabels }));
|
|
335
|
+
const runLabels = mock(async () => labels);
|
|
336
|
+
const whereLabel = mock(() => ({ run: runLabels }));
|
|
327
337
|
const transaction = {
|
|
328
338
|
mutate: {
|
|
339
|
+
accountLabel: {
|
|
340
|
+
update: labelUpdate,
|
|
341
|
+
},
|
|
329
342
|
thread: {
|
|
330
343
|
update: threadUpdate,
|
|
331
344
|
},
|
|
332
345
|
},
|
|
333
|
-
query: {
|
|
346
|
+
query: {
|
|
347
|
+
accountLabel: {
|
|
348
|
+
where: whereLabel,
|
|
349
|
+
},
|
|
350
|
+
threadLabel: {
|
|
351
|
+
where: whereThreadLabel,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
334
354
|
};
|
|
335
355
|
const mutators = createMutators();
|
|
336
356
|
await mutators.thread.setSeen(transaction, {
|
|
@@ -346,6 +366,38 @@ describe('threadMutators', () => {
|
|
|
346
366
|
id: 'test-thread-id-2',
|
|
347
367
|
seen: true,
|
|
348
368
|
});
|
|
369
|
+
expect(labelUpdate).toHaveBeenCalledWith({
|
|
370
|
+
id: 'test-inbox-label-id',
|
|
371
|
+
unreadCount: 3,
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
it('skips label update when threads have no labels', async () => {
|
|
375
|
+
const threadUpdate = mock(async () => { });
|
|
376
|
+
const labelUpdate = mock(async () => { });
|
|
377
|
+
const runThreadLabels = mock(async () => []);
|
|
378
|
+
const whereThreadLabel = mock(() => ({ run: runThreadLabels }));
|
|
379
|
+
const transaction = {
|
|
380
|
+
mutate: {
|
|
381
|
+
accountLabel: {
|
|
382
|
+
update: labelUpdate,
|
|
383
|
+
},
|
|
384
|
+
thread: {
|
|
385
|
+
update: threadUpdate,
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
query: {
|
|
389
|
+
threadLabel: {
|
|
390
|
+
where: whereThreadLabel,
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
};
|
|
394
|
+
const mutators = createMutators();
|
|
395
|
+
await mutators.thread.setSeen(transaction, {
|
|
396
|
+
seen: true,
|
|
397
|
+
threadIds: ['test-thread-id-1'],
|
|
398
|
+
});
|
|
399
|
+
expect(threadUpdate).toHaveBeenCalledTimes(1);
|
|
400
|
+
expect(labelUpdate).not.toHaveBeenCalled();
|
|
349
401
|
});
|
|
350
402
|
});
|
|
351
403
|
describe('setSpam', () => {
|