diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 13633cacb..2664b6ba0 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -24,6 +24,7 @@ interface Props { } export class ActionsPanel extends React.Component { + private ourConversation: any; constructor(props: Props) { super(props); this.state = { @@ -31,6 +32,7 @@ export class ActionsPanel extends React.Component { }; this.editProfileHandle = this.editProfileHandle.bind(this); + this.refreshAvatarCallback = this.refreshAvatarCallback.bind(this); } public componentDidMount() { @@ -45,17 +47,33 @@ export class ActionsPanel extends React.Component { // When our primary device updates its avatar, we will need for a message sync to know about that. // Once we get the avatar update, we need to refresh this react component. // So we listen to changes on our profile avatar and use the updated avatarPath (done on message received). - conversation.on('change', () => { - if (conversation.changed?.profileAvatar) { - this.setState({ - avatarPath: conversation.getAvatarPath(), - }); - } - }); + this.ourConversation = conversation; + + this.ourConversation.on( + 'change', + () => { + this.refreshAvatarCallback(this.ourConversation); + }, + 'refreshAvatarCallback' + ); } ); } + public refreshAvatarCallback(conversation: any) { + if (conversation.changed?.profileAvatar) { + this.setState({ + avatarPath: conversation.getAvatarPath(), + }); + } + } + + public componentWillUnmount() { + if (this.ourConversation) { + this.ourConversation.off('change', null, 'refreshAvatarCallback'); + } + } + public Section = ({ isSelected, onSelect,