@marcoappio/marco-config 2.0.504 → 2.0.505
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.
- package/dist/types/AuthData.d.ts +4 -0
- package/dist/types/AuthData.d.ts.map +1 -0
- package/dist/types/AuthData.js +1 -0
- package/dist/types/IMAPSourceLocation.d.ts +7 -0
- package/dist/types/IMAPSourceLocation.d.ts.map +1 -0
- package/dist/types/IMAPSourceLocation.js +1 -0
- package/dist/types/Zero.d.ts +14 -8
- package/dist/types/Zero.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/zero/index.d.ts +7745 -3109
- package/dist/zero/index.d.ts.map +1 -1
- package/dist/zero/index.js +14 -5
- package/dist/zero/mutatorSchemas/account.d.ts +80 -0
- package/dist/zero/mutatorSchemas/account.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/account.js +66 -0
- package/dist/zero/mutatorSchemas/draft.d.ts +150 -0
- package/dist/zero/mutatorSchemas/draft.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/draft.js +104 -0
- package/dist/zero/mutatorSchemas/index.d.ts +323 -0
- package/dist/zero/mutatorSchemas/index.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/index.js +10 -0
- package/dist/zero/mutatorSchemas/thread.d.ts +71 -0
- package/dist/zero/mutatorSchemas/thread.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/thread.js +47 -0
- package/dist/zero/mutatorSchemas/user.d.ts +26 -0
- package/dist/zero/mutatorSchemas/user.d.ts.map +1 -0
- package/dist/zero/mutatorSchemas/user.js +27 -0
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts +3 -188
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -1
- package/dist/zero/mutators/accountMutators/accountMutators.js +82 -118
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +2 -0
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/accountMutators/accountMutators.test.js +372 -0
- package/dist/zero/mutators/accountMutators/index.d.ts +1 -1
- package/dist/zero/mutators/accountMutators/index.d.ts.map +1 -1
- package/dist/zero/mutators/accountMutators/index.js +1 -1
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts +3 -305
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -1
- package/dist/zero/mutators/draftMutators/draftMutators.js +83 -157
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +2 -0
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/draftMutators/draftMutators.test.js +416 -0
- package/dist/zero/mutators/draftMutators/index.d.ts +1 -1
- package/dist/zero/mutators/draftMutators/index.d.ts.map +1 -1
- package/dist/zero/mutators/draftMutators/index.js +1 -1
- package/dist/zero/mutators/index.d.ts +1 -251
- package/dist/zero/mutators/index.d.ts.map +1 -1
- package/dist/zero/mutators/index.js +1 -11
- package/dist/zero/mutators/mutators.d.ts +17 -1519
- package/dist/zero/mutators/mutators.d.ts.map +1 -1
- package/dist/zero/mutators/mutators.js +38 -11
- package/dist/zero/mutators/threadMutators/index.d.ts +1 -1
- package/dist/zero/mutators/threadMutators/index.d.ts.map +1 -1
- package/dist/zero/mutators/threadMutators/index.js +1 -1
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts +6 -199
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -1
- package/dist/zero/mutators/threadMutators/threadMutators.js +87 -119
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +2 -0
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/threadMutators/threadMutators.test.js +755 -0
- package/dist/zero/mutators/userMutators/index.d.ts +1 -1
- package/dist/zero/mutators/userMutators/index.d.ts.map +1 -1
- package/dist/zero/mutators/userMutators/index.js +1 -1
- package/dist/zero/mutators/userMutators/userMutators.d.ts +3 -56
- package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -1
- package/dist/zero/mutators/userMutators/userMutators.js +26 -40
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts +2 -0
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +1 -0
- package/dist/zero/mutators/userMutators/userMutators.test.js +84 -0
- package/dist/zero/queries/getAccounts.d.ts +1025 -4
- package/dist/zero/queries/getAccounts.d.ts.map +1 -1
- package/dist/zero/queries/getAccounts.js +3 -6
- package/dist/zero/queries/getContacts.d.ts +1033 -18
- package/dist/zero/queries/getContacts.d.ts.map +1 -1
- package/dist/zero/queries/getContacts.js +15 -11
- package/dist/zero/queries/getDrafts.d.ts +1031 -11
- package/dist/zero/queries/getDrafts.d.ts.map +1 -1
- package/dist/zero/queries/getDrafts.js +11 -7
- package/dist/zero/queries/getThread.d.ts +1028 -7
- package/dist/zero/queries/getThread.d.ts.map +1 -1
- package/dist/zero/queries/getThread.js +9 -5
- package/dist/zero/queries/getThreadList.d.ts +1035 -23
- package/dist/zero/queries/getThreadList.d.ts.map +1 -1
- package/dist/zero/queries/getThreadList.js +18 -14
- package/dist/zero/queries/getThreads.d.ts +1035 -23
- package/dist/zero/queries/getThreads.d.ts.map +1 -1
- package/dist/zero/queries/getThreads.js +18 -14
- package/dist/zero/queries/getUser.d.ts +1025 -4
- package/dist/zero/queries/getUser.d.ts.map +1 -1
- package/dist/zero/queries/getUser.js +7 -10
- package/dist/zero/queries/index.d.ts +141 -460
- package/dist/zero/queries/index.d.ts.map +1 -1
- package/dist/zero/queries/index.js +10 -18
- package/dist/zero/schema.d.ts +133 -133
- package/dist/zero/schema.d.ts.map +1 -1
- package/dist/zero/schema.js +1 -0
- package/package.json +2 -2
- package/dist/zero/crud.d.ts +0 -1024
- package/dist/zero/crud.d.ts.map +0 -1
- package/dist/zero/crud.js +0 -3
- package/dist/zero/mutators/typedMutator.d.ts +0 -2056
- package/dist/zero/mutators/typedMutator.d.ts.map +0 -1
- package/dist/zero/mutators/typedMutator.js +0 -2
- package/dist/zero/queries/z.d.ts +0 -14439
- package/dist/zero/queries/z.d.ts.map +0 -1
- package/dist/zero/queries/z.js +0 -3
|
@@ -1,46 +1,14 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
import { marcoSchemas } from '../../../schemas';
|
|
3
1
|
import { MutationError } from '../../../types';
|
|
4
2
|
import { threadsUtils } from '../../../utils/threads';
|
|
5
|
-
import { zeroCRUD } from '../../../zero/crud';
|
|
6
|
-
import { defineMutator } from '../../../zero/mutators/typedMutator';
|
|
7
|
-
import { z } from '../../../zero/queries/z';
|
|
8
3
|
const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
|
|
9
|
-
const accountsSchema = v.record(marcoSchemas.string.required(), v.object({
|
|
10
|
-
threadIds: v.array(marcoSchemas.string.required()),
|
|
11
|
-
}));
|
|
12
|
-
const baseThreadSchema = v.object({
|
|
13
|
-
accounts: accountsSchema,
|
|
14
|
-
});
|
|
15
|
-
const threadChangeLabelSchema = v.object({
|
|
16
|
-
accounts: accountsSchema,
|
|
17
|
-
labelPath: marcoSchemas.string.required(),
|
|
18
|
-
});
|
|
19
|
-
export const threadMutatorSchemas = {
|
|
20
|
-
addLabel: threadChangeLabelSchema,
|
|
21
|
-
delete: baseThreadSchema,
|
|
22
|
-
removeLabel: threadChangeLabelSchema,
|
|
23
|
-
setArchive: baseThreadSchema,
|
|
24
|
-
setFlagged: v.object({
|
|
25
|
-
accounts: accountsSchema,
|
|
26
|
-
flagged: v.nonOptional(v.boolean()),
|
|
27
|
-
}),
|
|
28
|
-
setInbox: baseThreadSchema,
|
|
29
|
-
setSeen: v.object({
|
|
30
|
-
accounts: accountsSchema,
|
|
31
|
-
seen: v.boolean(),
|
|
32
|
-
}),
|
|
33
|
-
setSpam: baseThreadSchema,
|
|
34
|
-
setTrash: baseThreadSchema,
|
|
35
|
-
};
|
|
36
4
|
export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
|
|
37
|
-
const thread = await tx.
|
|
5
|
+
const thread = await tx.query.thread.where('id', threadId).one().run();
|
|
38
6
|
if (!thread) {
|
|
39
7
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
40
8
|
}
|
|
41
9
|
const [targetLabel, messages] = await Promise.all([
|
|
42
|
-
tx.
|
|
43
|
-
tx.
|
|
10
|
+
tx.query.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one().run(),
|
|
11
|
+
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
44
12
|
]);
|
|
45
13
|
if (!targetLabel) {
|
|
46
14
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
@@ -52,28 +20,28 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
|
|
|
52
20
|
const threadLabelDeletes = [];
|
|
53
21
|
for (const message of messages) {
|
|
54
22
|
for (const labelId of labelIdsToRemove) {
|
|
55
|
-
threadLabelDeletes.push(tx.mutate
|
|
23
|
+
threadLabelDeletes.push(tx.mutate.threadLabel.delete({
|
|
56
24
|
accountId: thread.accountId,
|
|
57
25
|
labelId,
|
|
58
26
|
threadMessageId: message.id,
|
|
59
|
-
}))
|
|
27
|
+
}));
|
|
60
28
|
}
|
|
61
29
|
}
|
|
62
30
|
await Promise.all([
|
|
63
31
|
...threadLabelDeletes,
|
|
64
|
-
...[...labelIdsToRemove].map(labelId => tx.mutate
|
|
32
|
+
...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
|
|
65
33
|
]);
|
|
66
34
|
if (thread.seen === false && labelIdsToRemove.size > 0) {
|
|
67
|
-
const labelsToUpdate = await tx.
|
|
68
|
-
await Promise.all(labelsToUpdate.map(label => tx.mutate
|
|
35
|
+
const labelsToUpdate = await tx.query.accountLabel.where('id', 'IN', [...labelIdsToRemove]).run();
|
|
36
|
+
await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
|
|
69
37
|
id: label.id,
|
|
70
38
|
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
71
|
-
})))
|
|
39
|
+
})));
|
|
72
40
|
}
|
|
73
41
|
if (!hasTarget) {
|
|
74
42
|
const baseTimestamp = Date.now();
|
|
75
43
|
await Promise.all([
|
|
76
|
-
...messages.map((message, i) => tx.mutate
|
|
44
|
+
...messages.map((message, i) => tx.mutate.threadLabel.insert({
|
|
77
45
|
accountId: thread.accountId,
|
|
78
46
|
labelId: targetLabel.id,
|
|
79
47
|
lastSyncedAt: 0,
|
|
@@ -81,38 +49,38 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
|
|
|
81
49
|
threadMessageId: message.id,
|
|
82
50
|
uid: -(baseTimestamp + i),
|
|
83
51
|
uidValidity: targetLabel.uidValidity ?? 0,
|
|
84
|
-
}))
|
|
85
|
-
tx.mutate
|
|
52
|
+
})),
|
|
53
|
+
tx.mutate.threadByLabel.insert({
|
|
86
54
|
labelId: targetLabel.id,
|
|
87
55
|
latestMessageDate: thread.latestMessageDate,
|
|
88
56
|
threadId,
|
|
89
|
-
})
|
|
57
|
+
}),
|
|
90
58
|
...(thread.seen === false
|
|
91
59
|
? [
|
|
92
|
-
tx.mutate
|
|
60
|
+
tx.mutate.accountLabel.update({
|
|
93
61
|
id: targetLabel.id,
|
|
94
62
|
unreadCount: (targetLabel.unreadCount ?? 0) + 1,
|
|
95
|
-
})
|
|
63
|
+
}),
|
|
96
64
|
]
|
|
97
65
|
: []),
|
|
98
66
|
]);
|
|
99
67
|
}
|
|
100
|
-
await tx.mutate
|
|
68
|
+
await tx.mutate.thread.update({
|
|
101
69
|
id: threadId,
|
|
102
70
|
labelIdList: buildLabelIdList([targetLabel.id]),
|
|
103
|
-
})
|
|
71
|
+
});
|
|
104
72
|
};
|
|
105
|
-
export const
|
|
106
|
-
addLabel:
|
|
107
|
-
for (const [accountId, { threadIds }] of Object.entries(accounts)) {
|
|
108
|
-
const label = await tx.
|
|
73
|
+
export const createThreadMutators = (_authData) => ({
|
|
74
|
+
addLabel: async (tx, args) => {
|
|
75
|
+
for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
|
|
76
|
+
const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
|
|
109
77
|
if (!label) {
|
|
110
78
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
111
79
|
}
|
|
112
80
|
for (const threadId of threadIds) {
|
|
113
81
|
const [thread, messages] = await Promise.all([
|
|
114
|
-
tx.
|
|
115
|
-
tx.
|
|
82
|
+
tx.query.thread.where('id', threadId).one().run(),
|
|
83
|
+
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
116
84
|
]);
|
|
117
85
|
if (!thread) {
|
|
118
86
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
@@ -120,26 +88,26 @@ export const threadMutators = {
|
|
|
120
88
|
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
121
89
|
if (!currentLabelIds.has(label.id)) {
|
|
122
90
|
await Promise.all([
|
|
123
|
-
tx.mutate
|
|
91
|
+
tx.mutate.threadByLabel.insert({
|
|
124
92
|
labelId: label.id,
|
|
125
93
|
latestMessageDate: thread.latestMessageDate,
|
|
126
94
|
threadId,
|
|
127
|
-
})
|
|
95
|
+
}),
|
|
128
96
|
...(thread.seen === false
|
|
129
97
|
? [
|
|
130
|
-
tx.mutate
|
|
98
|
+
tx.mutate.accountLabel.update({
|
|
131
99
|
id: label.id,
|
|
132
100
|
unreadCount: (label.unreadCount ?? 0) + 1,
|
|
133
|
-
})
|
|
101
|
+
}),
|
|
134
102
|
]
|
|
135
103
|
: []),
|
|
136
104
|
]);
|
|
137
105
|
}
|
|
138
|
-
const existingChecks = await Promise.all(messages.map(x => tx.
|
|
106
|
+
const existingChecks = await Promise.all(messages.map(x => tx.query.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one().run()));
|
|
139
107
|
const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
|
|
140
108
|
const baseTimestamp = Date.now();
|
|
141
109
|
if (messagesToInsert.length > 0) {
|
|
142
|
-
await Promise.all(messagesToInsert.map((x, i) => tx.mutate
|
|
110
|
+
await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
|
|
143
111
|
accountId,
|
|
144
112
|
labelId: label.id,
|
|
145
113
|
lastSyncedAt: 0,
|
|
@@ -147,48 +115,48 @@ export const threadMutators = {
|
|
|
147
115
|
threadMessageId: x.id,
|
|
148
116
|
uid: -(baseTimestamp + i),
|
|
149
117
|
uidValidity: label.uidValidity ?? 0,
|
|
150
|
-
})))
|
|
118
|
+
})));
|
|
151
119
|
}
|
|
152
120
|
currentLabelIds.add(label.id);
|
|
153
|
-
await tx.mutate
|
|
121
|
+
await tx.mutate.thread.update({
|
|
154
122
|
id: threadId,
|
|
155
123
|
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
156
|
-
})
|
|
124
|
+
});
|
|
157
125
|
}
|
|
158
126
|
}
|
|
159
|
-
}
|
|
160
|
-
delete:
|
|
161
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
127
|
+
},
|
|
128
|
+
delete: async (tx, args) => {
|
|
129
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
162
130
|
for (const threadId of threadIds) {
|
|
163
|
-
const thread = await tx.
|
|
131
|
+
const thread = await tx.query.thread.where('id', threadId).one().run();
|
|
164
132
|
if (thread) {
|
|
165
133
|
if (thread.seen === false) {
|
|
166
134
|
const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
|
|
167
135
|
if (labelIds.length > 0) {
|
|
168
|
-
const labels = await tx.
|
|
169
|
-
await Promise.all(labels.map(x => tx.mutate
|
|
136
|
+
const labels = await tx.query.accountLabel.where('id', 'IN', labelIds).run();
|
|
137
|
+
await Promise.all(labels.map(x => tx.mutate.accountLabel.update({
|
|
170
138
|
id: x.id,
|
|
171
139
|
unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
|
|
172
|
-
})))
|
|
140
|
+
})));
|
|
173
141
|
}
|
|
174
142
|
}
|
|
175
|
-
await tx.mutate
|
|
143
|
+
await tx.mutate.thread.delete({
|
|
176
144
|
id: threadId,
|
|
177
|
-
})
|
|
145
|
+
});
|
|
178
146
|
}
|
|
179
147
|
}
|
|
180
148
|
}
|
|
181
|
-
}
|
|
182
|
-
removeLabel:
|
|
183
|
-
for (const [accountId, { threadIds }] of Object.entries(accounts)) {
|
|
184
|
-
const label = await tx.
|
|
149
|
+
},
|
|
150
|
+
removeLabel: async (tx, args) => {
|
|
151
|
+
for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
|
|
152
|
+
const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
|
|
185
153
|
if (!label) {
|
|
186
154
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
187
155
|
}
|
|
188
156
|
for (const threadId of threadIds) {
|
|
189
157
|
const [thread, messages] = await Promise.all([
|
|
190
|
-
tx.
|
|
191
|
-
tx.
|
|
158
|
+
tx.query.thread.where('id', threadId).one().run(),
|
|
159
|
+
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
192
160
|
]);
|
|
193
161
|
if (!thread) {
|
|
194
162
|
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
@@ -199,91 +167,91 @@ export const threadMutators = {
|
|
|
199
167
|
}
|
|
200
168
|
currentLabelIds.delete(label.id);
|
|
201
169
|
await Promise.all([
|
|
202
|
-
...messages.map(x => tx.mutate
|
|
170
|
+
...messages.map(x => tx.mutate.threadLabel.delete({
|
|
203
171
|
accountId,
|
|
204
172
|
labelId: label.id,
|
|
205
173
|
threadMessageId: x.id,
|
|
206
|
-
}))
|
|
207
|
-
tx.mutate
|
|
174
|
+
})),
|
|
175
|
+
tx.mutate.threadByLabel.delete({
|
|
208
176
|
labelId: label.id,
|
|
209
177
|
threadId,
|
|
210
|
-
})
|
|
178
|
+
}),
|
|
211
179
|
...(thread.seen === false
|
|
212
180
|
? [
|
|
213
|
-
tx.mutate
|
|
181
|
+
tx.mutate.accountLabel.update({
|
|
214
182
|
id: label.id,
|
|
215
183
|
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
216
|
-
})
|
|
184
|
+
}),
|
|
217
185
|
]
|
|
218
186
|
: []),
|
|
219
|
-
tx.mutate
|
|
187
|
+
tx.mutate.thread.update({
|
|
220
188
|
id: threadId,
|
|
221
189
|
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
222
|
-
})
|
|
190
|
+
}),
|
|
223
191
|
]);
|
|
224
192
|
}
|
|
225
193
|
}
|
|
226
|
-
}
|
|
227
|
-
setArchive:
|
|
228
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
194
|
+
},
|
|
195
|
+
setArchive: async (tx, args) => {
|
|
196
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
229
197
|
for (const threadId of threadIds) {
|
|
230
198
|
await setSystemLabel(tx, threadId, 'ARCHIVE');
|
|
231
199
|
}
|
|
232
200
|
}
|
|
233
|
-
}
|
|
234
|
-
setFlagged:
|
|
235
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
236
|
-
await Promise.all(threadIds.map(threadId => tx.mutate
|
|
237
|
-
flagged,
|
|
201
|
+
},
|
|
202
|
+
setFlagged: async (tx, args) => {
|
|
203
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
204
|
+
await Promise.all(threadIds.map(threadId => tx.mutate.thread.update({
|
|
205
|
+
flagged: args.flagged,
|
|
238
206
|
id: threadId,
|
|
239
|
-
})))
|
|
207
|
+
})));
|
|
240
208
|
}
|
|
241
|
-
}
|
|
242
|
-
setInbox:
|
|
243
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
209
|
+
},
|
|
210
|
+
setInbox: async (tx, args) => {
|
|
211
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
244
212
|
for (const threadId of threadIds) {
|
|
245
213
|
await setSystemLabel(tx, threadId, 'INBOX');
|
|
246
214
|
}
|
|
247
215
|
}
|
|
248
|
-
}
|
|
249
|
-
setSeen:
|
|
250
|
-
const allThreadIds = Object.values(accounts).flatMap(x => x.threadIds);
|
|
251
|
-
const threads = await tx.
|
|
216
|
+
},
|
|
217
|
+
setSeen: async (tx, args) => {
|
|
218
|
+
const allThreadIds = Object.values(args.accounts).flatMap(x => x.threadIds);
|
|
219
|
+
const threads = await tx.query.thread.where('id', 'IN', allThreadIds).run();
|
|
252
220
|
const labelCounts = new Map();
|
|
253
221
|
for (const thread of threads) {
|
|
254
|
-
if (thread.seen !== seen) {
|
|
222
|
+
if (thread.seen !== args.seen) {
|
|
255
223
|
for (const labelId of threadsUtils.parseLabelIdList(thread.labelIdList)) {
|
|
256
224
|
labelCounts.set(labelId, (labelCounts.get(labelId) ?? 0) + 1);
|
|
257
225
|
}
|
|
258
226
|
}
|
|
259
227
|
}
|
|
260
228
|
if (labelCounts.size > 0) {
|
|
261
|
-
const labels = await tx.
|
|
262
|
-
const delta = seen ? -1 : 1;
|
|
229
|
+
const labels = await tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]).run();
|
|
230
|
+
const delta = args.seen ? -1 : 1;
|
|
263
231
|
await Promise.all(labels
|
|
264
232
|
.filter(x => labelCounts.has(x.id))
|
|
265
|
-
.map(x => tx.mutate
|
|
233
|
+
.map(x => tx.mutate.accountLabel.update({
|
|
266
234
|
id: x.id,
|
|
267
235
|
unreadCount: Math.max(0, (x.unreadCount ?? 0) + delta * (labelCounts.get(x.id) ?? 0)),
|
|
268
|
-
})))
|
|
236
|
+
})));
|
|
269
237
|
}
|
|
270
|
-
await Promise.all(allThreadIds.map(threadId => tx.mutate
|
|
238
|
+
await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
|
|
271
239
|
id: threadId,
|
|
272
|
-
seen,
|
|
273
|
-
})))
|
|
274
|
-
}
|
|
275
|
-
setSpam:
|
|
276
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
240
|
+
seen: args.seen,
|
|
241
|
+
})));
|
|
242
|
+
},
|
|
243
|
+
setSpam: async (tx, args) => {
|
|
244
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
277
245
|
for (const threadId of threadIds) {
|
|
278
246
|
await setSystemLabel(tx, threadId, 'SPAM');
|
|
279
247
|
}
|
|
280
248
|
}
|
|
281
|
-
}
|
|
282
|
-
setTrash:
|
|
283
|
-
for (const [, { threadIds }] of Object.entries(accounts)) {
|
|
249
|
+
},
|
|
250
|
+
setTrash: async (tx, args) => {
|
|
251
|
+
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
284
252
|
for (const threadId of threadIds) {
|
|
285
253
|
await setSystemLabel(tx, threadId, 'TRASH');
|
|
286
254
|
}
|
|
287
255
|
}
|
|
288
|
-
}
|
|
289
|
-
};
|
|
256
|
+
},
|
|
257
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threadMutators.test.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.test.ts"],"names":[],"mappings":""}
|