Add Hogfather.Create() factory.
This commit is contained in:
@@ -20,23 +20,42 @@
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Cosmopolite} cosmo
|
* @param {Cosmopolite} cosmo
|
||||||
* @param {string} name
|
* @param {string} prefix
|
||||||
*/
|
*/
|
||||||
var Hogfather = function(cosmo, name) {
|
var Hogfather = function(cosmo, prefix) {
|
||||||
this.cosmo_ = cosmo;
|
this.cosmo_ = cosmo;
|
||||||
this.name_ = name;
|
this.prefix_ = prefix;
|
||||||
|
|
||||||
this.cosmo_.getProfile().then(this.onProfile_.bind(this));
|
console.log(this.loggingPrefix_(), 'create');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} profile_id
|
* @param {Cosmopolite} cosmo
|
||||||
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
Hogfather.prototype.onProfile_ = function(profile_id) {
|
Hogfather.Create = function(cosmo) {
|
||||||
this.prefix_ = '/hogfather/' + profile_id + '/' + this.name_ + '/';
|
return new Promise(function(resolve, reject) {
|
||||||
this.cosmo_.subscribe(this.prefix_ + 'control');
|
var prefix;
|
||||||
console.log(this.prefix_);
|
cosmo.getProfile().then(function(profile_id) {
|
||||||
|
prefix = '/hogfather/' + profile_id + '/' + cosmo.uuid() + '/';
|
||||||
|
var subject = {
|
||||||
|
name: prefix + 'control',
|
||||||
|
readable_only_by: 'me',
|
||||||
|
writeable_only_by: 'me',
|
||||||
|
};
|
||||||
|
var msg = {
|
||||||
|
owners: [profile_id],
|
||||||
|
writers: [profile_id],
|
||||||
|
readers: [profile_id],
|
||||||
|
};
|
||||||
|
return cosmo.sendMessage(subject, msg);
|
||||||
|
}).then(function(msg) {
|
||||||
|
resolve(new Hogfather(cosmo, prefix));
|
||||||
|
}).catch(function(err) {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -44,3 +63,12 @@ Hogfather.prototype.onProfile_ = function(profile_id) {
|
|||||||
*/
|
*/
|
||||||
Hogfather.prototype.shutdown = function() {
|
Hogfather.prototype.shutdown = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
Hogfather.prototype.loggingPrefix_ = function() {
|
||||||
|
return 'hogfather (' + this.prefix_ + '):';
|
||||||
|
};
|
||||||
|
|||||||
@@ -947,7 +947,7 @@ QUnit.asyncTest('sendMessage admin ACL', function(assert) {
|
|||||||
|
|
||||||
QUnit.module('Hogfather');
|
QUnit.module('Hogfather');
|
||||||
|
|
||||||
QUnit.asyncTest('Construct/shutdown', function(assert) {
|
QUnit.test('Construct/shutdown', function(assert) {
|
||||||
assert.expect(4);
|
assert.expect(4);
|
||||||
|
|
||||||
var cosmo = new Cosmopolite(null, randstring());
|
var cosmo = new Cosmopolite(null, randstring());
|
||||||
@@ -956,7 +956,24 @@ QUnit.asyncTest('Construct/shutdown', function(assert) {
|
|||||||
var hogfather = new Hogfather(cosmo, randstring());
|
var hogfather = new Hogfather(cosmo, randstring());
|
||||||
assert.ok(true, 'new Hogfather()) succeeds');
|
assert.ok(true, 'new Hogfather()) succeeds');
|
||||||
|
|
||||||
window.setTimeout(function() {
|
hogfather.shutdown();
|
||||||
|
assert.ok(true, 'Hogfather.shutdown() succeeds');
|
||||||
|
|
||||||
|
cosmo.shutdown();
|
||||||
|
assert.ok(true, 'Cosmopolite.shutdown() succeeds');
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.asyncTest('Create', function(assert) {
|
||||||
|
assert.expect(5);
|
||||||
|
|
||||||
|
var cosmo = new Cosmopolite(null, randstring());
|
||||||
|
assert.ok(true, 'new Cosmopolite() succeeds');
|
||||||
|
|
||||||
|
Hogfather.Create(cosmo).then(function(hogfather) {
|
||||||
|
assert.ok(true, 'Hogfather.Create() succeeds');
|
||||||
|
|
||||||
|
assert.ok(hogfather, 'Hogfather.Create() returns something');
|
||||||
|
|
||||||
hogfather.shutdown();
|
hogfather.shutdown();
|
||||||
assert.ok(true, 'Hogfather.shutdown() succeeds');
|
assert.ok(true, 'Hogfather.shutdown() succeeds');
|
||||||
|
|
||||||
@@ -964,6 +981,5 @@ QUnit.asyncTest('Construct/shutdown', function(assert) {
|
|||||||
assert.ok(true, 'Cosmopolite.shutdown() succeeds');
|
assert.ok(true, 'Cosmopolite.shutdown() succeeds');
|
||||||
|
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 10 * 1000);
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user