mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-10 09:32:28 +08:00
Add optional thread message counters to listing
This commit is contained in:
parent
1234496f6e
commit
48be006eba
2 changed files with 44 additions and 0 deletions
|
@ -1503,6 +1503,11 @@ paths:
|
|||
description: 'If true, then includes metaData in the response'
|
||||
schema:
|
||||
type: boolean
|
||||
- name: threadCounters
|
||||
in: query
|
||||
description: 'If true, then includes threadMessageCount in the response. Counters come with some overhead'
|
||||
schema:
|
||||
type: boolean
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many records to return
|
||||
|
@ -1828,6 +1833,11 @@ paths:
|
|||
description: Maximal message size in bytes
|
||||
schema:
|
||||
type: number
|
||||
- name: threadCounters
|
||||
in: query
|
||||
description: 'If true, then includes threadMessageCount in the response. Counters come with some overhead'
|
||||
schema:
|
||||
type: boolean
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many records to return
|
||||
|
@ -6379,6 +6389,9 @@ components:
|
|||
thread:
|
||||
type: string
|
||||
description: ID of the Thread
|
||||
threadMessageCount:
|
||||
type: number
|
||||
description: Amount of messages in the Thread. Included if threadCounters query argument was true
|
||||
from:
|
||||
$ref: '#/components/schemas/Address'
|
||||
to:
|
||||
|
|
|
@ -267,6 +267,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
mailbox: Joi.string().hex().lowercase().length(24).required(),
|
||||
unseen: booleanSchema,
|
||||
metaData: booleanSchema.default(false),
|
||||
threadCounters: booleanSchema.default(false),
|
||||
limit: Joi.number().empty('').default(20).min(1).max(250),
|
||||
order: Joi.any().empty('').allow('asc', 'desc').default('desc'),
|
||||
next: nextPageCursorSchema,
|
||||
|
@ -302,6 +303,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
let user = new ObjectId(result.value.user);
|
||||
let mailbox = new ObjectId(result.value.mailbox);
|
||||
let limit = result.value.limit;
|
||||
let threadCounters = result.value.threadCounters;
|
||||
let page = result.value.page;
|
||||
let pageNext = result.value.next;
|
||||
let pagePrevious = result.value.previous;
|
||||
|
@ -410,6 +412,19 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
page = 1;
|
||||
}
|
||||
|
||||
if (threadCounters) {
|
||||
const threadIdsToFetch = listing.results.map(message => message.thread);
|
||||
const threads = await db.database
|
||||
.collection('threads')
|
||||
.find({ _id: { $in: threadIdsToFetch } })
|
||||
.toArray();
|
||||
|
||||
listing.results = listing.results.map(message => ({
|
||||
...message,
|
||||
threadEntity: threads.find(thread => thread._id.toString() === message.thread.toString())
|
||||
}));
|
||||
}
|
||||
|
||||
let response = {
|
||||
success: true,
|
||||
total,
|
||||
|
@ -454,6 +469,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
flagged: booleanSchema,
|
||||
unseen: booleanSchema,
|
||||
searchable: booleanSchema,
|
||||
threadCounters: booleanSchema.default(false),
|
||||
limit: Joi.number().default(20).min(1).max(250),
|
||||
next: nextPageCursorSchema,
|
||||
previous: previousPageCursorSchema,
|
||||
|
@ -505,6 +521,7 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
let filterMinSize = result.value.minSize;
|
||||
let filterMaxSize = result.value.maxSize;
|
||||
|
||||
let threadCounters = result.value.threadCounters;
|
||||
let limit = result.value.limit;
|
||||
let page = result.value.page;
|
||||
let pageNext = result.value.next;
|
||||
|
@ -819,6 +836,19 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
|
|||
page = 1;
|
||||
}
|
||||
|
||||
if (threadCounters) {
|
||||
const threadIdsToFetch = listing.results.map(message => message.thread);
|
||||
const threads = await db.database
|
||||
.collection('threads')
|
||||
.find({ _id: { $in: threadIdsToFetch } })
|
||||
.toArray();
|
||||
|
||||
listing.results = listing.results.map(message => ({
|
||||
...message,
|
||||
threadEntity: threads.find(thread => thread._id.toString() === message.thread.toString())
|
||||
}));
|
||||
}
|
||||
|
||||
let response = {
|
||||
success: true,
|
||||
query,
|
||||
|
@ -3139,6 +3169,7 @@ function formatMessageListing(messageData) {
|
|||
id: messageData.uid,
|
||||
mailbox: messageData.mailbox,
|
||||
thread: messageData.thread,
|
||||
threadMessageCount: messageData.threadEntity?.ids?.length,
|
||||
from: from && from[0],
|
||||
to,
|
||||
cc,
|
||||
|
|
Loading…
Reference in a new issue