Commit 37255a26 authored by JC Brand's avatar JC Brand

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.
parent 4a31978e
...@@ -52,12 +52,22 @@ ...@@ -52,12 +52,22 @@
var contains = function (attr, query) { var contains = function (attr, query) {
return function (item) { 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) { contains.not = function (attr, query) {
return function (item) { return function (item) {
return item.get(attr).toLowerCase().indexOf(query.toLowerCase()) === -1; return !(contains(attr, query)(item));
}; };
}; };
...@@ -2019,7 +2029,7 @@ ...@@ -2019,7 +2029,7 @@
name: 'contacts-dataset', name: 'contacts-dataset',
source: function (q, cb) { source: function (q, cb) {
var results = []; 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')}); results.push({value: n.get('fullname'), jid: n.get('jid')});
}); });
cb(results); cb(results);
...@@ -2029,11 +2039,11 @@ ...@@ -2029,11 +2039,11 @@
} }
}); });
$el.on('typeahead:selected', $.proxy(function (ev, suggestion, dname) { $el.on('typeahead:selected', $.proxy(function (ev, suggestion, dname) {
var result = confirm( var reason = prompt(
__(___('Do you want to invite %1$s to the chat room "%2$s"?'), suggestion.value, this.model.get('id')) __(___('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) { if (reason !== null) {
var reason = prompt(__("You may optionally include a message, explaining the reason for the invitation."));
converse.connection.muc.rooms[this.model.get('id')].directInvite(suggestion.jid, reason); converse.connection.muc.rooms[this.model.get('id')].directInvite(suggestion.jid, reason);
} }
$(ev.target).typeahead('val', ''); $(ev.target).typeahead('val', '');
...@@ -3416,6 +3426,10 @@ ...@@ -3416,6 +3426,10 @@
return view; return view;
}, },
show: function () {
this.$el.nextUntil('dt').addBack().show();
},
hide: function () { hide: function () {
this.$el.nextUntil('dt').addBack().hide(); this.$el.nextUntil('dt').addBack().hide();
}, },
...@@ -3587,11 +3601,12 @@ ...@@ -3587,11 +3601,12 @@
var matches; var matches;
query = query.toLowerCase(); query = query.toLowerCase();
if (type === 'groups') { if (type === 'groups') {
matches = _.filter(this.getAll(), function (view) { _.each(this.getAll(), function (view, idx) {
return view.model.get('name').toLowerCase().indexOf(query) === -1; if (view.model.get('name').toLowerCase().indexOf(query.toLowerCase()) === -1) {
}); view.hide();
_.each(matches, function (view) { } else if (view.model.contacts.length > 0) {
view.hide(); view.show();
}
}); });
} else { } else {
_.each(this.getAll(), function (view) { _.each(this.getAll(), function (view) {
......
...@@ -69,6 +69,9 @@ ...@@ -69,6 +69,9 @@
expect($(occupant).attr('title')).toBe('This user is a moderator'); expect($(occupant).attr('title')).toBe('This user is a moderator');
}, converse)); }, 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 () { it("shows received groupchat messages", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var view = this.chatboxviews.get('lounge@muc.localhost'); var view = this.chatboxviews.get('lounge@muc.localhost');
......
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