Commit 9ea018a5 authored by JC Brand's avatar JC Brand

Trigger `onBookmarksFetched` event and use to autojoin rooms

parent aad90cc9
...@@ -143,7 +143,6 @@ ...@@ -143,7 +143,6 @@
'name': $form.find('input[name=name]').val(), 'name': $form.find('input[name=name]').val(),
'nick': $form.find('input[name=nick]').val() 'nick': $form.find('input[name=nick]').val()
}); });
this.model.save('bookmarked', true);
this.$el.find('div.chatroom-form-container').hide( this.$el.find('div.chatroom-form-container').hide(
function () { function () {
$(this).remove(); $(this).remove();
...@@ -179,6 +178,7 @@ ...@@ -179,6 +178,7 @@
model: converse.Bookmark, model: converse.Bookmark,
initialize: function () { initialize: function () {
this.on('bookmarksFetched', this.onBookmarksFetched, this);
this.on('add', this.markRoomAsBookmarked, this); this.on('add', this.markRoomAsBookmarked, this);
this.on('add', this.openBookmarkedRoom, this); this.on('add', this.openBookmarkedRoom, this);
this.on('add', this.sendBookmarkStanza, this); this.on('add', this.sendBookmarkStanza, this);
...@@ -190,10 +190,15 @@ ...@@ -190,10 +190,15 @@
); );
}, },
onBookmarksFetched: function () {
this.each(_.compose(this.markRoomAsBookmarked, this.openBookmarkedRoom));
},
openBookmarkedRoom: function (bookmark) { openBookmarkedRoom: function (bookmark) {
if (bookmark.get('autojoin')) { if (bookmark.get('autojoin')) {
converse_api.rooms.open(bookmark.get('jid'), bookmark.get('nick')); converse_api.rooms.open(bookmark.get('jid'), bookmark.get('nick'));
} }
return bookmark;
}, },
fetchBookmarks: function () { fetchBookmarks: function () {
...@@ -251,6 +256,7 @@ ...@@ -251,6 +256,7 @@
// XMPP server. // XMPP server.
this.fetchBookmarksFromServer(deferred); this.fetchBookmarksFromServer(deferred);
} else { } else {
this.trigger('bookmarksFetched');
return deferred.resolve(); return deferred.resolve();
} }
}, },
...@@ -295,6 +301,7 @@ ...@@ -295,6 +301,7 @@
'nick': bookmark.querySelector('nick').textContent 'nick': bookmark.querySelector('nick').textContent
}, {'silent':true}); }, {'silent':true});
}); });
this.trigger('bookmarksFetched');
if (!_.isUndefined(deferred)) { if (!_.isUndefined(deferred)) {
return deferred.resolve(); return deferred.resolve();
} }
......
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