Merge pull request #4466 from ihatetothink/unignored-in-settings
Unignored in settings
This commit is contained in:
commit
2952c37a47
1 changed files with 40 additions and 12 deletions
|
@ -25,11 +25,13 @@ import Analytics from "../../../../../Analytics";
|
||||||
import Modal from "../../../../../Modal";
|
import Modal from "../../../../../Modal";
|
||||||
import * as sdk from "../../../../..";
|
import * as sdk from "../../../../..";
|
||||||
import {sleep} from "../../../../../utils/promise";
|
import {sleep} from "../../../../../utils/promise";
|
||||||
|
import dis from "../../../../../dispatcher";
|
||||||
|
|
||||||
export class IgnoredUser extends React.Component {
|
export class IgnoredUser extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
userId: PropTypes.string.isRequired,
|
userId: PropTypes.string.isRequired,
|
||||||
onUnignored: PropTypes.func.isRequired,
|
onUnignored: PropTypes.func.isRequired,
|
||||||
|
inProgress: PropTypes.bool.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
_onUnignoreClicked = (e) => {
|
_onUnignoreClicked = (e) => {
|
||||||
|
@ -40,7 +42,7 @@ export class IgnoredUser extends React.Component {
|
||||||
const id = `mx_SecurityUserSettingsTab_ignoredUser_${this.props.userId}`;
|
const id = `mx_SecurityUserSettingsTab_ignoredUser_${this.props.userId}`;
|
||||||
return (
|
return (
|
||||||
<div className='mx_SecurityUserSettingsTab_ignoredUser'>
|
<div className='mx_SecurityUserSettingsTab_ignoredUser'>
|
||||||
<AccessibleButton onClick={this._onUnignoreClicked} kind='primary_sm' aria-describedby={id}>
|
<AccessibleButton onClick={this._onUnignoreClicked} kind='primary_sm' aria-describedby={id} disabled={this.props.inProgress}>
|
||||||
{ _t('Unignore') }
|
{ _t('Unignore') }
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
<span id={id}>{ this.props.userId }</span>
|
<span id={id}>{ this.props.userId }</span>
|
||||||
|
@ -58,9 +60,29 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(),
|
ignoredUserIds: MatrixClientPeg.get().getIgnoredUsers(),
|
||||||
|
waitingUnignored: [],
|
||||||
managingInvites: false,
|
managingInvites: false,
|
||||||
invitedRoomAmt: invitedRooms.length,
|
invitedRoomAmt: invitedRooms.length,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._onAction = this._onAction.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_onAction({action}) {
|
||||||
|
if (action === "ignore_state_changed") {
|
||||||
|
const ignoredUserIds = MatrixClientPeg.get().getIgnoredUsers();
|
||||||
|
const newWaitingUnignored = this.state.waitingUnignored.filter(e=> ignoredUserIds.includes(e));
|
||||||
|
this.setState({ignoredUserIds, waitingUnignored: newWaitingUnignored});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.dispatcherRef = dis.register(this._onAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
dis.unregister(this.dispatcherRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateBlacklistDevicesFlag = (checked) => {
|
_updateBlacklistDevicesFlag = (checked) => {
|
||||||
|
@ -86,16 +108,15 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
_onUserUnignored = async (userId) => {
|
_onUserUnignored = async (userId) => {
|
||||||
// Don't use this.state to get the ignored user list as it might be
|
const {ignoredUserIds, waitingUnignored} = this.state;
|
||||||
// ever so slightly outdated. Instead, prefer to get a fresh list and
|
const currentlyIgnoredUserIds = ignoredUserIds.filter(e => !waitingUnignored.includes(e));
|
||||||
// update that.
|
|
||||||
const ignoredUsers = MatrixClientPeg.get().getIgnoredUsers();
|
const index = currentlyIgnoredUserIds.indexOf(userId);
|
||||||
const index = ignoredUsers.indexOf(userId);
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
ignoredUsers.splice(index, 1);
|
currentlyIgnoredUserIds.splice(index, 1);
|
||||||
MatrixClientPeg.get().setIgnoredUsers(ignoredUsers);
|
this.setState(({waitingUnignored}) => ({waitingUnignored: [...waitingUnignored, userId]}));
|
||||||
|
MatrixClientPeg.get().setIgnoredUsers(currentlyIgnoredUserIds);
|
||||||
}
|
}
|
||||||
this.setState({ignoredUsers});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_getInvitedRooms = () => {
|
_getInvitedRooms = () => {
|
||||||
|
@ -201,10 +222,17 @@ export default class SecurityUserSettingsTab extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderIgnoredUsers() {
|
_renderIgnoredUsers() {
|
||||||
if (!this.state.ignoredUserIds || this.state.ignoredUserIds.length === 0) return null;
|
const {waitingUnignored, ignoredUserIds} = this.state;
|
||||||
|
|
||||||
const userIds = this.state.ignoredUserIds
|
if (!ignoredUserIds || ignoredUserIds.length === 0) return null;
|
||||||
.map((u) => <IgnoredUser userId={u} onUnignored={this._onUserUnignored} key={u} />);
|
|
||||||
|
const userIds = ignoredUserIds
|
||||||
|
.map((u) => <IgnoredUser
|
||||||
|
userId={u}
|
||||||
|
onUnignored={this._onUserUnignored}
|
||||||
|
key={u}
|
||||||
|
inProgress={waitingUnignored.includes(u)}
|
||||||
|
/>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='mx_SettingsTab_section'>
|
<div className='mx_SettingsTab_section'>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue