/** * 保存服务端向客户端发送的“推送消息”。当用户A向用户B发送消息,服务器会保存此消息,并构建一条通知消息保存到数据库, * 并通过个推系统向B发送此消息。 */ "use strict"; let log = require('../../util/log'); let ImDb = require("../mysql/db/im.db.js"); class NotifyMsgRepo { /** * 保存推送消息。 * * @param to * @param contentType * @param title * @param content * @param message * @param has_pushed * @param delay * @param handler */ static save(to, contentType, title, content, message, has_pushed, delay, handler) { ImDb.execQuery({ "sql": "INSERT INTO push_notify (to_uid, type, title, content, data, delay, has_pushed) VALUES (?,?,?,?,?,?,?)", "args": [to, contentType, title, content, message, delay, has_pushed], "handler": handler }); }; /** * 查找未推送的消息。 */ static findUnpushedMessages(handler) { let sql = "select to_uid, title, type, content, data, delay " + "FROM push_notify " + "WHERE delay IS NOT NULL AND delay > now()"; ImDb.execQuery({ "sql": sql, "args": [], "handler": handler }); }; } module.exports = NotifyMsgRepo;