Add options to display/ignore usersId's
This commit is contained in:
parent
1aa16a43ee
commit
b28b94bfe7
8 changed files with 88 additions and 5 deletions
|
@ -5,12 +5,12 @@ import initMatrix from '../../client/initMatrix';
|
||||||
|
|
||||||
export function useAccountData(eventType) {
|
export function useAccountData(eventType) {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const [event, setEvent] = useState(mx.getAccountData(eventType)?.getContent());
|
const [event, setEvent] = useState(mx.getAccountData(eventType));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleChange = (mEvent) => {
|
const handleChange = (mEvent) => {
|
||||||
if (mEvent.getType() !== eventType) return;
|
if (mEvent.getType() !== eventType) return;
|
||||||
setEvent(mEvent.getContent());
|
setEvent(mEvent);
|
||||||
};
|
};
|
||||||
mx.on('accountData', handleChange);
|
mx.on('accountData', handleChange);
|
||||||
return () => {
|
return () => {
|
||||||
|
|
|
@ -53,7 +53,7 @@ export function getTypeActions(type, highlightValue = false) {
|
||||||
|
|
||||||
function useGlobalNotif() {
|
function useGlobalNotif() {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const pushRules = useAccountData('m.push_rules');
|
const pushRules = useAccountData('m.push_rules')?.getContent();
|
||||||
const underride = pushRules?.global?.underride ?? [];
|
const underride = pushRules?.global?.underride ?? [];
|
||||||
const rulesToType = {
|
const rulesToType = {
|
||||||
[DM]: notifType.ON,
|
[DM]: notifType.ON,
|
||||||
|
|
64
src/app/molecules/global-notification/IgnoreUserList.jsx
Normal file
64
src/app/molecules/global-notification/IgnoreUserList.jsx
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
import React from 'react';
|
||||||
|
import './IgnoreUserList.scss';
|
||||||
|
|
||||||
|
import initMatrix from '../../../client/initMatrix';
|
||||||
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
|
||||||
|
import Text from '../../atoms/text/Text';
|
||||||
|
import Chip from '../../atoms/chip/Chip';
|
||||||
|
import Input from '../../atoms/input/Input';
|
||||||
|
import Button from '../../atoms/button/Button';
|
||||||
|
import { MenuHeader } from '../../atoms/context-menu/ContextMenu';
|
||||||
|
import SettingTile from '../setting-tile/SettingTile';
|
||||||
|
|
||||||
|
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||||
|
|
||||||
|
import { useAccountData } from '../../hooks/useAccountData';
|
||||||
|
|
||||||
|
function IgnoreUserList() {
|
||||||
|
useAccountData('m.ignored_user_list');
|
||||||
|
const ignoredUsers = initMatrix.matrixClient.getIgnoredUsers();
|
||||||
|
|
||||||
|
const handleSubmit = (evt) => {
|
||||||
|
evt.preventDefault();
|
||||||
|
const { ignoreInput } = evt.target.elements;
|
||||||
|
const value = ignoreInput.value.trim();
|
||||||
|
const userIds = value.split(' ').filter((v) => v.match(/^@\S+:\S+$/));
|
||||||
|
if (userIds.length === 0) return;
|
||||||
|
ignoreInput.value = '';
|
||||||
|
roomActions.ignore(userIds);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ignore-user-list">
|
||||||
|
<MenuHeader>Ignored users</MenuHeader>
|
||||||
|
<SettingTile
|
||||||
|
title="Ignore userId"
|
||||||
|
content={(
|
||||||
|
<div className="ignore-user-list__users">
|
||||||
|
<Text variant="b3">Ignore userId if you do not want to see their messages.</Text>
|
||||||
|
<form onSubmit={handleSubmit}>
|
||||||
|
<Input name="ignoreInput" required />
|
||||||
|
<Button variant="primary" type="submit">Ignore</Button>
|
||||||
|
</form>
|
||||||
|
{ignoredUsers.length > 0 && (
|
||||||
|
<div>
|
||||||
|
{ignoredUsers.map((uId) => (
|
||||||
|
<Chip
|
||||||
|
iconSrc={CrossIC}
|
||||||
|
key={uId}
|
||||||
|
text={uId}
|
||||||
|
iconColor={CrossIC}
|
||||||
|
onClick={() => roomActions.unignore([uId])}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IgnoreUserList;
|
16
src/app/molecules/global-notification/IgnoreUserList.scss
Normal file
16
src/app/molecules/global-notification/IgnoreUserList.scss
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
.ignore-user-list {
|
||||||
|
&__users {
|
||||||
|
& form,
|
||||||
|
& > div:last-child {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--sp-tight);
|
||||||
|
}
|
||||||
|
|
||||||
|
& form {
|
||||||
|
margin: var(--sp-extra-tight) 0 var(--sp-normal);
|
||||||
|
.input-container {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ const KEYWORD = 'keyword';
|
||||||
|
|
||||||
function useKeywordNotif() {
|
function useKeywordNotif() {
|
||||||
const mx = initMatrix.matrixClient;
|
const mx = initMatrix.matrixClient;
|
||||||
const pushRules = useAccountData('m.push_rules');
|
const pushRules = useAccountData('m.push_rules')?.getContent();
|
||||||
const override = pushRules?.global?.override ?? [];
|
const override = pushRules?.global?.override ?? [];
|
||||||
const content = pushRules?.global?.content ?? [];
|
const content = pushRules?.global?.content ?? [];
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
& form {
|
& form {
|
||||||
margin: var(--sp-ultra-tight) 0 var(--sp-normal);
|
margin: var(--sp-extra-tight) 0 var(--sp-normal);
|
||||||
.input-container {
|
.input-container {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import ExportE2ERoomKeys from '../../molecules/import-export-e2e-room-keys/Expor
|
||||||
import { ImagePackUser, ImagePackGlobal } from '../../molecules/image-pack/ImagePack';
|
import { ImagePackUser, ImagePackGlobal } from '../../molecules/image-pack/ImagePack';
|
||||||
import GlobalNotification from '../../molecules/global-notification/GlobalNotification';
|
import GlobalNotification from '../../molecules/global-notification/GlobalNotification';
|
||||||
import KeywordNotification from '../../molecules/global-notification/KeywordNotification';
|
import KeywordNotification from '../../molecules/global-notification/KeywordNotification';
|
||||||
|
import IgnoreUserList from '../../molecules/global-notification/IgnoreUserList';
|
||||||
|
|
||||||
import ProfileEditor from '../profile-editor/ProfileEditor';
|
import ProfileEditor from '../profile-editor/ProfileEditor';
|
||||||
import CrossSigning from './CrossSigning';
|
import CrossSigning from './CrossSigning';
|
||||||
|
@ -173,6 +174,7 @@ function NotificationsSection() {
|
||||||
</div>
|
</div>
|
||||||
<GlobalNotification />
|
<GlobalNotification />
|
||||||
<KeywordNotification />
|
<KeywordNotification />
|
||||||
|
<IgnoreUserList />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
.settings-notifications,
|
.settings-notifications,
|
||||||
.global-notification,
|
.global-notification,
|
||||||
.keyword-notification,
|
.keyword-notification,
|
||||||
|
.ignore-user-list,
|
||||||
.settings-security__card,
|
.settings-security__card,
|
||||||
.settings-security .device-manage,
|
.settings-security .device-manage,
|
||||||
.settings-about__card,
|
.settings-about__card,
|
||||||
|
|
Loading…
Reference in a new issue