notify.msg.repo.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * 保存服务端向客户端发送的“推送消息”。当用户A向用户B发送消息,服务器会保存此消息,并构建一条通知消息保存到数据库,
  3. * 并通过个推系统向B发送此消息。
  4. */
  5. "use strict";
  6. let log = require('../util/log');
  7. let imRepo = require("./mysql/im.db.js");
  8. /**
  9. * 保存推送消息。
  10. *
  11. * @param to
  12. * @param contentType
  13. * @param title
  14. * @param content
  15. * @param message
  16. * @param has_pushed
  17. * @param delay
  18. * @param handler
  19. */
  20. exports.save = function(to, contentType, title, content, message, has_pushed, delay, handler) {
  21. imRepo.execQuery({
  22. "sql": "INSERT INTO push_notify (to_uid, type, title, content, data, delay, has_pushed) VALUES (?,?,?,?,?,?,?)",
  23. "args": [to, contentType, title, content, message,delay, has_pushed],
  24. "handler": handler
  25. });
  26. };
  27. /**
  28. * 查找未推送的消息。
  29. */
  30. exports.findUnpushedMessages = function (handler) {
  31. let sql = "select to_uid, title, type, content, data, delay " +
  32. "FROM push_notify " +
  33. "WHERE delay IS NOT NULL AND delay > now()";
  34. imRepo.execQuery({
  35. "sql": sql,
  36. "args": [],
  37. "handler": handler
  38. });
  39. };
  40. //exports.save = save;