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

Commit 6d86ef6

Browse files
SimonBrandnertoger5
authored andcommitted
Fix avatar disappearing when setting a topic (#7092)
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 9115036 commit 6d86ef6

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/components/views/room_settings/RoomProfileSettings.tsx

+8-19
Original file line numberDiff line numberDiff line change
@@ -121,43 +121,32 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
121121
this.setState({ profileFieldsTouched: {} });
122122

123123
const client = MatrixClientPeg.get();
124-
125-
let originalDisplayName: string;
126-
let avatarUrl: string;
127-
let originalAvatarUrl: string;
128-
let originalTopic: string;
129-
let avatarFile: File;
124+
const newState: Partial<IState> = {};
130125

131126
// TODO: What do we do about errors?
132127
const displayName = this.state.displayName.trim();
133128
if (this.state.originalDisplayName !== this.state.displayName) {
134129
await client.setRoomName(this.props.roomId, displayName);
135-
originalDisplayName = displayName;
130+
newState.originalDisplayName = displayName;
131+
newState.displayName = displayName;
136132
}
137133

138134
if (this.state.avatarFile) {
139135
const uri = await client.uploadContent(this.state.avatarFile);
140136
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', { url: uri }, '');
141-
avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
142-
originalAvatarUrl = avatarUrl;
143-
avatarFile = null;
137+
newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
138+
newState.originalAvatarUrl = newState.avatarUrl;
139+
newState.avatarFile = null;
144140
} else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
145141
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', {}, '');
146142
}
147143

148144
if (this.state.originalTopic !== this.state.topic) {
149145
await client.setRoomTopic(this.props.roomId, this.state.topic);
150-
originalTopic = this.state.topic;
146+
newState.originalTopic = this.state.topic;
151147
}
152148

153-
this.setState({
154-
originalAvatarUrl,
155-
avatarUrl,
156-
originalDisplayName,
157-
originalTopic,
158-
displayName,
159-
avatarFile,
160-
});
149+
this.setState(newState as IState);
161150
};
162151

163152
private onDisplayNameChanged = (e: React.ChangeEvent<HTMLInputElement>): void => {

0 commit comments

Comments
 (0)