From 65f8991ac8cbefcde100e041a3eedb9ec2654b11 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Thu, 2 Apr 2020 14:50:29 -0400 Subject: [PATCH] invite search: avoid crashing with no associations By using an array, not a set, we stop deduplicating our group index, pushing redundant information instead. When searching, this prevents a component fail state where it cannot search a non-existent index for matches. --- .../chat/src/js/components/lib/invite-search.js | 6 +++--- .../groups/src/js/components/lib/invite-search.js | 15 ++++++--------- .../link/src/js/components/lib/invite-search.js | 15 ++++++--------- .../src/js/components/lib/invite-search.js | 15 ++++++--------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/pkg/interface/chat/src/js/components/lib/invite-search.js b/pkg/interface/chat/src/js/components/lib/invite-search.js index 5a52dcc480..f1340d08e3 100644 --- a/pkg/interface/chat/src/js/components/lib/invite-search.js +++ b/pkg/interface/chat/src/js/components/lib/invite-search.js @@ -33,15 +33,15 @@ export class InviteSearch extends Component { let groups = Array.from(Object.keys(this.props.groups)); groups = groups.filter(e => !e.startsWith("/~/")) .map(e => { - let eachGroup = new Set(); - eachGroup.add(e); + let eachGroup = []; + eachGroup.push(e); if (this.props.associations) { let name = e; if (e in this.props.associations) { name = (this.props.associations[e].metadata.title !== "") ? this.props.associations[e].metadata.title : e; } - eachGroup.add(name); + eachGroup.push(name); } return Array.from(eachGroup); }); diff --git a/pkg/interface/groups/src/js/components/lib/invite-search.js b/pkg/interface/groups/src/js/components/lib/invite-search.js index 97a84c8a3b..1dfed0d850 100644 --- a/pkg/interface/groups/src/js/components/lib/invite-search.js +++ b/pkg/interface/groups/src/js/components/lib/invite-search.js @@ -31,20 +31,17 @@ export class InviteSearch extends Component { peerUpdate() { let groups = Array.from(Object.keys(this.props.groups)); - groups = groups - .filter(e => !e.startsWith("/~/")) + groups = groups.filter(e => !e.startsWith("/~/")) .map(e => { - let eachGroup = new Set(); - eachGroup.add(e); + let eachGroup = []; + eachGroup.push(e); if (this.props.associations) { let name = e; if (e in this.props.associations) { - name = - this.props.associations[e].metadata.title !== "" - ? this.props.associations[e].metadata.title - : e; + name = (this.props.associations[e].metadata.title !== "") + ? this.props.associations[e].metadata.title : e; } - eachGroup.add(name); + eachGroup.push(name); } return Array.from(eachGroup); }); diff --git a/pkg/interface/link/src/js/components/lib/invite-search.js b/pkg/interface/link/src/js/components/lib/invite-search.js index 4d497ec04d..257a5fe2bf 100644 --- a/pkg/interface/link/src/js/components/lib/invite-search.js +++ b/pkg/interface/link/src/js/components/lib/invite-search.js @@ -31,20 +31,17 @@ export class InviteSearch extends Component { peerUpdate() { let groups = Array.from(Object.keys(this.props.groups)); - groups = groups - .filter(e => !e.startsWith("/~/")) + groups = groups.filter(e => !e.startsWith("/~/")) .map(e => { - let eachGroup = new Set(); - eachGroup.add(e); + let eachGroup = []; + eachGroup.push(e); if (this.props.associations) { let name = e; if (e in this.props.associations) { - name = - this.props.associations[e].metadata.title !== "" - ? this.props.associations[e].metadata.title - : e; + name = (this.props.associations[e].metadata.title !== "") + ? this.props.associations[e].metadata.title : e; } - eachGroup.add(name); + eachGroup.push(name); } return Array.from(eachGroup); }); diff --git a/pkg/interface/publish/src/js/components/lib/invite-search.js b/pkg/interface/publish/src/js/components/lib/invite-search.js index 2c8a57bdb4..ac5f2d7ead 100644 --- a/pkg/interface/publish/src/js/components/lib/invite-search.js +++ b/pkg/interface/publish/src/js/components/lib/invite-search.js @@ -31,20 +31,17 @@ export class InviteSearch extends Component { peerUpdate() { let groups = Array.from(Object.keys(this.props.groups)); - groups = groups - .filter(e => !e.startsWith("/~/")) + groups = groups.filter(e => !e.startsWith("/~/")) .map(e => { - let eachGroup = new Set(); - eachGroup.add(e); + let eachGroup = []; + eachGroup.push(e); if (this.props.associations) { let name = e; if (e in this.props.associations) { - name = - this.props.associations[e].metadata.title !== "" - ? this.props.associations[e].metadata.title - : e; + name = (this.props.associations[e].metadata.title !== "") + ? this.props.associations[e].metadata.title : e; } - eachGroup.add(name); + eachGroup.push(name); } return Array.from(eachGroup); });