Commit e39999f3 authored by JC Brand's avatar JC Brand

Check bookmarks for nicks when joining rooms

parent 7319ebf0
...@@ -233,6 +233,33 @@ ...@@ -233,6 +233,33 @@
}); });
}); });
}); });
describe("and when autojoin is set", function () {
beforeEach(function () {
converse.bookmarks.reset();
});
it("will be be opened and joined automatically upon login", function () {
spyOn(converse_api.rooms, 'open');
var jid = 'theplay@conference.shakespeare.lit';
var model = converse.bookmarks.create({
'jid': jid,
'autojoin': false,
'name': 'The Play',
'nick': ''
});
expect(converse_api.rooms.open).not.toHaveBeenCalled();
converse.bookmarks.remove(model);
converse.bookmarks.create({
'jid': jid,
'autojoin': true,
'name': 'Hamlet',
'nick': ''
});
expect(converse_api.rooms.open).toHaveBeenCalled();
});
});
}); });
describe("Bookmarks", function () { describe("Bookmarks", function () {
...@@ -345,9 +372,16 @@ ...@@ -345,9 +372,16 @@
'name': 'The Play's the Thing', 'name': 'The Play's the Thing',
'autojoin': 'true', 'autojoin': 'true',
'jid': 'theplay@conference.shakespeare.lit' 'jid': 'theplay@conference.shakespeare.lit'
}).c('nick').t('JC'); }).c('nick').t('JC').up().up()
.c('conference', {
'name': 'Another room',
'autojoin': 'false',
'jid': 'another@conference.shakespeare.lit'
}).c('nick').t('JC').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza)); converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.bookmarks.models.length).toBe(1); expect(converse.bookmarks.models.length).toBe(2);
expect(converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
}); });
}); });
})); }));
...@@ -65,6 +65,19 @@ ...@@ -65,6 +65,19 @@
return this; return this;
}, },
checkForReservedNick: function () {
/* Check if the user has a bookmark with a saved nickanme
* for this room, and if so use it.
* Otherwise delegate to the super method.
*/
var model = converse.bookmarks.findWhere({'jid': this.model.get('jid')});
if (!_.isUndefined(model) && model.get('nick')) {
this.join(this.model.get('nick'));
} else {
this.__super__.checkForReservedNick.apply(this, arguments);
}
},
onBookmarked: function () { onBookmarked: function () {
if (this.model.get('bookmarked')) { if (this.model.get('bookmarked')) {
this.$('.icon-pushpin').addClass('button-on'); this.$('.icon-pushpin').addClass('button-on');
...@@ -263,7 +276,7 @@ ...@@ -263,7 +276,7 @@
this.create({ this.create({
'jid': bookmark.getAttribute('jid'), 'jid': bookmark.getAttribute('jid'),
'name': bookmark.getAttribute('name'), 'name': bookmark.getAttribute('name'),
'autojoin': bookmark.getAttribute('autojoin'), 'autojoin': bookmark.getAttribute('autojoin') === 'true',
'nick': bookmark.querySelector('nick').textContent 'nick': bookmark.querySelector('nick').textContent
}); });
}.bind(this)); }.bind(this));
......
...@@ -766,7 +766,7 @@ ...@@ -766,7 +766,7 @@
}, },
checkForReservedNick: function () { checkForReservedNick: function () {
/* User service-discovery to as the XMPP server whether /* User service-discovery to ask the XMPP server whether
* this user has a reserved nickname for this room. * this user has a reserved nickname for this room.
* If so, we'll use that, otherwise we render the nickname * If so, we'll use that, otherwise we render the nickname
* form. * form.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment