return res.pop();
}
+ async countUnread(to: string): Promise<number> {
+ const res = await this.db.raw<{unread: number}>(`select count(id) as
+ unread from mail
+ where to_account = ? and read_at = 0`, to);
+
+ try {
+ return parseInt(res[0].unread.toString()) || 0;
+ }
+ catch(e) {
+ return 0;
+ }
+ }
+
async listReceivedMessages(to: string): Promise<MessageWithNames[]> {
return this.db.raw<MessageWithNames[]>(`select m.*, a.username
from mail m
where m.to_account = ?
order by sent_at desc`, to);
}
-}
\ No newline at end of file
+}