Bookmarked rooms will now be automatically opened
If configured for it.
This commit is contained in:
parent
e80f001b35
commit
6972066076
|
@ -2,11 +2,12 @@
|
|||
(function (root, factory) {
|
||||
define([
|
||||
"jquery",
|
||||
"underscore",
|
||||
"utils",
|
||||
"mock",
|
||||
"test_utils"
|
||||
], factory);
|
||||
} (this, function ($, utils, mock, test_utils) {
|
||||
} (this, function ($, _, utils, mock, test_utils) {
|
||||
"use strict";
|
||||
var $iq = converse_api.env.$iq,
|
||||
Strophe = converse_api.env.Strophe;
|
||||
|
@ -122,6 +123,26 @@
|
|||
// nothing to test for here.
|
||||
});
|
||||
|
||||
it("will be automatilly opened if 'autojoin' is set on the bookmark", function () {
|
||||
var jid = 'lounge@localhost';
|
||||
converse.bookmarks.create({
|
||||
'jid': jid,
|
||||
'autojoin': false,
|
||||
'name': 'The Lounge',
|
||||
'nick': ' Othello'
|
||||
});
|
||||
expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeTruthy();
|
||||
|
||||
jid = 'theplay@conference.shakespeare.lit';
|
||||
converse.bookmarks.create({
|
||||
'jid': jid,
|
||||
'autojoin': true,
|
||||
'name': 'The Play',
|
||||
'nick': ' Othello'
|
||||
});
|
||||
expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeFalsy();
|
||||
});
|
||||
|
||||
describe("when bookmarked", function () {
|
||||
beforeEach(function () {
|
||||
test_utils.closeAllChatBoxes();
|
||||
|
@ -145,7 +166,7 @@
|
|||
});
|
||||
|
||||
it("can be unbookmarked", function () {
|
||||
var sent_stanza, IQ_id;
|
||||
var view, sent_stanza, IQ_id;
|
||||
var sendIQ = converse.connection.sendIQ;
|
||||
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
||||
sent_stanza = iq;
|
||||
|
@ -159,7 +180,7 @@
|
|||
waits(100);
|
||||
runs(function () {
|
||||
var jid = 'theplay@conference.shakespeare.lit';
|
||||
var view = converse.chatboxviews.get(jid);
|
||||
view = converse.chatboxviews.get(jid);
|
||||
spyOn(view, 'toggleBookmark').andCallThrough();
|
||||
spyOn(converse.bookmarks, 'sendBookmarkStanza').andCallThrough();
|
||||
view.delegateEvents();
|
||||
|
@ -170,7 +191,10 @@
|
|||
'nick': ' Othello'
|
||||
});
|
||||
expect(converse.bookmarks.length).toBe(1);
|
||||
view.model.save('bookmarked', true);
|
||||
});
|
||||
waits(100);
|
||||
runs(function () {
|
||||
expect(view.model.get('bookmarked')).toBeTruthy();
|
||||
var $bookmark_icon = view.$('.icon-pushpin');
|
||||
expect($bookmark_icon.hasClass('button-on')).toBeTruthy();
|
||||
$bookmark_icon.click();
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
initialize: function () {
|
||||
this.__super__.initialize.apply(this, arguments);
|
||||
this.model.on('change:bookmarked', this.onBookmarked, this);
|
||||
this.setBookmarkState();
|
||||
},
|
||||
|
||||
render: function (options) {
|
||||
|
@ -65,7 +66,22 @@
|
|||
},
|
||||
|
||||
onBookmarked: function () {
|
||||
this.$('.icon-pushpin').toggleClass('button-on');
|
||||
if (this.model.get('bookmarked')) {
|
||||
this.$('.icon-pushpin').addClass('button-on');
|
||||
} else {
|
||||
this.$('.icon-pushpin').removeClass('button-on');
|
||||
}
|
||||
},
|
||||
|
||||
setBookmarkState: function () {
|
||||
if (!_.isUndefined(converse.bookmarks)) {
|
||||
var models = converse.bookmarks.where({'jid': this.model.get('jid')});
|
||||
if (!models.length) {
|
||||
this.model.save('bookmarked', false);
|
||||
} else {
|
||||
this.model.save('bookmarked', true);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
renderBookmarkForm: function () {
|
||||
|
@ -129,15 +145,29 @@
|
|||
*/
|
||||
var converse = this.converse;
|
||||
|
||||
converse.Bookmark = Backbone.Model;
|
||||
|
||||
converse.Bookmarks = Backbone.Collection.extend({
|
||||
model: converse.Bookmark,
|
||||
|
||||
initialize: function () {
|
||||
this.on('add', this.markRoomAsBookmarked, this);
|
||||
this.on('add', this.openBookmarkedRoom, this);
|
||||
this.on('remove', this.markRoomAsUnbookmarked, this);
|
||||
|
||||
this.browserStorage = new Backbone.BrowserStorage[converse.storage](
|
||||
b64_sha1('converse.room-bookmarks'+converse.bare_jid)
|
||||
);
|
||||
},
|
||||
|
||||
openBookmarkedRoom: function (bookmark) {
|
||||
if (bookmark.get('autojoin')) {
|
||||
converse_api.rooms.open(bookmark.get('jid'), bookmark.get('nick'));
|
||||
}
|
||||
},
|
||||
|
||||
fetchBookmarks: function () {
|
||||
converse.bookmarks.fetch({
|
||||
this.fetch({
|
||||
'add': true,
|
||||
'success': this.onCachedBookmarksFetched.bind(this),
|
||||
'error': this.onCachedBookmarksFetched.bind(this)
|
||||
|
@ -247,9 +277,6 @@
|
|||
|
||||
converse.initBookmarks = function () {
|
||||
converse.bookmarks = new converse.Bookmarks();
|
||||
var id = b64_sha1('converse.room-bookmarks');
|
||||
converse.bookmarks.id = id;
|
||||
converse.bookmarks.browserStorage = new Backbone.BrowserStorage[converse.storage](id);
|
||||
converse.bookmarks.fetchBookmarks();
|
||||
};
|
||||
converse.on('connected', converse.initBookmarks);
|
||||
|
|
|
@ -1676,7 +1676,8 @@
|
|||
initialize: function () {
|
||||
this.addClientIdentities().addClientFeatures();
|
||||
this.browserStorage = new Backbone.BrowserStorage[converse.storage](
|
||||
b64_sha1('converse.features'+converse.bare_jid));
|
||||
b64_sha1('converse.features'+converse.bare_jid)
|
||||
);
|
||||
this.on('add', this.onFeatureAdded, this);
|
||||
if (this.browserStorage.records.length === 0) {
|
||||
// browserStorage is empty, so we've likely never queried this
|
||||
|
|
Loading…
Reference in New Issue
Block a user