Browse Source

Bugfix. Chat wasn't being opened when receiving a message.

JC Brand 7 years ago
parent
commit
03d7f07a4c

+ 16 - 10
spec/chatbox.js

@@ -56,13 +56,14 @@
                     null, ['rosterGroupsFetched'], {},
                     null, ['rosterGroupsFetched'], {},
                     function (done, _converse) {
                     function (done, _converse) {
 
 
+                var view;
+                test_utils.createContacts(_converse, 'current');
                 test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
                 test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
                 .then(function () {
                 .then(function () {
                     return test_utils.waitUntil(function () {
                     return test_utils.waitUntil(function () {
                         return _converse.xmppstatus.get('fullname');
                         return _converse.xmppstatus.get('fullname');
                     }, 300);
                     }, 300);
                 }).then(function () {
                 }).then(function () {
-                    test_utils.createContacts(_converse, 'current');
                     test_utils.openControlBox();
                     test_utils.openControlBox();
                     expect(_converse.chatboxes.length).toEqual(1);
                     expect(_converse.chatboxes.length).toEqual(1);
                     var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
                     var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
@@ -76,15 +77,20 @@
                         .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
                         .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
 
 
                     _converse.chatboxes.onMessage(msg);
                     _converse.chatboxes.onMessage(msg);
-                    var view = _converse.chatboxviews.get(sender_jid);
-                    expect(_.includes($(view.el).find('.chat-msg-author').text(), '**Max Frankfurter')).toBeTruthy();
-                    expect($(view.el).find('.chat-msg-content').text()).toBe(' is tired');
+                    view = _converse.chatboxviews.get(sender_jid);
 
 
-                    message = '/me is as well';
-                    test_utils.sendMessage(view, message);
-                    expect(_.includes($(view.el).find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
-                    expect($(view.el).find('.chat-msg-content:last').text()).toBe(' is as well');
-                    done();
+                    test_utils.waitUntil(function () {
+                        return u.isVisible(view.el);
+                    }).then(function () {
+                        expect(_.includes(view.el.querySelector('.chat-msg-author').textContent, '**Max Frankfurter')).toBeTruthy();
+                        expect($(view.el).find('.chat-msg-content').text()).toBe(' is tired');
+
+                        message = '/me is as well';
+                        test_utils.sendMessage(view, message);
+                        expect(_.includes($(view.el).find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy();
+                        expect($(view.el).find('.chat-msg-content:last').text()).toBe(' is as well');
+                        done();
+                    });
                 });
                 });
             }));
             }));
 
 
@@ -189,7 +195,7 @@
                 test_utils.createContacts(_converse, 'current');
                 test_utils.createContacts(_converse, 'current');
 
 
                 var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
                 var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
-                var chat = _converse.api.chats.open(sender_jid, {
+                var chat = _converse.api.chats.create(sender_jid, {
                     minimized: true
                     minimized: true
                 });
                 });
 
 

+ 5 - 1
src/converse-chatboxes.js

@@ -367,10 +367,14 @@
                         attrs = jid;
                         attrs = jid;
                         jid = attrs.jid;
                         jid = attrs.jid;
                     }
                     }
-                    jid = jid.toLowerCase();
+                    jid = Strophe.getBareJidFromJid(jid.toLowerCase());
                     attrs.jid = jid;
                     attrs.jid = jid;
                     attrs.id = jid;
                     attrs.id = jid;
 
 
+                    if (!attrs.fullname) {
+                        const roster_item = _converse.roster.get(jid);
+                        attrs.fullname = roster_item.get('fullname');
+                    }
                     let  chatbox = this.get(Strophe.getBareJidFromJid(jid));
                     let  chatbox = this.get(Strophe.getBareJidFromJid(jid));
                     if (!chatbox && create) {
                     if (!chatbox && create) {
                         chatbox = this.create(attrs, {
                         chatbox = this.create(attrs, {

+ 9 - 1
src/converse-chatview.js

@@ -688,6 +688,10 @@
                     return message;
                     return message;
                 },
                 },
 
 
+                shouldShowOnTextMessage () {
+                    return !u.isVisible(this.el);
+                },
+
                 handleTextMessage (message) {
                 handleTextMessage (message) {
                     this.showMessage(_.clone(message.attributes));
                     this.showMessage(_.clone(message.attributes));
                     if (u.isNewMessage(message)) {
                     if (u.isNewMessage(message)) {
@@ -701,7 +705,11 @@
                             this.showNewMessagesIndicator();
                             this.showNewMessagesIndicator();
                         }
                         }
                     }
                     }
-                    this.scrollDown();
+                    if (this.shouldShowOnTextMessage()) {
+                        this.show();
+                    } else {
+                        this.scrollDown();
+                    }
                 },
                 },
 
 
                 handleErrorMessage (message) {
                 handleErrorMessage (message) {

+ 5 - 0
src/converse-minimize.js

@@ -116,6 +116,11 @@
                         this.__super__.isNewMessageHidden.apply(this, arguments);
                         this.__super__.isNewMessageHidden.apply(this, arguments);
                 },
                 },
 
 
+                shouldShowOnTextMessage () {
+                    return !this.model.get('minimized') &&
+                        this.__super__.shouldShowOnTextMessage.apply(this, arguments);
+                },
+
                 setChatBoxHeight (height) {
                 setChatBoxHeight (height) {
                     if (!this.model.get('minimized')) {
                     if (!this.model.get('minimized')) {
                         return this.__super__.setChatBoxHeight.apply(this, arguments);
                         return this.__super__.setChatBoxHeight.apply(this, arguments);

+ 1 - 4
src/converse-rosterview.js

@@ -691,11 +691,8 @@
                     // assigned to their various groups.
                     // assigned to their various groups.
                     _converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
                     _converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
 
 
-                    // _converse.on('rosterGroupsFetched', this.positionFetchedGroups, this);
                     _converse.on('rosterContactsFetched', () => {
                     _converse.on('rosterContactsFetched', () => {
-                        _converse.roster.each((contact) => {
-                            this.addRosterContact(contact, {'silent': true});
-                        });
+                        _converse.roster.each((contact) => this.addRosterContact(contact, {'silent': true}));
                         this.update();
                         this.update();
                         this.updateFilter();
                         this.updateFilter();
                         this.trigger('rosterContactsFetchedAndProcessed');
                         this.trigger('rosterContactsFetchedAndProcessed');

+ 4 - 0
src/converse-singleton.js

@@ -63,6 +63,10 @@
             },
             },
 
 
             ChatBoxView: {
             ChatBoxView: {
+                shouldShowOnTextMessage () {
+                    return false;
+                },
+
                 _show (focus) {
                 _show (focus) {
                     /* We only have one chat visible at any one
                     /* We only have one chat visible at any one
                      * time. So before opening a chat, we make sure all other
                      * time. So before opening a chat, we make sure all other