thelounge/src/models/msg.js

66 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
2014-09-13 23:29:45 +02:00
var _ = require("lodash");
var 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);
}
}
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",
MOTD: "motd",
NICK: "nick",
NOTICE: "notice",
PART: "part",
QUIT: "quit",
CTCP: "ctcp",
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",
BANLIST: "ban_list",
2014-09-13 23:29:45 +02:00
};
module.exports = Msg;