mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-18 07:52:09 +03:00
Fix avatar disappearing when setting a topic (#7092)
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
07d9e93d67
commit
8c9e75b16e
1 changed files with 8 additions and 19 deletions
|
@ -121,43 +121,32 @@ export default class RoomProfileSettings extends React.Component<IProps, IState>
|
||||||
this.setState({ profileFieldsTouched: {} });
|
this.setState({ profileFieldsTouched: {} });
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
|
const newState: Partial<IState> = {};
|
||||||
let originalDisplayName: string;
|
|
||||||
let avatarUrl: string;
|
|
||||||
let originalAvatarUrl: string;
|
|
||||||
let originalTopic: string;
|
|
||||||
let avatarFile: File;
|
|
||||||
|
|
||||||
// TODO: What do we do about errors?
|
// TODO: What do we do about errors?
|
||||||
const displayName = this.state.displayName.trim();
|
const displayName = this.state.displayName.trim();
|
||||||
if (this.state.originalDisplayName !== this.state.displayName) {
|
if (this.state.originalDisplayName !== this.state.displayName) {
|
||||||
await client.setRoomName(this.props.roomId, displayName);
|
await client.setRoomName(this.props.roomId, displayName);
|
||||||
originalDisplayName = displayName;
|
newState.originalDisplayName = displayName;
|
||||||
|
newState.displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.avatarFile) {
|
if (this.state.avatarFile) {
|
||||||
const uri = await client.uploadContent(this.state.avatarFile);
|
const uri = await client.uploadContent(this.state.avatarFile);
|
||||||
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', { url: uri }, '');
|
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', { url: uri }, '');
|
||||||
avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
|
newState.avatarUrl = mediaFromMxc(uri).getSquareThumbnailHttp(96);
|
||||||
originalAvatarUrl = avatarUrl;
|
newState.originalAvatarUrl = newState.avatarUrl;
|
||||||
avatarFile = null;
|
newState.avatarFile = null;
|
||||||
} else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
|
} else if (this.state.originalAvatarUrl !== this.state.avatarUrl) {
|
||||||
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', {}, '');
|
await client.sendStateEvent(this.props.roomId, 'm.room.avatar', {}, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.state.originalTopic !== this.state.topic) {
|
if (this.state.originalTopic !== this.state.topic) {
|
||||||
await client.setRoomTopic(this.props.roomId, this.state.topic);
|
await client.setRoomTopic(this.props.roomId, this.state.topic);
|
||||||
originalTopic = this.state.topic;
|
newState.originalTopic = this.state.topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState(newState as IState);
|
||||||
originalAvatarUrl,
|
|
||||||
avatarUrl,
|
|
||||||
originalDisplayName,
|
|
||||||
originalTopic,
|
|
||||||
displayName,
|
|
||||||
avatarFile,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private onDisplayNameChanged = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
private onDisplayNameChanged = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
||||||
|
|
Loading…
Reference in a new issue