message.util.js 947 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * 消息工具。
  3. *
  4. * author: Sand
  5. * since: 1/9/2017
  6. */
  7. "use strict";
  8. let ObjectUtil = require("./object.util.js");
  9. class MessageUtil {
  10. /**
  11. * 将消息的返回结果合并成JSON。
  12. *
  13. * @param dataRows
  14. */
  15. static fillMessages(dataRows) {
  16. let messages = {start_id: dataRows.length > 0 ? dataRows[0].msg_id : '', count: dataRows.length, records: []};
  17. for (let i = 0; i < dataRows.length; i++) {
  18. let row = dataRows[i];
  19. let record = {
  20. id: row.msg_id,
  21. from: row.from_uid,
  22. content_type: row.type,
  23. content: row.content,
  24. timestamp: ObjectUtil.timestampToLong(row.timestamp)
  25. };
  26. if (row.to !== undefined) record.to = row.to;
  27. if (row.at !== undefined) record.at = row.at;
  28. messages.records.push(record);
  29. }
  30. return messages;
  31. }
  32. }