@@ -80,6 +80,9 @@ const useStyles = makeStyles((theme) => ({
8080 margin : "0 -4px" ,
8181 padding : "0 4px 0 2px" ,
8282 } ,
83+ action : {
84+ fontStyle : "italic" ,
85+ } ,
8386} ) ) ;
8487
8588const makeMentionRE = ( username ) => {
@@ -88,6 +91,8 @@ const makeMentionRE = (username) => {
8891 return new RegExp ( `@(all|${ username } )(\\W|$)` , "iu" ) ;
8992} ;
9093
94+ const emojiRE = / : ( [ a - z 0 - 9 _ + - ] + ) : / g;
95+
9196/** A chat sidebar element, opens lobby chat when the `gameId` prop is not set. */
9297function Chat ( {
9398 title,
@@ -129,14 +134,17 @@ function Chat({
129134
130135 function handleSubmit ( event ) {
131136 event . preventDefault ( ) ;
132- const trimmed = input . trim ( ) ;
133- if ( trimmed ) {
137+ let text = input . trim ( ) ;
138+ if ( text ) {
139+ if ( text . startsWith ( "/slap " ) ) {
140+ text = `/me slaps ${ text . slice ( 6 ) } around a bit with a large trout` ;
141+ }
134142 firebase
135143 . database ( )
136144 . ref ( databasePath )
137145 . push ( {
138146 user : user . id ,
139- message : censorText ( trimmed ) ,
147+ message : censorText ( text ) ,
140148 time : firebase . database . ServerValue . TIMESTAMP ,
141149 } ) ;
142150 }
@@ -210,7 +218,7 @@ function Chat({
210218 } ;
211219
212220 const processText = ( text ) => {
213- return text . replace ( / : ( [ a - z 0 - 9 _ + - ] + ) : / g , ( m , n ) => emoji [ n ] || m ) ;
221+ return text . replace ( emojiRE , ( m , n ) => emoji [ n ] || m ) ;
214222 } ;
215223
216224 return (
@@ -243,13 +251,29 @@ function Chat({
243251 item . time ,
244252 < Typography variant = "body2" >
245253 { formatTime ( item . time ) }
246- < User
247- id = { item . user }
248- component = { InternalLink }
249- to = { `/profile/${ item . user } ` }
250- underline = "none"
251- />
252- : { item . message }
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+ ) }
253277 </ Typography >
254278 ) }
255279 { user . admin && (
0 commit comments