@@ -82,6 +82,27 @@ function textForCallInviteEvent(event: MatrixEvent): (() => string) | null {
8282 return null ;
8383}
8484
85+ enum Modification {
86+ None ,
87+ Unset ,
88+ Set ,
89+ Changed ,
90+ }
91+
92+ function getModification ( prev ?: string , value ?: string ) : Modification {
93+ if ( prev && value && prev !== value ) {
94+ return Modification . Changed ;
95+ }
96+ if ( prev && ! value ) {
97+ return Modification . Unset ;
98+ }
99+ if ( ! prev && value ) {
100+ return Modification . Set ;
101+ }
102+
103+ return Modification . None ;
104+ }
105+
85106function textForMemberEvent ( ev : MatrixEvent , allowJSX : boolean , showHiddenEvents ?: boolean ) : ( ( ) => string ) | null {
86107 // XXX: SYJS-16 "sender is sometimes null for join messages"
87108 const senderName = ev . sender ?. name || getRoomMemberDisplayname ( ev ) ;
@@ -114,36 +135,44 @@ function textForMemberEvent(ev: MatrixEvent, allowJSX: boolean, showHiddenEvents
114135 : _t ( "%(senderName)s banned %(targetName)s" , { senderName, targetName } ) ;
115136 case "join" :
116137 if ( prevContent && prevContent . membership === "join" ) {
117- if ( prevContent . displayname && content . displayname && prevContent . displayname !== content . displayname ) {
138+ const modDisplayname = getModification ( prevContent . displayname , content . displayname ) ;
139+ const modAvatarUrl = getModification ( prevContent . avatar_url , content . avatar_url ) ;
140+
141+ if ( modDisplayname !== Modification . None && modAvatarUrl !== Modification . None ) {
142+ // Compromise to provide the user with more context without needing 16 translations
118143 return ( ) =>
119- _t ( "%(oldDisplayName)s changed their display name to %(displayName)s " , {
144+ _t ( "%(oldDisplayName)s changed their display name and profile picture " , {
120145 // We're taking the display namke directly from the event content here so we need
121146 // to strip direction override chars which the js-sdk would normally do when
122147 // calculating the display name
123148 oldDisplayName : removeDirectionOverrideChars ( prevContent . displayname ! ) ,
149+ } ) ;
150+ } else if ( modDisplayname === Modification . Changed ) {
151+ return ( ) =>
152+ _t ( "%(oldDisplayName)s changed their display name to %(displayName)s" , {
153+ // We're taking the display name directly from the event content here so we need
154+ // to strip direction override chars which the js-sdk would normally do when
155+ // calculating the display name
156+ oldDisplayName : removeDirectionOverrideChars ( prevContent . displayname ! ) ,
124157 displayName : removeDirectionOverrideChars ( content . displayname ! ) ,
125158 } ) ;
126- } else if ( ! prevContent . displayname && content . displayname ) {
159+ } else if ( modDisplayname === Modification . Set ) {
127160 return ( ) =>
128161 _t ( "%(senderName)s set their display name to %(displayName)s" , {
129162 senderName : ev . getSender ( ) ,
130163 displayName : removeDirectionOverrideChars ( content . displayname ! ) ,
131164 } ) ;
132- } else if ( prevContent . displayname && ! content . displayname ) {
165+ } else if ( modDisplayname === Modification . Unset ) {
133166 return ( ) =>
134167 _t ( "%(senderName)s removed their display name (%(oldDisplayName)s)" , {
135168 senderName,
136169 oldDisplayName : removeDirectionOverrideChars ( prevContent . displayname ! ) ,
137170 } ) ;
138- } else if ( prevContent . avatar_url && ! content . avatar_url ) {
171+ } else if ( modAvatarUrl === Modification . Unset ) {
139172 return ( ) => _t ( "%(senderName)s removed their profile picture" , { senderName } ) ;
140- } else if (
141- prevContent . avatar_url &&
142- content . avatar_url &&
143- prevContent . avatar_url !== content . avatar_url
144- ) {
173+ } else if ( modAvatarUrl === Modification . Changed ) {
145174 return ( ) => _t ( "%(senderName)s changed their profile picture" , { senderName } ) ;
146- } else if ( ! prevContent . avatar_url && content . avatar_url ) {
175+ } else if ( modAvatarUrl === Modification . Set ) {
147176 return ( ) => _t ( "%(senderName)s set a profile picture" , { senderName } ) ;
148177 } else if ( showHiddenEvents ?? SettingsStore . getValue ( "showHiddenEventsInTimeline" ) ) {
149178 // This is a null rejoin, it will only be visible if using 'show hidden events' (labs)
0 commit comments