@@ -25,8 +25,24 @@ import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
2525import { isValid3pidInvite } from "../../../RoomInvite" ;
2626import EventListSummary from "./EventListSummary" ;
2727import { replaceableComponent } from "../../../utils/replaceableComponent" ;
28+ import defaultDispatcher from '../../../dispatcher/dispatcher' ;
29+ import { RightPanelPhases } from '../../../stores/RightPanelStorePhases' ;
30+ import { Action } from '../../../dispatcher/actions' ;
31+ import { SetRightPanelPhasePayload } from '../../../dispatcher/payloads/SetRightPanelPhasePayload' ;
32+ import { jsxJoin } from '../../../utils/ReactUtils' ;
33+ import { EventType } from 'matrix-js-sdk/src/@types/event' ;
2834import { Layout } from '../../../settings/Layout' ;
2935
36+ const onPinnedMessagesClick = ( ) : void => {
37+ defaultDispatcher . dispatch < SetRightPanelPhasePayload > ( {
38+ action : Action . SetRightPanelPhase ,
39+ phase : RightPanelPhases . PinnedMessages ,
40+ allowClose : false ,
41+ } ) ;
42+ } ;
43+
44+ const SENDER_AS_DISPLAY_NAME_EVENTS = [ EventType . RoomServerAcl , EventType . RoomPinnedEvents ] ;
45+
3046interface IProps extends Omit < ComponentProps < typeof EventListSummary > , "summaryText" | "summaryMembers" > {
3147 // The maximum number of names to show in either each summary e.g. 2 would result "A, B and 234 others left"
3248 summaryLength ?: number ;
@@ -60,6 +76,7 @@ enum TransitionType {
6076 ChangedAvatar = "changed_avatar" ,
6177 NoChange = "no_change" ,
6278 ServerAcl = "server_acl" ,
79+ ChangedPins = "pinned_messages"
6380}
6481
6582const SEP = "," ;
@@ -93,7 +110,10 @@ export default class MemberEventListSummary extends React.Component<IProps> {
93110 * `Object.keys(eventAggregates)`.
94111 * @returns {string } the textual summary of the aggregated events that occurred.
95112 */
96- private generateSummary ( eventAggregates : Record < string , string [ ] > , orderedTransitionSequences : string [ ] ) {
113+ private generateSummary (
114+ eventAggregates : Record < string , string [ ] > ,
115+ orderedTransitionSequences : string [ ] ,
116+ ) : string | JSX . Element {
97117 const summaries = orderedTransitionSequences . map ( ( transitions ) => {
98118 const userNames = eventAggregates [ transitions ] ;
99119 const nameList = this . renderNameList ( userNames ) ;
@@ -122,7 +142,7 @@ export default class MemberEventListSummary extends React.Component<IProps> {
122142 return null ;
123143 }
124144
125- return summaries . join ( ", " ) ;
145+ return jsxJoin ( summaries , ", " ) ;
126146 }
127147
128148 /**
@@ -216,7 +236,11 @@ export default class MemberEventListSummary extends React.Component<IProps> {
216236 * @param {number } repeats the number of times the transition was repeated in a row.
217237 * @returns {string } the written Human Readable equivalent of the transition.
218238 */
219- private static getDescriptionForTransition ( t : TransitionType , userCount : number , repeats : number ) {
239+ private static getDescriptionForTransition (
240+ t : TransitionType ,
241+ userCount : number ,
242+ repeats : number ,
243+ ) : string | JSX . Element {
220244 // The empty interpolations 'severalUsers' and 'oneUser'
221245 // are there only to show translators to non-English languages
222246 // that the verb is conjugated to plural or singular Subject.
@@ -299,6 +323,15 @@ export default class MemberEventListSummary extends React.Component<IProps> {
299323 { severalUsers : "" , count : repeats } )
300324 : _t ( "%(oneUser)schanged the server ACLs %(count)s times" , { oneUser : "" , count : repeats } ) ;
301325 break ;
326+ case "pinned_messages" :
327+ res = ( userCount > 1 )
328+ ? _t ( "%(severalUsers)schanged the <a>pinned messages</a> for the room %(count)s times." ,
329+ { severalUsers : "" , count : repeats } ,
330+ { "a" : ( sub ) => < a onClick = { onPinnedMessagesClick } > { sub } </ a > } )
331+ : _t ( "%(oneUser)schanged the <a>pinned messages</a> for the room %(count)s times." ,
332+ { oneUser : "" , count : repeats } ,
333+ { "a" : ( sub ) => < a onClick = { onPinnedMessagesClick } > { sub } </ a > } ) ;
334+ break ;
302335 }
303336
304337 return res ;
@@ -317,16 +350,18 @@ export default class MemberEventListSummary extends React.Component<IProps> {
317350 * if a transition is not recognised.
318351 */
319352 private static getTransition ( e : IUserEvents ) : TransitionType {
320- if ( e . mxEvent . getType ( ) === 'm.room.third_party_invite' ) {
353+ const type = e . mxEvent . getType ( ) ;
354+
355+ if ( type === EventType . RoomThirdPartyInvite ) {
321356 // Handle 3pid invites the same as invites so they get bundled together
322357 if ( ! isValid3pidInvite ( e . mxEvent ) ) {
323358 return TransitionType . InviteWithdrawal ;
324359 }
325360 return TransitionType . Invited ;
326- }
327-
328- if ( e . mxEvent . getType ( ) === 'm.room.server_acl' ) {
361+ } else if ( type === EventType . RoomServerAcl ) {
329362 return TransitionType . ServerAcl ;
363+ } else if ( type === EventType . RoomPinnedEvents ) {
364+ return TransitionType . ChangedPins ;
330365 }
331366
332367 switch ( e . mxEvent . getContent ( ) . membership ) {
@@ -415,22 +450,23 @@ export default class MemberEventListSummary extends React.Component<IProps> {
415450 // Object mapping user IDs to an array of IUserEvents
416451 const userEvents : Record < string , IUserEvents [ ] > = { } ;
417452 eventsToRender . forEach ( ( e , index ) => {
418- const userId = e . getType ( ) === 'm.room.server_acl' ? e . getSender ( ) : e . getStateKey ( ) ;
453+ const type = e . getType ( ) ;
454+ const userId = type === EventType . RoomServerAcl ? e . getSender ( ) : e . getStateKey ( ) ;
419455 // Initialise a user's events
420456 if ( ! userEvents [ userId ] ) {
421457 userEvents [ userId ] = [ ] ;
422458 }
423459
424- if ( e . getType ( ) === 'm.room.server_acl' ) {
460+ if ( SENDER_AS_DISPLAY_NAME_EVENTS . includes ( type as EventType ) ) {
425461 latestUserAvatarMember . set ( userId , e . sender ) ;
426462 } else if ( e . target ) {
427463 latestUserAvatarMember . set ( userId , e . target ) ;
428464 }
429465
430466 let displayName = userId ;
431- if ( e . getType ( ) === 'm.room.third_party_invite' ) {
467+ if ( type === EventType . RoomThirdPartyInvite ) {
432468 displayName = e . getContent ( ) . display_name ;
433- } else if ( e . getType ( ) === 'm.room.server_acl' ) {
469+ } else if ( SENDER_AS_DISPLAY_NAME_EVENTS . includes ( type as EventType ) ) {
434470 displayName = e . sender . name ;
435471 } else if ( e . target ) {
436472 displayName = e . target . name ;
0 commit comments