ensl_gathers/lib/chat/chatroom.js

34 lines
627 B
JavaScript
Raw Normal View History

2015-07-21 14:10:24 +00:00
"use strict";
var Message = require("./message");
function Chatroom (o) {
if (!(this instanceof Chatroom)) {
return new Chatroom(o);
}
this.messages = [];
};
Chatroom.prototype.createMessage = function (options, callback) {
var message = new Message({
author: options.author,
content: options.content
})
this.messages.push(message);
if (callback) {
return callback(message);
}
};
Chatroom.prototype.retrieveMessages = function (n) {
return this.messages
.slice(this.messages.length - n, this.messages.length)
.map(function (message) {
return message.toJson();
});
};
module.exports = Chatroom;