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