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

Commit

Permalink
Add (un)ignore button to MemberInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Ralston <travpc@gmail.com>
  • Loading branch information
turt2live committed Sep 15, 2017
1 parent 13a251e commit 3889df6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/components/views/rooms/MemberInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = withMatrixClient(React.createClass({
updating: 0,
devicesLoading: true,
devices: null,
isIgnoring: false,
};
},

Expand All @@ -81,6 +82,8 @@ module.exports = withMatrixClient(React.createClass({
cli.on("RoomState.events", this.onRoomStateEvents);
cli.on("RoomMember.name", this.onRoomMemberName);
cli.on("accountData", this.onAccountData);

this._checkIgnoreState();
},

componentDidMount: function() {
Expand Down Expand Up @@ -111,6 +114,11 @@ module.exports = withMatrixClient(React.createClass({
}
},

_checkIgnoreState: function() {
const isIgnoring = this.props.matrixClient.getIgnoredUsers().indexOf(this.props.member.userId) !== -1;
this.setState({isIgnoring: isIgnoring});
},

_disambiguateDevices: function(devices) {
var names = Object.create(null);
for (var i = 0; i < devices.length; i++) {
Expand Down Expand Up @@ -225,6 +233,18 @@ module.exports = withMatrixClient(React.createClass({
});
},

onIgnoreToggle: function() {
const ignoredUsers = this.props.matrixClient.getIgnoredUsers();
if (this.state.isIgnoring) {
const index = ignoredUsers.indexOf(this.props.member.userId);
if (index !== -1) ignoredUsers.splice(index, 1);
} else {
ignoredUsers.push(this.props.member.userId);
}

this.props.matrixClient.setIgnoredUsers(ignoredUsers).then(() => this.setState({isIgnoring: !this.state.isIgnoring}));
},

onKick: function() {
const membership = this.props.member.membership;
const kickLabel = membership === "invite" ? _t("Disinvite") : _t("Kick");
Expand Down Expand Up @@ -607,6 +627,29 @@ module.exports = withMatrixClient(React.createClass({
);
},

_renderUserOptions: function() {
// Only allow the user to ignore the user if its not ourselves
let ignoreButton = null;
if (this.props.member.userId !== this.props.matrixClient.getUserId()) {
ignoreButton = (
<AccessibleButton onClick={this.onIgnoreToggle} className="mx_MemberInfo_field">
{this.state.isIgnoring ? _t("Unignore") : _t("Ignore")}
</AccessibleButton>
);
}

if (!ignoreButton) return null;

return (
<div>
<h3>{ _t("User Options") }</h3>
<div className="mx_MemberInfo_buttons">
{ignoreButton}
</div>
</div>
);
},

render: function() {
var startChat, kickButton, banButton, muteButton, giveModButton, spinner;
if (this.props.member.userId !== this.props.matrixClient.credentials.userId) {
Expand Down Expand Up @@ -756,6 +799,8 @@ module.exports = withMatrixClient(React.createClass({
</div>
</div>

{ this._renderUserOptions() }

{ adminTools }

{ startChat }
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@
"Kicks user with given id": "Kicks user with given id",
"Labs": "Labs",
"Ignored Users": "Ignored Users",
"Ignore": "Ignore",
"Unignore": "Unignore",
"User Options": "User Options",
"You are now ignoring %(userId)s": "You are now ignoring %(userId)s",
"You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s",
"Unignored user": "Unignored user",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
"Kicks user with given id": "Kicks user with given id",
"Labs": "Labs",
"Ignored Users": "Ignored Users",
"Ignore": "Ignore",
"Unignore": "Unignore",
"User Options": "User Options",
"You are now ignoring %(userId)s": "You are now ignoring %(userId)s",
"You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s",
"Unignored user": "Unignored user",
Expand Down

0 comments on commit 3889df6

Please sign in to comment.