summaryrefslogtreecommitdiffstats
path: root/app/core/messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/core/messages.js')
-rw-r--r--app/core/messages.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/app/core/messages.js b/app/core/messages.js
index 8c2d893..481a612 100644
--- a/app/core/messages.js
+++ b/app/core/messages.js
@@ -46,6 +46,8 @@ MessageManager.prototype.create = function(options, cb) {
};
MessageManager.prototype.list = function(options, cb) {
+ var Room = mongoose.model('Room');
+
options = options || {};
if (!options.room) {
@@ -105,14 +107,37 @@ MessageManager.prototype.list = function(options, cb) {
find.sort({ 'posted': 1 });
}
- find.limit(options.take)
- .exec(function(err, messages) {
+ Room.findById(options.room, function(err, room) {
+ if (err) {
+ console.error(err);
+ return cb(err);
+ }
+
+ var opts = {
+ userId: options.userId,
+ password: options.password
+ };
+
+ room.canJoin(opts, function(err, canJoin) {
if (err) {
console.error(err);
return cb(err);
}
- cb(null, messages);
+
+ if (!canJoin) {
+ return cb(null, []);
+ }
+
+ find.limit(options.take)
+ .exec(function(err, messages) {
+ if (err) {
+ console.error(err);
+ return cb(err);
+ }
+ cb(null, messages);
+ });
});
+ });
};
module.exports = MessageManager;