Check bookmarks for nicks when joining rooms

This commit is contained in:
JC Brand 2016-09-23 09:41:55 +02:00
parent 7319ebf087
commit e39999f3ec
3 changed files with 51 additions and 4 deletions

View File

@ -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 () {
@ -345,9 +372,16 @@
'name': 'The Play's the Thing',
'autojoin': 'true',
'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));
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);
});
});
}));

View File

@ -65,6 +65,19 @@
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 () {
if (this.model.get('bookmarked')) {
this.$('.icon-pushpin').addClass('button-on');
@ -263,7 +276,7 @@
this.create({
'jid': bookmark.getAttribute('jid'),
'name': bookmark.getAttribute('name'),
'autojoin': bookmark.getAttribute('autojoin'),
'autojoin': bookmark.getAttribute('autojoin') === 'true',
'nick': bookmark.querySelector('nick').textContent
});
}.bind(this));

View File

@ -766,7 +766,7 @@
},
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.
* If so, we'll use that, otherwise we render the nickname
* form.