From b28b94bfe78e2a04cbea9c3f34bdc4069e413779 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sun, 4 Sep 2022 22:21:54 +0530 Subject: [PATCH] Add options to display/ignore usersId's --- src/app/hooks/useAccountData.js | 4 +- .../GlobalNotification.jsx | 2 +- .../global-notification/IgnoreUserList.jsx | 64 +++++++++++++++++++ .../global-notification/IgnoreUserList.scss | 16 +++++ .../KeywordNotification.jsx | 2 +- .../KeywordNotification.scss | 2 +- src/app/organisms/settings/Settings.jsx | 2 + src/app/organisms/settings/Settings.scss | 1 + 8 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 src/app/molecules/global-notification/IgnoreUserList.jsx create mode 100644 src/app/molecules/global-notification/IgnoreUserList.scss diff --git a/src/app/hooks/useAccountData.js b/src/app/hooks/useAccountData.js index 01c973e7..ed654d97 100644 --- a/src/app/hooks/useAccountData.js +++ b/src/app/hooks/useAccountData.js @@ -5,12 +5,12 @@ import initMatrix from '../../client/initMatrix'; export function useAccountData(eventType) { const mx = initMatrix.matrixClient; - const [event, setEvent] = useState(mx.getAccountData(eventType)?.getContent()); + const [event, setEvent] = useState(mx.getAccountData(eventType)); useEffect(() => { const handleChange = (mEvent) => { if (mEvent.getType() !== eventType) return; - setEvent(mEvent.getContent()); + setEvent(mEvent); }; mx.on('accountData', handleChange); return () => { diff --git a/src/app/molecules/global-notification/GlobalNotification.jsx b/src/app/molecules/global-notification/GlobalNotification.jsx index a28687eb..865582ce 100644 --- a/src/app/molecules/global-notification/GlobalNotification.jsx +++ b/src/app/molecules/global-notification/GlobalNotification.jsx @@ -53,7 +53,7 @@ export function getTypeActions(type, highlightValue = false) { function useGlobalNotif() { const mx = initMatrix.matrixClient; - const pushRules = useAccountData('m.push_rules'); + const pushRules = useAccountData('m.push_rules')?.getContent(); const underride = pushRules?.global?.underride ?? []; const rulesToType = { [DM]: notifType.ON, diff --git a/src/app/molecules/global-notification/IgnoreUserList.jsx b/src/app/molecules/global-notification/IgnoreUserList.jsx new file mode 100644 index 00000000..d23a6265 --- /dev/null +++ b/src/app/molecules/global-notification/IgnoreUserList.jsx @@ -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 ( +