@@ -18,6 +18,7 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member";
18
18
import { User } from "matrix-js-sdk/src/models/user" ;
19
19
import { Room } from "matrix-js-sdk/src/models/room" ;
20
20
import { ResizeMethod } from "matrix-js-sdk/src/@types/partials" ;
21
+ import { split } from "lodash" ;
21
22
22
23
import DMRoomMap from './utils/DMRoomMap' ;
23
24
import { mediaFromMxc } from "./customisations/Media" ;
@@ -122,27 +123,13 @@ export function getInitialLetter(name: string): string {
122
123
return undefined ;
123
124
}
124
125
125
- let idx = 0 ;
126
126
const initial = name [ 0 ] ;
127
127
if ( ( initial === '@' || initial === '#' || initial === '+' ) && name [ 1 ] ) {
128
- idx ++ ;
128
+ name = name . substring ( 1 ) ;
129
129
}
130
130
131
- // string.codePointAt(0) would do this, but that isn't supported by
132
- // some browsers (notably PhantomJS).
133
- let chars = 1 ;
134
- const first = name . charCodeAt ( idx ) ;
135
-
136
- // check if it’s the start of a surrogate pair
137
- if ( first >= 0xD800 && first <= 0xDBFF && name [ idx + 1 ] ) {
138
- const second = name . charCodeAt ( idx + 1 ) ;
139
- if ( second >= 0xDC00 && second <= 0xDFFF ) {
140
- chars ++ ;
141
- }
142
- }
143
-
144
- const firstChar = name . substring ( idx , idx + chars ) ;
145
- return firstChar . toUpperCase ( ) ;
131
+ // rely on the grapheme cluster splitter in lodash so that we don't break apart compound emojis
132
+ return split ( name , "" , 1 ) [ 0 ] ;
146
133
}
147
134
148
135
export function avatarUrlForRoom ( room : Room , width : number , height : number , resizeMethod ?: ResizeMethod ) {
0 commit comments