hardlounge/src/models/msg.js

85 lines
1.6 KiB
JavaScript
Raw Normal View History

"use strict";
2018-01-11 11:33:36 +00:00
const _ = require("lodash");
2014-09-13 21:29:45 +00:00
class Msg {
constructor(attr) {
// Some properties need to be copied in the Msg object instead of referenced
if (attr) {
["from", "target"].forEach((prop) => {
if (attr[prop]) {
this[prop] = {
mode: attr[prop].mode,
nick: attr[prop].nick,
};
}
});
}
_.defaults(this, attr, {
from: {},
id: 0,
previews: [],
text: "",
type: Msg.Type.MESSAGE,
self: false,
});
if (this.time > 0) {
this.time = new Date(this.time);
} else {
this.time = new Date();
}
}
findPreview(link) {
return this.previews.find((preview) => preview.link === link);
}
isLoggable() {
2018-06-03 19:12:17 +00:00
if (this.type === Msg.Type.TOPIC) {
// Do not log topic that is sent on channel join
return !!this.from.nick;
}
2019-07-17 09:33:59 +00:00
return (
this.type !== Msg.Type.MONOSPACE_BLOCK &&
2017-11-28 17:56:53 +00:00
this.type !== Msg.Type.ERROR &&
2018-06-03 19:12:17 +00:00
this.type !== Msg.Type.TOPIC_SET_BY &&
this.type !== Msg.Type.MODE_CHANNEL &&
2019-07-17 07:34:23 +00:00
this.type !== Msg.Type.RAW &&
2019-10-22 16:44:05 +00:00
this.type !== Msg.Type.WHOIS &&
this.type !== Msg.Type.PLUGIN
2019-07-17 09:33:59 +00:00
);
}
}
2014-09-13 21:29:45 +00:00
Msg.Type = {
UNHANDLED: "unhandled",
AWAY: "away",
2014-09-13 21:29:45 +00:00
ACTION: "action",
BACK: "back",
2014-09-13 21:29:45 +00:00
ERROR: "error",
2016-02-12 11:24:13 +00:00
INVITE: "invite",
2014-09-13 21:29:45 +00:00
JOIN: "join",
KICK: "kick",
MESSAGE: "message",
MODE: "mode",
MODE_CHANNEL: "mode_channel",
MONOSPACE_BLOCK: "monospace_block",
2014-09-13 21:29:45 +00:00
NICK: "nick",
NOTICE: "notice",
PART: "part",
QUIT: "quit",
CTCP: "ctcp",
CTCP_REQUEST: "ctcp_request",
2017-09-19 15:22:50 +00:00
CHGHOST: "chghost",
2014-09-13 21:29:45 +00:00
TOPIC: "topic",
TOPIC_SET_BY: "topic_set_by",
2017-04-22 12:51:21 +00:00
WHOIS: "whois",
2019-07-17 07:34:23 +00:00
RAW: "raw",
2019-10-22 16:44:05 +00:00
PLUGIN: "plugin",
2014-09-13 21:29:45 +00:00
};
module.exports = Msg;