Commit eaa67dab authored by JC Brand's avatar JC Brand

Bugfix. Filtering of contacts stopped working after refactoring

parent 68070166
...@@ -5,7 +5,6 @@ import { _converse, api } from "@converse/headless/core"; ...@@ -5,7 +5,6 @@ import { _converse, api } from "@converse/headless/core";
import { debounce } from "lodash-es"; import { debounce } from "lodash-es";
import { render } from 'lit-html'; import { render } from 'lit-html';
export const RosterFilter = Model.extend({ export const RosterFilter = Model.extend({
initialize () { initialize () {
this.set({ this.set({
...@@ -13,10 +12,9 @@ export const RosterFilter = Model.extend({ ...@@ -13,10 +12,9 @@ export const RosterFilter = Model.extend({
'filter_type': 'contacts', 'filter_type': 'contacts',
'chat_state': 'online' 'chat_state': 'online'
}); });
}, }
}); });
export class RosterFilterView extends ElementView { export class RosterFilterView extends ElementView {
tagName = 'span'; tagName = 'span';
...@@ -30,8 +28,12 @@ export class RosterFilterView extends ElementView { ...@@ -30,8 +28,12 @@ export class RosterFilterView extends ElementView {
this.model.save({'filter_text': this.querySelector('.roster-filter').value}); this.model.save({'filter_text': this.querySelector('.roster-filter').value});
}, 250); }, 250);
this.listenTo(this.model, 'change:filter_type', this.render); this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'change:filter_text', this.render); this.listenTo(
this.model,
'change',
() => this.dispatchEvent(new CustomEvent('update', { 'detail': this.model.changed }))
);
this.listenTo(_converse.roster, "add", this.render); this.listenTo(_converse.roster, "add", this.render);
this.listenTo(_converse.roster, "destroy", this.render); this.listenTo(_converse.roster, "destroy", this.render);
...@@ -102,5 +104,4 @@ export class RosterFilterView extends ElementView { ...@@ -102,5 +104,4 @@ export class RosterFilterView extends ElementView {
} }
} }
api.elements.define('converse-roster-filter', RosterFilterView); api.elements.define('converse-roster-filter', RosterFilterView);
...@@ -80,7 +80,7 @@ const RosterView = OrderedListView.extend({ ...@@ -80,7 +80,7 @@ const RosterView = OrderedListView.extend({
listenToRosterFilter () { listenToRosterFilter () {
this.filter_view = this.el.querySelector('converse-roster-filter'); this.filter_view = this.el.querySelector('converse-roster-filter');
this.listenTo(this.filter_view.model, 'change', this.updateFilter); this.filter_view.addEventListener('update', () => this.updateFilter());
}, },
/** /**
...@@ -91,6 +91,7 @@ const RosterView = OrderedListView.extend({ ...@@ -91,6 +91,7 @@ const RosterView = OrderedListView.extend({
* contact fetched from browser storage. * contact fetched from browser storage.
*/ */
updateFilter: debounce(function () { updateFilter: debounce(function () {
this.filter_view = this.el.querySelector('converse-roster-filter');
const type = this.filter_view.model.get('filter_type'); const type = this.filter_view.model.get('filter_type');
if (type === 'state') { if (type === 'state') {
this.filter(this.filter_view.model.get('chat_state'), type); this.filter(this.filter_view.model.get('chat_state'), type);
...@@ -103,7 +104,6 @@ const RosterView = OrderedListView.extend({ ...@@ -103,7 +104,6 @@ const RosterView = OrderedListView.extend({
if (!u.isVisible(this.roster_el)) { if (!u.isVisible(this.roster_el)) {
u.showElement(this.roster_el); u.showElement(this.roster_el);
} }
// this.filter_view.render();
return this; return this;
}, },
......
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