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