Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Replace (IRC) with flair #1637

Merged
merged 4 commits into from
Nov 28, 2017
Merged

Replace (IRC) with flair #1637

merged 4 commits into from
Nov 28, 2017

Conversation

lukebarnard1
Copy link
Contributor

@lukebarnard1 lukebarnard1 commented Nov 28, 2017

If a user has public groups that are honoured in their flair, remove the (IRC) to give the appearance that the flair replaces it.

This required a total refactor of how is used. I think it makes sense to do the filtering outside of the component itself anyway, but it was necessary to do this so that SenderProfile could strip "(IRC)" accordingly.

Sadly, this meant SenderProfile became stateful.

If a user has public groups that are honoured in their flair, remove the (IRC) to give the appearance that the flair replaces it.
onClick: React.PropTypes.func,
};

let groups = this.state.groups || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got a bit confusing between the local variables groups, this.state.groups and this.state.relatedGroups. Maybe make the local var displayedGroups and this.state.groups into this.state.userGroups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, fair enough

});
} else {
groups = [];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels like it ought to be pulled out to a displayedGroupsForUserInRoom() or something, but not urgent. Mind you, it would still presumably live in this class given it's having to worry about listening to the related groups changes.

Copy link
Contributor Author

@lukebarnard1 lukebarnard1 Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd still be clearer, so I shall make it so.

if (this.state.relatedGroups && this.state.relatedGroups.length > 0) {
groups = groups.filter((groupId) => {
return this.state.relatedGroups.includes(groupId);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another (faster) way to do this now we have ES6 would be with Set so you could do an actual intersection.

Copy link
Contributor Author

@lukebarnard1 lukebarnard1 Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, Sets don't have a native intersection operator/function. You'd end up doing the Set equivalent of the above, which is to filter and use has instead of includes (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, javascript. Well, I'd imagine it'd still be faster as you'd expect a membership test to be faster with a set than a list, but probably not enough that it's worth changing.

<span className="mx_SenderProfile_name">
{ nameElem }
</span>
{ this.props.enableFlair ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the name mangling above if enableFlair is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I shall change that.

@dbkr dbkr assigned lukebarnard1 and unassigned dbkr Nov 28, 2017
@lukebarnard1 lukebarnard1 assigned dbkr and unassigned lukebarnard1 Nov 28, 2017
@dbkr dbkr merged commit a5acc2c into develop Nov 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants