Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix avatar disappearing when setting a topic (#7092)
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
SimonBrandner authored Nov 8, 2021
1 parent 07d9e93 commit 8c9e75b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/components/views/room_settings/RoomProfileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,32 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
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<IState> = {};

// 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<HTMLInputElement>): void => {
Expand Down

0 comments on commit 8c9e75b

Please sign in to comment.