新增邮件显示已读未读功能

This commit is contained in:
eoao
2025-11-18 22:08:00 +08:00
parent 0395992b5b
commit 9a089da3b7
12 changed files with 102 additions and 16 deletions

View File

@@ -29,3 +29,8 @@ app.post('/email/send', async (c) => {
return c.json(result.ok(email));
});
app.put('/email/read', async (c) => {
await emailService.read(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
})

View File

@@ -43,6 +43,10 @@ export const emailConst = {
SAVING: 6,
NOONE: 7,
FAILED: 8
},
unread: {
UNREAD: 0,
READ: 1
}
}

View File

@@ -21,6 +21,7 @@ export const email = sqliteTable('email', {
status: integer('status').default(0).notNull(),
resendEmailId: text('resend_email_id'),
message: text('message'),
unread: integer('unread').default(0).notNull(),
createTime: text('create_time').default(sql`CURRENT_TIMESTAMP`).notNull(),
isDel: integer('is_del').default(0).notNull()
});

View File

@@ -30,11 +30,22 @@ const init = {
},
async v2_5DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN email_prefix_filter text NOT NULL DEFAULT '';`).run();
} catch (e) {
console.error(e)
}
try {
await c.env.db.batch([
c.env.db.prepare(`ALTER TABLE email ADD COLUMN unread INTEGER NOT NULL DEFAULT 0;`).run(),
c.env.db.prepare(`UPDATE email SET unread = 1;`).run()
]);
} catch (e) {
console.error(e)
}
},
async v2_4DB(c) {

View File

@@ -671,6 +671,11 @@ const emailService = {
async physicsDeleteByAccountId(c, accountId) {
await attService.removeByAccountId(c, accountId);
await orm(c).delete(email).where(eq(email.accountId, accountId)).run();
},
async read(c, params, userId) {
const { emailIds } = params;
await orm(c).update(email).set({ unread: emailConst.unread.READ }).where(and(eq(email.userId, userId), inArray(email.emailId, emailIds)));
}
};