Просмотр исходного кода

Don't set fullname in `getChatBox`, it's too generic

Instead do it in `_api.chats.create` which is specifically for private chats.
JC Brand 7 лет назад
Родитель
Сommit
daff088c97
1 измененных файлов с 15 добавлено и 9 удалено
  1. 15 9
      src/converse-chatboxes.js

+ 15 - 9
src/converse-chatboxes.js

@@ -368,15 +368,10 @@
                         jid = attrs.jid;
                     }
                     jid = Strophe.getBareJidFromJid(jid.toLowerCase());
-                    attrs.jid = 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));
                     if (!chatbox && create) {
+                        _.extend(attrs, {'jid': jid, 'id': jid});
                         chatbox = this.create(attrs, {
                             'error' (model, response) {
                                 _converse.log(response.responseText);
@@ -492,9 +487,17 @@
                 'chats': {
                     'create' (jids, attrs) {
                         if (_.isUndefined(jids)) {
-                            _converse.log("chats.create: You need to provide at least one JID", Strophe.LogLevel.ERROR);
+                            _converse.log(
+                                "chats.create: You need to provide at least one JID",
+                                Strophe.LogLevel.ERROR
+                            );
                             return null;
-                        } else if (_.isString(jids)) {
+                        }
+
+                        if (_.isString(jids)) {
+                            if (!attrs.fullname) {
+                                attrs.fullname = _.get(_converse.api.contacts.get(jids), 'attributes.fullname');
+                            }
                             const chatbox = _converse.chatboxes.getChatBox(jids, attrs, true);
                             if (_.isNil(chatbox)) {
                                 _converse.log("Could not open chatbox for JID: "+jids, Strophe.LogLevel.ERROR);
@@ -502,7 +505,10 @@
                             }
                             return chatbox;
                         }
-                        return _.map(jids, (jid) => _converse.chatboxes.getChatBox(jid, attrs, true).trigger('show'));
+                        return _.map(jids, (jid) => {
+                            attrs.fullname = _.get(_converse.api.contacts.get(jid), 'attributes.fullname');
+                            return _converse.chatboxes.getChatBox(jid, attrs, true).trigger('show');
+                        });
                     },
                     'open' (jids, attrs) {
                         if (_.isUndefined(jids)) {