thelounge/src/models/msg.js

88 lines
1.7 KiB
JavaScript
Raw Normal View History

"use strict";
2018-01-11 12:33:36 +01:00
const _ = require("lodash");
2014-09-13 23:29:45 +02: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 21:12:17 +02:00
if (this.type === Msg.Type.TOPIC) {
// Do not log topic that is sent on channel join
return !!this.from.nick;
}
2019-07-17 11:33:59 +02:00
return (
this.type !== Msg.Type.MONOSPACE_BLOCK &&
2017-11-28 18:56:53 +01:00
this.type !== Msg.Type.ERROR &&
2018-06-03 21:12:17 +02:00
this.type !== Msg.Type.TOPIC_SET_BY &&
this.type !== Msg.Type.MODE_CHANNEL &&
2021-12-04 11:42:36 +01:00
this.type !== Msg.Type.MODE_USER &&
2019-07-17 09:34:23 +02:00
this.type !== Msg.Type.RAW &&
2019-10-22 18:44:05 +02:00
this.type !== Msg.Type.WHOIS &&
this.type !== Msg.Type.PLUGIN
2019-07-17 11:33:59 +02:00
);
}
}
2014-09-13 23:29:45 +02:00
Msg.Type = {
UNHANDLED: "unhandled",
AWAY: "away",
2014-09-13 23:29:45 +02:00
ACTION: "action",
BACK: "back",
2014-09-13 23:29:45 +02:00
ERROR: "error",
2016-02-12 12:24:13 +01:00
INVITE: "invite",
2014-09-13 23:29:45 +02:00
JOIN: "join",
KICK: "kick",
MESSAGE: "message",
MODE: "mode",
MODE_CHANNEL: "mode_channel",
2021-12-04 11:42:36 +01:00
MODE_USER: "mode_user", // RPL_UMODEIS
MONOSPACE_BLOCK: "monospace_block",
2014-09-13 23:29:45 +02:00
NICK: "nick",
NOTICE: "notice",
PART: "part",
QUIT: "quit",
CTCP: "ctcp",
CTCP_REQUEST: "ctcp_request",
2017-09-19 17:22:50 +02:00
CHGHOST: "chghost",
2014-09-13 23:29:45 +02:00
TOPIC: "topic",
TOPIC_SET_BY: "topic_set_by",
2017-04-22 14:51:21 +02:00
WHOIS: "whois",
2019-07-17 09:34:23 +02:00
RAW: "raw",
2019-10-22 18:44:05 +02:00
PLUGIN: "plugin",
2021-06-22 12:50:22 +02:00
WALLOPS: "wallops",
2014-09-13 23:29:45 +02:00
};
module.exports = Msg;