Add (un)ignore button to MemberInfo

Signed-off-by: Travis Ralston <travpc@gmail.com>
This commit is contained in:
Travis Ralston 2017-09-14 17:10:02 -06:00 committed by turt2live
parent 13a251e29c
commit 3889df6b08
3 changed files with 49 additions and 0 deletions

View file

@ -62,6 +62,7 @@ module.exports = withMatrixClient(React.createClass({
updating: 0, updating: 0,
devicesLoading: true, devicesLoading: true,
devices: null, devices: null,
isIgnoring: false,
}; };
}, },
@ -81,6 +82,8 @@ module.exports = withMatrixClient(React.createClass({
cli.on("RoomState.events", this.onRoomStateEvents); cli.on("RoomState.events", this.onRoomStateEvents);
cli.on("RoomMember.name", this.onRoomMemberName); cli.on("RoomMember.name", this.onRoomMemberName);
cli.on("accountData", this.onAccountData); cli.on("accountData", this.onAccountData);
this._checkIgnoreState();
}, },
componentDidMount: function() { componentDidMount: function() {
@ -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) { _disambiguateDevices: function(devices) {
var names = Object.create(null); var names = Object.create(null);
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
@ -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() { onKick: function() {
const membership = this.props.member.membership; const membership = this.props.member.membership;
const kickLabel = membership === "invite" ? _t("Disinvite") : _t("Kick"); const kickLabel = membership === "invite" ? _t("Disinvite") : _t("Kick");
@ -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() { render: function() {
var startChat, kickButton, banButton, muteButton, giveModButton, spinner; var startChat, kickButton, banButton, muteButton, giveModButton, spinner;
if (this.props.member.userId !== this.props.matrixClient.credentials.userId) { if (this.props.member.userId !== this.props.matrixClient.credentials.userId) {
@ -756,6 +799,8 @@ module.exports = withMatrixClient(React.createClass({
</div> </div>
</div> </div>
{ this._renderUserOptions() }
{ adminTools } { adminTools }
{ startChat } { startChat }

View file

@ -265,7 +265,9 @@
"Kicks user with given id": "Kicks user with given id", "Kicks user with given id": "Kicks user with given id",
"Labs": "Labs", "Labs": "Labs",
"Ignored Users": "Ignored Users", "Ignored Users": "Ignored Users",
"Ignore": "Ignore",
"Unignore": "Unignore", "Unignore": "Unignore",
"User Options": "User Options",
"You are now ignoring %(userId)s": "You are now ignoring %(userId)s", "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", "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s",
"Unignored user": "Unignored user", "Unignored user": "Unignored user",

View file

@ -232,7 +232,9 @@
"Kicks user with given id": "Kicks user with given id", "Kicks user with given id": "Kicks user with given id",
"Labs": "Labs", "Labs": "Labs",
"Ignored Users": "Ignored Users", "Ignored Users": "Ignored Users",
"Ignore": "Ignore",
"Unignore": "Unignore", "Unignore": "Unignore",
"User Options": "User Options",
"You are now ignoring %(userId)s": "You are now ignoring %(userId)s", "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", "You are no longer ignoring %(userId)s": "You are no longer ignoring %(userId)s",
"Unignored user": "Unignored user", "Unignored user": "Unignored user",