Nachrichten: kein Pushover wenn Empfänger aktiv im Chat
This commit is contained in:
@@ -38,6 +38,17 @@ router.post('/keys', authenticate, (req, res) => {
|
||||
});
|
||||
|
||||
// ── Users ─────────────────────────────────────────────────────────────────────
|
||||
// Presence: User ist gerade aktiv im Chat
|
||||
router.post('/presence', authenticate, (req, res) => {
|
||||
const { active } = req.body;
|
||||
if (active) {
|
||||
db.prepare("UPDATE users SET chat_active_at=datetime('now','localtime') WHERE id=?").run(req.user.id);
|
||||
} else {
|
||||
db.prepare("UPDATE users SET chat_active_at=NULL WHERE id=?").run(req.user.id);
|
||||
}
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.get('/users', authenticate, (req, res) => {
|
||||
const me = req.user.id;
|
||||
const isAdmin = req.user.role === 'admin';
|
||||
@@ -120,8 +131,14 @@ router.post('/messages/:userId', authenticate, async (req, res) => {
|
||||
const senderName = db.prepare('SELECT username FROM users WHERE id = ?').get(me)?.username || 'Jemand';
|
||||
const pushover = db.prepare('SELECT * FROM pushover_settings WHERE user_id = ?').get(recipId);
|
||||
if (pushover) {
|
||||
await sendPushover(pushover.user_key, pushover.app_token, 'DickenDock', `Neue Nachricht von ${senderName}`,
|
||||
{ retry: pushover.retry, expire: pushover.expire });
|
||||
// Kein Push wenn Empfänger gerade im Chat ist (aktiv in letzten 45 Sekunden)
|
||||
const presence = db.prepare(`
|
||||
SELECT chat_active_at FROM users WHERE id=? AND chat_active_at > datetime('now','localtime','-45 seconds')
|
||||
`).get(recipId);
|
||||
if (!presence) {
|
||||
await sendPushover(pushover.user_key, pushover.app_token, 'DickenDock', `Neue Nachricht von ${senderName}`,
|
||||
{ retry: pushover.retry, expire: pushover.expire });
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ id: result.lastInsertRowid });
|
||||
|
||||
Reference in New Issue
Block a user