2018-03-13 00:23:32 -04:00
|
|
|
const utils = require("../utils");
|
|
|
|
|
2018-02-11 14:54:30 -05:00
|
|
|
/**
|
|
|
|
* @property {Number} id
|
|
|
|
* @property {String} thread_id
|
|
|
|
* @property {Number} message_type
|
2020-05-24 18:33:10 -04:00
|
|
|
* @property {Number} message_number
|
2018-02-11 14:54:30 -05:00
|
|
|
* @property {String} user_id
|
|
|
|
* @property {String} user_name
|
2020-08-13 17:42:32 -04:00
|
|
|
* @property {String} role_name
|
2018-02-11 14:54:30 -05:00
|
|
|
* @property {String} body
|
|
|
|
* @property {Number} is_anonymous
|
2020-08-13 17:42:32 -04:00
|
|
|
* @property {String[]} attachments
|
|
|
|
* @property {String[]} small_attachments The subset of attachments that were relayed when relaySmallAttachmentsAsAttachments is enabled
|
2020-05-24 18:33:10 -04:00
|
|
|
* @property {String} dm_channel_id
|
|
|
|
* @property {String} dm_message_id
|
|
|
|
* @property {String} inbox_message_id
|
2018-02-11 14:54:30 -05:00
|
|
|
* @property {String} created_at
|
2020-08-13 17:42:32 -04:00
|
|
|
* @property {Number} use_legacy_format
|
2018-02-11 14:54:30 -05:00
|
|
|
*/
|
|
|
|
class ThreadMessage {
|
|
|
|
constructor(props) {
|
2018-03-13 00:23:32 -04:00
|
|
|
utils.setDataModelProps(this, props);
|
2020-08-13 17:42:32 -04:00
|
|
|
|
|
|
|
if (props.attachments) {
|
|
|
|
if (typeof props.attachments === "string") {
|
|
|
|
this.attachments = JSON.parse(props.attachments);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.attachments = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.small_attachments) {
|
|
|
|
if (typeof props.small_attachments === "string") {
|
|
|
|
this.small_attachments = JSON.parse(props.small_attachments);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.small_attachments = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getSQLProps() {
|
|
|
|
return Object.entries(this).reduce((obj, [key, value]) => {
|
|
|
|
if (typeof value === "function") return obj;
|
|
|
|
if (typeof value === "object") {
|
|
|
|
obj[key] = JSON.stringify(value);
|
|
|
|
} else {
|
|
|
|
obj[key] = value;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}, {});
|
2018-02-11 14:54:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ThreadMessage;
|