UNPKG

twiedenbein-thelounge

Version:

The self-hosted Web IRC client

93 lines (92 loc) 2.49 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = __importDefault(require("lodash")); const msg_1 = require("../../shared/types/msg"); class Msg { from; id; previews; text; type; self; time; hostmask; target; // TODO: new_nick is only on MessageType.NICK, // we should probably make Msgs that extend this class and use those // throughout. I'll leave any similar fields below. new_nick; highlight; showInActive; new_ident; new_host; ctcpMessage; command; invitedYou; gecos; account; // these are all just for error: error; nick; channel; reason; raw_modes; when; whois; users; statusmsgGroup; params; 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, }; } }); } lodash_1.default.defaults(this, attr, { from: {}, id: 0, previews: [], text: "", type: msg_1.MessageType.MESSAGE, self: false, }); if (this.time) { this.time = new Date(this.time); } else { this.time = new Date(); } } findPreview(link) { return this.previews.find((preview) => preview.link === link); } isLoggable() { if (this.type === msg_1.MessageType.TOPIC) { // Do not log topic that is sent on channel join return !!this.from.nick; } switch (this.type) { case msg_1.MessageType.MONOSPACE_BLOCK: case msg_1.MessageType.ERROR: case msg_1.MessageType.TOPIC_SET_BY: case msg_1.MessageType.MODE_CHANNEL: case msg_1.MessageType.MODE_USER: case msg_1.MessageType.RAW: case msg_1.MessageType.WHOIS: case msg_1.MessageType.PLUGIN: return false; default: return true; } } } exports.default = Msg;