소스 검색

Check bookmarks for nicks when joining rooms

JC Brand 8 년 전
부모
커밋
e39999f3ec
3개의 변경된 파일51개의 추가작업 그리고 4개의 파일을 삭제
  1. 36 2
      spec/bookmarks.js
  2. 14 1
      src/converse-bookmarks.js
  3. 1 1
      src/converse-muc.js

+ 36 - 2
spec/bookmarks.js

@@ -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 @@
                                     '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);
         });
         });
     });
     });
 }));
 }));

+ 14 - 1
src/converse-bookmarks.js

@@ -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 @@
                         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));

+ 1 - 1
src/converse-muc.js

@@ -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.