diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 7e8dbeff76..b69bea9282 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -427,6 +427,11 @@ module.exports = React.createClass({ }); }, + onAvatarRemoveClick: function() { + MatrixClientPeg.get().setAvatarUrl(null); + this.setState({avatarUrl: null}); // the avatar update will complete async for us + }, + onLogoutClicked: function(ev) { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createTrackedDialog('Logout E2E Export', '', QuestionDialog, { @@ -1322,7 +1327,11 @@ module.exports = React.createClass({
-
+
+ {_t("Remove +
+
diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 42cbb90cd9..3d2dee9e64 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -129,6 +129,10 @@ module.exports = React.createClass({ }).done(); }, + onAvatarRemoveClick: function() { + MatrixClientPeg.get().sendStateEvent(this.props.room.roomId, 'm.room.avatar', {url: null}, ''); + }, + onShowRhsClick: function(ev) { dis.dispatch({ action: 'show_right_panel' }); }, @@ -268,11 +272,15 @@ module.exports = React.createClass({
+
+ {_t("Remove +
); } else if (this.props.room || (this.props.oobData && this.props.oobData.name)) { diff --git a/src/components/views/settings/ChangeAvatar.js b/src/components/views/settings/ChangeAvatar.js index b3204ab86e..a363dc2c60 100644 --- a/src/components/views/settings/ChangeAvatar.js +++ b/src/components/views/settings/ChangeAvatar.js @@ -53,6 +53,10 @@ module.exports = React.createClass({ }; }, + componentWillMount: function() { + MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents); + }, + componentWillReceiveProps: function(newProps) { if (this.avatarSet) { // don't clobber what the user has just set @@ -63,6 +67,28 @@ module.exports = React.createClass({ }); }, + componentWillUnmount: function() { + if (MatrixClientPeg.get()) { + MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents); + } + }, + + onRoomStateEvents: function(ev) { + if (!this.props.room) { + return; + } + + if (ev.getRoomId() !== this.props.room.roomId || ev.getType() !== 'm.room.avatar' + || ev.getSender() !== MatrixClientPeg.get().getUserId()) { + return; + } + + if (!ev.getContent().url) { + this.avatarSet = false; + this.setState({}); // force update + } + }, + setAvatarFromFile: function(file) { let newUrl = null; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 6f46fd3257..a167381152 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -633,6 +633,7 @@ "quote": "quote", "bullet": "bullet", "numbullet": "numbullet", + "Remove avatar": "Remove avatar", "%(severalUsers)sjoined %(repeats)s times": "%(severalUsers)sjoined %(repeats)s times", "%(oneUser)sjoined %(repeats)s times": "%(oneUser)sjoined %(repeats)s times", "%(severalUsers)sjoined": "%(severalUsers)sjoined",