Bladeren bron

updates #215, see below.

* Filter by both fullname and jid when searching for users to invite.
* Combine the confirm and prompt popups into a single confirm popup.
* Bugfix in groups filter. Make sure to show group that were previously filtered out.
JC Brand 10 jaren geleden
bovenliggende
commit
37255a2692
2 gewijzigde bestanden met toevoegingen van 30 en 12 verwijderingen
  1. 27 12
      converse.js
  2. 3 0
      spec/chatroom.js

+ 27 - 12
converse.js

@@ -52,12 +52,22 @@
 
     var contains = function (attr, query) {
         return function (item) {
-            return item.get(attr).toLowerCase().indexOf(query.toLowerCase()) !== -1;
+            if (typeof attr === 'object') {
+                var value = false;
+                _.each(attr, function (a) {
+                    value = value || item.get(a).toLowerCase().indexOf(query.toLowerCase()) !== -1;
+                });
+                return value;
+            } else if (typeof attr === 'string') {
+                return item.get(attr).toLowerCase().indexOf(query.toLowerCase()) !== -1;
+            } else {
+                throw new Error('Wrong attribute type. Must be string or array.');
+            }
         };
     };
     contains.not = function (attr, query) {
         return function (item) {
-            return item.get(attr).toLowerCase().indexOf(query.toLowerCase()) === -1;
+            return !(contains(attr, query)(item));
         };
     };
 
@@ -2019,7 +2029,7 @@
                     name: 'contacts-dataset',
                     source: function (q, cb) {
                         var results = [];
-                        _.each(converse.roster.filter(contains('fullname', q)), function (n) {
+                        _.each(converse.roster.filter(contains(['fullname', 'jid'], q)), function (n) {
                             results.push({value: n.get('fullname'), jid: n.get('jid')});
                         });
                         cb(results);
@@ -2029,11 +2039,11 @@
                     }
                 });
                 $el.on('typeahead:selected', $.proxy(function (ev, suggestion, dname) {
-                    var result = confirm(
-                        __(___('Do you want to invite %1$s to the chat room "%2$s"?'), suggestion.value, this.model.get('id'))
+                    var reason = prompt(
+                        __(___('You are about to invite %1$s to the chat room "%2$s". '), suggestion.value, this.model.get('id')) +
+                        __("You may optionally include a message, explaining the reason for the invitation.")
                     );
-                    if (result === true) {
-                        var reason = prompt(__("You may optionally include a message, explaining the reason for the invitation."));
+                    if (reason !== null) {
                         converse.connection.muc.rooms[this.model.get('id')].directInvite(suggestion.jid, reason);
                     }
                     $(ev.target).typeahead('val', '');
@@ -3416,6 +3426,10 @@
                 return view;
             },
 
+            show: function () {
+                this.$el.nextUntil('dt').addBack().show();
+            },
+
             hide: function () {
                 this.$el.nextUntil('dt').addBack().hide();
             },
@@ -3587,11 +3601,12 @@
                 var matches;
                 query = query.toLowerCase();
                 if (type === 'groups') {
-                    matches = _.filter(this.getAll(), function (view) {
-                        return view.model.get('name').toLowerCase().indexOf(query) === -1;
-                    });
-                    _.each(matches, function (view) {
-                        view.hide();
+                    _.each(this.getAll(), function (view, idx) {
+                        if (view.model.get('name').toLowerCase().indexOf(query.toLowerCase()) === -1) {
+                            view.hide();
+                        } else if (view.model.contacts.length > 0) {
+                            view.show();
+                        }
                     });
                 } else {
                     _.each(this.getAll(), function (view) {

+ 3 - 0
spec/chatroom.js

@@ -69,6 +69,9 @@
                 expect($(occupant).attr('title')).toBe('This user is a moderator');
             }, converse));
 
+            it("allows the user to invite their roster contacts to enter the chat room", $.proxy(function () {
+            }, converse));
+
             it("shows received groupchat messages", $.proxy(function () {
                 spyOn(converse, 'emit');
                 var view = this.chatboxviews.get('lounge@muc.localhost');