@marcoappio/marco-config 2.0.470 → 2.0.471
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;
|
|
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;AAEnF,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;AAKD,eAAO,MAAM,cAAc,OACrB,WAAW,CAAC,eAAe,CAAC,YACtB,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,kBAAkB,EAAE,CAyE9B,CAAA;AAED,eAAO,MAAM,oBAAoB,cACpB,QAAQ,GAAG,SAAS,cACnB,sBAAsB,KACjC,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CA4MxC,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MutationError } from '../../../types';
|
|
2
|
+
import { threadsUtils } from '../../../utils/threads';
|
|
2
3
|
const buildLabelIdList = (labelIds) => labelIds.length === 0 ? '' : ` ${[...new Set(labelIds)].join(' ')} `;
|
|
3
4
|
export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
|
|
4
5
|
const thread = await tx.query.thread.where('id', threadId).one().run();
|
|
@@ -182,17 +183,24 @@ export const createThreadMutators = (_authData, callbacks) => ({
|
|
|
182
183
|
callbacks?.setInbox?.({ ...args, sourceLocations: allSourceLocations });
|
|
183
184
|
},
|
|
184
185
|
setSeen: async (tx, args) => {
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
const
|
|
186
|
+
const threads = await tx.query.thread.where('id', 'IN', args.threadIds).run();
|
|
187
|
+
const labelCounts = new Map();
|
|
188
|
+
for (const thread of threads) {
|
|
189
|
+
for (const labelId of threadsUtils.parseLabelIdList(thread.labelIdList)) {
|
|
190
|
+
labelCounts.set(labelId, (labelCounts.get(labelId) ?? 0) + 1);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (labelCounts.size > 0) {
|
|
194
|
+
const labels = await tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]).run();
|
|
189
195
|
const delta = args.seen ? -1 : 1;
|
|
190
|
-
for (const label of labels
|
|
191
|
-
const threadCount =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
+
for (const label of labels) {
|
|
197
|
+
const threadCount = labelCounts.get(label.id);
|
|
198
|
+
if (threadCount) {
|
|
199
|
+
await tx.mutate.accountLabel.update({
|
|
200
|
+
id: label.id,
|
|
201
|
+
unreadCount: Math.max(0, (label.unreadCount ?? 0) + delta * threadCount),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
for (const threadId of args.threadIds) {
|
|
@@ -369,13 +369,13 @@ describe('threadMutators', () => {
|
|
|
369
369
|
it('sets thread seen status and updates unread count', async () => {
|
|
370
370
|
const threadUpdate = mock(async () => { });
|
|
371
371
|
const labelUpdate = mock(async () => { });
|
|
372
|
-
const
|
|
373
|
-
{
|
|
374
|
-
{
|
|
372
|
+
const threads = [
|
|
373
|
+
{ id: 'test-thread-id-1', labelIdList: ' test-inbox-label-id ' },
|
|
374
|
+
{ id: 'test-thread-id-2', labelIdList: ' test-inbox-label-id ' },
|
|
375
375
|
];
|
|
376
376
|
const labels = [{ id: 'test-inbox-label-id', specialUse: 'INBOX', unreadCount: 5 }];
|
|
377
|
-
const
|
|
378
|
-
const
|
|
377
|
+
const runThreads = mock(async () => threads);
|
|
378
|
+
const whereThread = mock(() => ({ run: runThreads }));
|
|
379
379
|
const runLabels = mock(async () => labels);
|
|
380
380
|
const whereLabel = mock(() => ({ run: runLabels }));
|
|
381
381
|
const transaction = {
|
|
@@ -391,8 +391,8 @@ describe('threadMutators', () => {
|
|
|
391
391
|
accountLabel: {
|
|
392
392
|
where: whereLabel,
|
|
393
393
|
},
|
|
394
|
-
|
|
395
|
-
where:
|
|
394
|
+
thread: {
|
|
395
|
+
where: whereThread,
|
|
396
396
|
},
|
|
397
397
|
},
|
|
398
398
|
};
|
|
@@ -418,8 +418,9 @@ describe('threadMutators', () => {
|
|
|
418
418
|
it('skips label update when threads have no labels', async () => {
|
|
419
419
|
const threadUpdate = mock(async () => { });
|
|
420
420
|
const labelUpdate = mock(async () => { });
|
|
421
|
-
const
|
|
422
|
-
const
|
|
421
|
+
const threads = [{ id: 'test-thread-id-1', labelIdList: '' }];
|
|
422
|
+
const runThreads = mock(async () => threads);
|
|
423
|
+
const whereThread = mock(() => ({ run: runThreads }));
|
|
423
424
|
const transaction = {
|
|
424
425
|
mutate: {
|
|
425
426
|
accountLabel: {
|
|
@@ -430,8 +431,8 @@ describe('threadMutators', () => {
|
|
|
430
431
|
},
|
|
431
432
|
},
|
|
432
433
|
query: {
|
|
433
|
-
|
|
434
|
-
where:
|
|
434
|
+
thread: {
|
|
435
|
+
where: whereThread,
|
|
435
436
|
},
|
|
436
437
|
},
|
|
437
438
|
};
|