1234567891011121314151617181920212223242526272829303132333435363738 |
- /**
- * 消息工具。
- *
- * author: Sand
- * since: 1/9/2017
- */
- "use strict";
- let ObjectUtil = require("./object.util.js");
- class MessageUtil {
- /**
- * 将消息的返回结果合并成JSON。
- *
- * @param dataRows
- */
- static fillMessages(dataRows) {
- let messages = {start_id: dataRows.length > 0 ? dataRows[0].msg_id : '', count: dataRows.length, records: []};
- for (let i = 0; i < dataRows.length; i++) {
- let row = dataRows[i];
- let record = {
- id: row.msg_id,
- from: row.from_uid,
- content_type: row.type,
- content: row.content,
- timestamp: ObjectUtil.timestampToLong(row.timestamp)
- };
- if (row.to !== undefined) record.to = row.to;
- if (row.at !== undefined) record.at = row.at;
- messages.records.push(record);
- }
- return messages;
- }
- }
|