mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
Add starred query to threads route
This commit is contained in:
parent
bc5a4ecf3c
commit
621f8b5c2b
3 changed files with 27 additions and 15 deletions
|
@ -11,7 +11,8 @@ module.exports = (server) => {
|
|||
tags: ['threads'],
|
||||
validate: {
|
||||
query: {
|
||||
unread: Joi.boolean().allow(''),
|
||||
unread: Joi.boolean(),
|
||||
starred: Joi.boolean(),
|
||||
},
|
||||
},
|
||||
response: {
|
||||
|
@ -23,19 +24,25 @@ module.exports = (server) => {
|
|||
handler: (request, reply) => {
|
||||
request.getAccountDatabase().then((db) => {
|
||||
const {Thread} = db;
|
||||
// the unread value will be '' if the url was just '/threads?unread'
|
||||
if (request.query.unread || request.query.unread === '') {
|
||||
Thread.findAll({
|
||||
where: {unreadCount: {gt: 0}},
|
||||
limit: 50,
|
||||
}).then((threads) => {
|
||||
reply(Serialization.jsonStringify(threads));
|
||||
})
|
||||
} else {
|
||||
Thread.findAll({limit: 50}).then((threads) => {
|
||||
reply(Serialization.jsonStringify(threads));
|
||||
})
|
||||
const where = {};
|
||||
|
||||
if (request.query.unread) {
|
||||
where.unreadCount = {gt: 0};
|
||||
} else if (request.query.unread !== undefined) {
|
||||
where.unreadCount = 0;
|
||||
}
|
||||
if (request.query.starred) {
|
||||
where.starredCount = {gt: 0};
|
||||
} else if (request.query.starred !== undefined) {
|
||||
where.starredCount = 0;
|
||||
}
|
||||
|
||||
Thread.findAll({
|
||||
where: where,
|
||||
limit: 50,
|
||||
}).then((threads) => {
|
||||
reply(Serialization.jsonStringify(threads));
|
||||
})
|
||||
})
|
||||
},
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ module.exports = (sequelize, Sequelize) => {
|
|||
subject: Sequelize.STRING,
|
||||
cleanedSubject: Sequelize.STRING,
|
||||
unreadCount: Sequelize.INTEGER,
|
||||
starredCount: Sequelize.INTEGER,
|
||||
}, {
|
||||
classMethods: {
|
||||
associate: ({Message}) => {
|
||||
|
|
|
@ -128,6 +128,7 @@ function matchThread({db, accountId, message}) {
|
|||
subject: message.subject,
|
||||
cleanedSubject: cleanSubject(message.subject),
|
||||
unreadCount: 0,
|
||||
starredCount: 0,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -142,6 +143,7 @@ function matchThread({db, accountId, message}) {
|
|||
subject: message.subject,
|
||||
cleanedSubject: cleanSubject(message.subject),
|
||||
unreadCount: 0,
|
||||
starredCount: 0,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -157,11 +159,13 @@ function addMessageToThread({db, accountId, message}) {
|
|||
}
|
||||
|
||||
function updateThreadProperties({thread, message}) {
|
||||
// Update the thread's unread count
|
||||
if (message.unread) {
|
||||
thread.unreadCount++;
|
||||
thread.save();
|
||||
}
|
||||
if (message.starred) {
|
||||
thread.starredCount++;
|
||||
}
|
||||
thread.save();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue