Skip to content

Commit f8c81bf

Browse files
committed
This is why we can't have nice things
1 parent ef9e68c commit f8c81bf

File tree

6 files changed

+21
-46
lines changed

6 files changed

+21
-46
lines changed

src/components/Chat.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import firebase from "../firebase";
1414
import useFirebaseQuery from "../hooks/useFirebaseQuery";
1515
import useStats from "../hooks/useStats";
1616
import useStorage from "../hooks/useStorage";
17-
import { censorText } from "../util";
17+
import { censorText, unicodeTrim } from "../util";
1818
import autoscroll from "../utils/autoscroll";
1919
import emoji from "../utils/emoji";
2020
import ChatCards from "./ChatCards";
@@ -80,9 +80,6 @@ const useStyles = makeStyles((theme) => ({
8080
margin: "0 -4px",
8181
padding: "0 4px 0 2px",
8282
},
83-
action: {
84-
fontStyle: "italic",
85-
},
8683
}));
8784

8885
const makeMentionRE = (username) => {
@@ -134,11 +131,8 @@ function Chat({
134131

135132
function handleSubmit(event) {
136133
event.preventDefault();
137-
let text = input.trim();
134+
const text = unicodeTrim(input);
138135
if (text) {
139-
if (text.startsWith("/slap ")) {
140-
text = `/me slaps ${text.slice(6)} around a bit with a large trout`;
141-
}
142136
firebase
143137
.database()
144138
.ref(databasePath)
@@ -251,29 +245,13 @@ function Chat({
251245
item.time,
252246
<Typography variant="body2">
253247
{formatTime(item.time)}
254-
{item.message.startsWith("/me ") ? (
255-
<span className={classes.action}>
256-
*{" "}
257-
<User
258-
id={item.user}
259-
style={{ color: "inherit", fontWeight: "inherit" }}
260-
showIcon={false}
261-
component={InternalLink}
262-
to={`/profile/${item.user}`}
263-
/>
264-
{item.message.slice(3)}
265-
</span>
266-
) : (
267-
<>
268-
<User
269-
id={item.user}
270-
component={InternalLink}
271-
to={`/profile/${item.user}`}
272-
underline="none"
273-
/>
274-
: {item.message}
275-
</>
276-
)}
248+
<User
249+
id={item.user}
250+
component={InternalLink}
251+
to={`/profile/${item.user}`}
252+
underline="none"
253+
/>
254+
: {item.message}
277255
</Typography>
278256
)}
279257
{user.admin && (

src/components/Navbar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ function Navbar() {
7575

7676
function handleChangeSiteTitle(title) {
7777
setChangeSiteTitle(false);
78-
title = (title || "").trim();
7978
if (title) {
8079
firebase.database().ref("site/title").set(title);
8180
}
8281
}
8382

8483
function handleChangeName(name) {
8584
setChangeName(false);
86-
name = (name || "").trim();
8785
if (name) {
8886
firebase.database().ref(`users/${user.id}/name`).set(name);
8987
}

src/components/ProfileName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function ProfileName({ userId }) {
5555

5656
const handleBan = (duration) => {
5757
setBanUser(false);
58-
const seconds = parseDuration((duration || "").trim());
58+
const seconds = parseDuration(duration);
5959
if (seconds) {
6060
const endTime = Date.now() + seconds * 1000;
6161
firebase.database().ref(`users/${userId}/banned`).set(endTime);

src/components/PromptDialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import DialogTitle from "@material-ui/core/DialogTitle";
99
import TextField from "@material-ui/core/TextField";
1010

1111
import { UserContext } from "../context";
12-
import { censorText } from "../util";
12+
import { censorText, unicodeTrim } from "../util";
1313

1414
function PromptDialog(props) {
1515
const { open, onClose, title, message, label, maxLength } = props;
@@ -25,7 +25,7 @@ function PromptDialog(props) {
2525
if (!user.admin && !value.match(/^[\p{L}\p{M}\p{N}\p{P}\p{Zs}]*$/u)) {
2626
alert("Please use only letters, numbers, and punctuation.");
2727
} else {
28-
onClose(censorText(value));
28+
onClose(censorText(unicodeTrim(value)));
2929
setValue("");
3030
}
3131
}

src/components/User.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ const useStyles = makeStyles((theme) => ({
1818
},
1919
}));
2020

21-
function User({
22-
id,
23-
style,
24-
component,
25-
render,
26-
showRating,
27-
showIcon = true,
28-
...other
29-
}) {
21+
function User({ id, style, component, render, showRating, ...other }) {
3022
const theme = useTheme();
3123
const classes = useStyles();
3224

@@ -52,7 +44,7 @@ function User({
5244
{loadingStats ? "⋯" : Math.round(stats[showRating].rating)}
5345
</span>
5446
)}
55-
{showIcon && user.admin && (
47+
{user.admin && (
5648
<Security
5749
fontSize="inherit"
5850
style={{

src/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ export function formatDateTime(timestamp) {
162162
return d.toLocaleString(undefined, opts);
163163
}
164164

165+
const trimRegex =
166+
/^[\p{White_Space}\p{Default_Ignorable_Code_Point}]+|[\p{White_Space}\p{Default_Ignorable_Code_Point}]+$/gu;
167+
168+
export function unicodeTrim(str) {
169+
return str.replace(trimRegex, "");
170+
}
171+
165172
export function parseDuration(spec) {
166173
const units = [7 * 24 * 3600, 24 * 3600, 3600, 60, 1];
167174
const re =

0 commit comments

Comments
 (0)