display zalgo'd nicknames correctly on chrome/osx

This commit is contained in:
Matthew Hodgson 2015-07-30 00:48:20 +01:00
parent 2d1b88e50d
commit 55a4f3e3a1
5 changed files with 30 additions and 5 deletions

View file

@ -98,6 +98,9 @@ limitations under the License.
opacity: 0.5; opacity: 0.5;
} }
.mx_MemberTile_zalgo {
font-family: Helvetica, Arial, Sans-Serif;
}
.mx_MemberTile_leave { .mx_MemberTile_leave {
float: right; float: right;

View file

@ -14,5 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
.mx_SenderProfile { .mx_SenderProfile_zalgo {
font-family: Helvetica, Arial, Sans-Serif;
} }

View file

@ -25,6 +25,10 @@ var MemberTileController = require("../../../../src/controllers/molecules/Member
var MemberInfo = ComponentBroker.get('molecules/MemberInfo'); var MemberInfo = ComponentBroker.get('molecules/MemberInfo');
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog"); var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
// The Lato WOFF doesn't include sensible combining diacritics, so Chrome chokes on rendering them.
// Revert to Arial when this happens, which on OSX works at least.
var zalgo = /[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/;
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'MemberTile', displayName: 'MemberTile',
mixins: [MemberTileController], mixins: [MemberTileController],
@ -65,18 +69,24 @@ module.exports = React.createClass({
var name = this.props.member.name; var name = this.props.member.name;
if (isMyUser) name += " (me)"; if (isMyUser) name += " (me)";
var leave = isMyUser ? <span className="mx_MemberTile_leave" onClick={this.onLeaveClick}>X</span> : null; var leave = isMyUser ? <span className="mx_MemberTile_leave" onClick={this.onLeaveClick}>X</span> : null;
var nameClass = this.state.hover ? "mx_MemberTile_nameSpan" : "mx_MemberTile_name";
if (zalgo.test(name)) {
nameClass += " mx_MemberTile_zalgo";
}
var nameEl; var nameEl;
if (this.state.hover) { if (this.state.hover) {
nameEl = nameEl =
<div className="mx_MemberTile_nameWrapper"> <div className="mx_MemberTile_nameWrapper">
<MemberInfo member={this.props.member} /> <MemberInfo member={this.props.member} />
<span className="mx_MemberTile_nameSpan">{name}</span> <span className={nameClass}>{name}</span>
{leave} {leave}
</div> </div>
} }
else { else {
nameEl = nameEl =
<div className="mx_MemberTile_name"> <div className={nameClass}>
{name} {name}
{leave} {leave}
</div> </div>

View file

@ -57,7 +57,7 @@ module.exports = React.createClass({
mx_MessageTile_notSent: this.props.mxEvent.status == 'not_sent', mx_MessageTile_notSent: this.props.mxEvent.status == 'not_sent',
mx_MessageTile_highlight: this.shouldHighlight(), mx_MessageTile_highlight: this.shouldHighlight(),
mx_MessageTile_continuation: this.props.continuation, mx_MessageTile_continuation: this.props.continuation,
mx_MessageTile_last: this.props.last mx_MessageTile_last: this.props.last,
}); });
var timestamp = <MessageTimestamp ts={this.props.mxEvent.getTs()} /> var timestamp = <MessageTimestamp ts={this.props.mxEvent.getTs()} />
var avatar, sender, resend; var avatar, sender, resend;

View file

@ -17,9 +17,14 @@ limitations under the License.
'use strict'; 'use strict';
var React = require('react'); var React = require('react');
var classNames = require("classnames");
var SenderProfileController = require("../../../../src/controllers/molecules/SenderProfile"); var SenderProfileController = require("../../../../src/controllers/molecules/SenderProfile");
// The Lato WOFF doesn't include sensible combining diacritics, so Chrome chokes on rendering them.
// Revert to Arial when this happens, which on OSX works at least.
var zalgo = /[\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f]/;
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'SenderProfile', displayName: 'SenderProfile',
mixins: [SenderProfileController], mixins: [SenderProfileController],
@ -28,12 +33,18 @@ module.exports = React.createClass({
var mxEvent = this.props.mxEvent; var mxEvent = this.props.mxEvent;
var name = mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender(); var name = mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender();
var classes = classNames({
mx_SenderProfile: true,
// taken from https://en.wikipedia.org/wiki/Combining_character
mx_SenderProfile_zalgo: zalgo.test(name),
});
var msgtype = mxEvent.getContent().msgtype; var msgtype = mxEvent.getContent().msgtype;
if (msgtype && msgtype == 'm.emote') { if (msgtype && msgtype == 'm.emote') {
name = ''; // emote message must include the name so don't duplicate it name = ''; // emote message must include the name so don't duplicate it
} }
return ( return (
<span className="mx_SenderProfile"> <span className={classes}>
{name} {name}
</span> </span>
); );