hardlounge/src/models/msg.js

74 lines
1.2 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
2018-01-11 11:33:36 +00:00
let id = 0;
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: id++,
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() {
return this.type !== Msg.Type.MOTD &&
this.type !== Msg.Type.BANLIST &&
this.type !== Msg.Type.WHOIS;
}
}
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",
MOTD: "motd",
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",
BANLIST: "ban_list",
2014-09-13 21:29:45 +00:00
};
module.exports = Msg;