From 8c9e75b16e4fedf0e4778b7dab0004a9bdb36b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 8 Nov 2021 12:58:26 +0100 Subject: [PATCH] Fix avatar disappearing when setting a topic (#7092) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../room_settings/RoomProfileSettings.tsx | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/components/views/room_settings/RoomProfileSettings.tsx b/src/components/views/room_settings/RoomProfileSettings.tsx index 8cc7a620f8..f60a41ad89 100644 --- a/src/components/views/room_settings/RoomProfileSettings.tsx +++ b/src/components/views/room_settings/RoomProfileSettings.tsx @@ -121,43 +121,32 @@ export default class RoomProfileSettings extends React.Component this.setState({ profileFieldsTouched: {} }); const client = MatrixClientPeg.get(); - - let originalDisplayName: string; - let avatarUrl: string; - let originalAvatarUrl: string; - let originalTopic: string; - let avatarFile: File; + const newState: Partial = {}; // TODO: What do we do about errors? const displayName = this.state.displayName.trim(); if (this.state.originalDisplayName !== this.state.displayName) { await client.setRoomName(this.props.roomId, displayName); - originalDisplayName = displayName; + newState.originalDisplayName = displayName; + newState.displayName = displayName; } if (this.state.avatarFile) { const uri = await client.uploadContent(this.state.avatarFile); await client.sendStateEvent(this.props.roomId, 'm.room.avatar', { url: uri }, ''); - avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96); - originalAvatarUrl = avatarUrl; - avatarFile = null; + newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96); + newState.originalAvatarUrl = newState.avatarUrl; + newState.avatarFile = null; } else if (this.state.originalAvatarUrl !== this.state.avatarUrl) { await client.sendStateEvent(this.props.roomId, 'm.room.avatar', {}, ''); } if (this.state.originalTopic !== this.state.topic) { await client.setRoomTopic(this.props.roomId, this.state.topic); - originalTopic = this.state.topic; + newState.originalTopic = this.state.topic; } - this.setState({ - originalAvatarUrl, - avatarUrl, - originalDisplayName, - originalTopic, - displayName, - avatarFile, - }); + this.setState(newState as IState); }; private onDisplayNameChanged = (e: React.ChangeEvent): void => {