diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 797c4f0..61bddb3 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -413,7 +413,7 @@ Cosmopolite.prototype.sendMessage = function(subject, message) { (subject['readable_only_by'] || subject['writable_only_by'])) { console.log(this.loggingPrefix_(), 'local subjects can\'t have ACLs:', subject); - reject(); + reject(new Error('Local subject with ACL')); return; } diff --git a/static/hogfather.js b/static/hogfather.js index 5abd5cb..d747314 100644 --- a/static/hogfather.js +++ b/static/hogfather.js @@ -109,6 +109,22 @@ hogfather.PublicChat.prototype.getID = function() { }; +/** + * @return {boolean} + */ +hogfather.PublicChat.prototype.amOwner = function() { + return this.owners_.indexOf(this.cosmo_.currentProfile()) >= 0; +}; + + +/** + * @return {boolean} + */ +hogfather.PublicChat.prototype.amWriter = function() { + return this.writers_.indexOf(this.cosmo_.currentProfile()) >= 0; +}; + + /** * @private * @param {Cosmopolite.typeMessage} message @@ -162,10 +178,20 @@ hogfather.PublicChat.prototype.getMessages = function() { * @return {Promise} */ hogfather.PublicChat.prototype.sendMessage = function(message) { - return this.cosmo_.sendMessage(this.subject_, { - type: 'message', - message: message, - }); + return new Promise(function(resolve, reject) { + if (!this.amWriter()) { + reject(new Error('Write access denied')); + return; + } + this.cosmo_.sendMessage(this.subject_, { + type: 'message', + message: message, + }).then(function(msg) { + resolve(msg); + }).catch(function(err) { + reject(err); + }); + }.bind(this)); };