Improved way to retrieve event sender for thread summary (#7732)

This commit is contained in:
Germain 2022-02-08 12:08:47 +00:00 committed by GitHub
parent 773c7f46b7
commit af0b21de9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -360,6 +360,7 @@ interface IState {
thread: Thread; thread: Thread;
threadReplyCount: number; threadReplyCount: number;
threadLastReply: MatrixEvent; threadLastReply: MatrixEvent;
threadLastSender: RoomMember | null;
threadNotification?: NotificationCountType; threadNotification?: NotificationCountType;
} }
@ -408,6 +409,7 @@ export default class EventTile extends React.Component<IProps, IState> {
thread, thread,
threadReplyCount: thread?.length, threadReplyCount: thread?.length,
threadLastReply: thread?.replyToEvent, threadLastReply: thread?.replyToEvent,
threadLastSender: thread?.replyToEvent.sender,
}; };
// don't do RR animations until we are mounted // don't do RR animations until we are mounted
@ -562,6 +564,7 @@ export default class EventTile extends React.Component<IProps, IState> {
this.setState({ this.setState({
threadLastReply: thread?.replyToEvent, threadLastReply: thread?.replyToEvent,
threadLastSender: thread?.replyToEvent?.sender,
threadReplyCount: thread?.length, threadReplyCount: thread?.length,
thread, thread,
}); });
@ -659,23 +662,24 @@ export default class EventTile extends React.Component<IProps, IState> {
private renderThreadLastMessagePreview(): JSX.Element | null { private renderThreadLastMessagePreview(): JSX.Element | null {
const { threadLastReply } = this.state; const { threadLastReply } = this.state;
if (!threadLastReply) {
return null;
}
const threadMessagePreview = MessagePreviewStore.instance.generatePreviewForEvent(threadLastReply); const threadMessagePreview = MessagePreviewStore.instance.generatePreviewForEvent(threadLastReply);
if (!threadMessagePreview || !threadLastReply.sender) { const sender = this.thread.roomState.getSentinelMember(threadLastReply.getSender());
return null;
}
return <> return <>
<MemberAvatar member={threadLastReply.sender} width={24} height={24} className="mx_ThreadInfo_avatar" /> <MemberAvatar
member={sender}
fallbackUserId={threadLastReply.getSender()}
width={24}
height={24}
className="mx_ThreadInfo_avatar"
/>
{ threadMessagePreview && (
<div className="mx_ThreadInfo_content"> <div className="mx_ThreadInfo_content">
<span className="mx_ThreadInfo_message-preview"> <span className="mx_ThreadInfo_message-preview">
{ threadMessagePreview } { threadMessagePreview }
</span> </span>
</div> </div>
) }
</>; </>;
} }