2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 12:33:36 +01:00
|
|
|
const _ = require("lodash");
|
2014-09-13 23:29:45 +02:00
|
|
|
|
|
|
|
module.exports = User;
|
|
|
|
|
2016-09-24 18:34:35 +02:00
|
|
|
function User(attr, prefixLookup) {
|
2016-10-02 09:37:37 +02:00
|
|
|
_.defaults(this, attr, {
|
2016-09-24 18:34:35 +02:00
|
|
|
modes: [],
|
2017-07-10 18:01:20 +02:00
|
|
|
away: "",
|
2017-07-10 12:56:37 +02:00
|
|
|
nick: "",
|
|
|
|
lastMessage: 0,
|
2016-10-02 09:37:37 +02:00
|
|
|
});
|
2016-09-24 18:34:35 +02:00
|
|
|
|
2020-09-01 10:39:36 +02:00
|
|
|
Object.defineProperty(this, "mode", {
|
|
|
|
get() {
|
|
|
|
return this.modes[0] || "";
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-07-11 16:40:43 +02:00
|
|
|
this.setModes(this.modes, prefixLookup);
|
|
|
|
}
|
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
User.prototype.setModes = function (modes, prefixLookup) {
|
2018-02-21 18:48:22 +01:00
|
|
|
// irc-framework sets character mode, but The Lounge works with symbols
|
2017-07-11 16:40:43 +02:00
|
|
|
this.modes = modes.map((mode) => prefixLookup[mode]);
|
|
|
|
};
|
2017-06-01 20:54:46 +02:00
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
User.prototype.toJSON = function () {
|
2017-06-01 20:54:46 +02:00
|
|
|
return {
|
|
|
|
nick: this.nick,
|
2020-09-01 10:39:36 +02:00
|
|
|
modes: this.modes,
|
2017-07-10 12:56:37 +02:00
|
|
|
lastMessage: this.lastMessage,
|
2017-06-01 20:54:46 +02:00
|
|
|
};
|
|
|
|
};
|