Add ignore user confirmation dialog (#6116)
Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
parent
269d1622b9
commit
43c67ce4bf
3 changed files with 85 additions and 13 deletions
|
@ -353,25 +353,42 @@ export const UserOptionsSection: React.FC<{
|
|||
});
|
||||
};
|
||||
|
||||
const unignore = useCallback(() => {
|
||||
const ignoredUsers = cli.getIgnoredUsers();
|
||||
const index = ignoredUsers.indexOf(member.userId);
|
||||
if (index !== -1) ignoredUsers.splice(index, 1);
|
||||
cli.setIgnoredUsers(ignoredUsers);
|
||||
}, [cli, member]);
|
||||
|
||||
const ignore = useCallback(async () => {
|
||||
const { finished } = Modal.createDialog(QuestionDialog, {
|
||||
title: _t("Ignore %(user)s", { user: member.name }),
|
||||
description: (
|
||||
<div>
|
||||
{_t(
|
||||
"All messages and invites from this user will be hidden. " +
|
||||
"Are you sure you want to ignore them?",
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
button: _t("Ignore"),
|
||||
});
|
||||
const [confirmed] = await finished;
|
||||
|
||||
if (confirmed) {
|
||||
const ignoredUsers = cli.getIgnoredUsers();
|
||||
ignoredUsers.push(member.userId);
|
||||
cli.setIgnoredUsers(ignoredUsers);
|
||||
}
|
||||
}, [cli, member]);
|
||||
|
||||
// Only allow the user to ignore the user if its not ourselves
|
||||
// same goes for jumping to read receipt
|
||||
if (!isMe) {
|
||||
const onIgnoreToggle = (): void => {
|
||||
const ignoredUsers = cli.getIgnoredUsers();
|
||||
if (isIgnored) {
|
||||
const index = ignoredUsers.indexOf(member.userId);
|
||||
if (index !== -1) ignoredUsers.splice(index, 1);
|
||||
} else {
|
||||
ignoredUsers.push(member.userId);
|
||||
}
|
||||
|
||||
cli.setIgnoredUsers(ignoredUsers);
|
||||
};
|
||||
|
||||
ignoreButton = (
|
||||
<AccessibleButton
|
||||
onClick={isIgnored ? unignore : ignore}
|
||||
kind="link"
|
||||
onClick={onIgnoreToggle}
|
||||
className={classNames("mx_UserInfo_field", { mx_UserInfo_destructive: !isIgnored })}
|
||||
>
|
||||
{isIgnored ? _t("Unignore") : _t("Ignore")}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue