Manage ignored users (#814)

* Add options to display/ignore usersId's

* Update string

* Hide search icon in encrypted rooms (#763)

* Fix styles
This commit is contained in:
Ajay Bura 2022-09-05 08:30:45 +05:30 committed by GitHub
parent 1aa16a43ee
commit 8583ab19f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 9 deletions

View file

@ -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 () => {

View file

@ -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,

View 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 user"
content={(
<div className="ignore-user-list__users">
<Text variant="b3">Ignore userId if you do not want to receive their messages or invites.</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;

View file

@ -0,0 +1,17 @@
.ignore-user-list {
&__users {
& form,
& > div:last-child {
display: flex;
flex-wrap: wrap;
gap: var(--sp-tight);
}
& form {
margin: var(--sp-extra-tight) 0 var(--sp-normal);
.input-container {
flex-grow: 1;
}
}
}
}

View file

@ -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 ?? [];

View file

@ -3,11 +3,12 @@
& form, & form,
& > div:last-child { & > div:last-child {
display: flex; display: flex;
flex-wrap: wrap;
gap: var(--sp-tight); gap: var(--sp-tight);
} }
& 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;
} }

View file

@ -33,9 +33,10 @@ function RoomViewHeader({ roomId }) {
const [, forceUpdate] = useForceUpdate(); const [, forceUpdate] = useForceUpdate();
const mx = initMatrix.matrixClient; const mx = initMatrix.matrixClient;
const isDM = initMatrix.roomList.directs.has(roomId); const isDM = initMatrix.roomList.directs.has(roomId);
let avatarSrc = mx.getRoom(roomId).getAvatarUrl(mx.baseUrl, 36, 36, 'crop'); const room = mx.getRoom(roomId);
avatarSrc = isDM ? mx.getRoom(roomId).getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 36, 36, 'crop') : avatarSrc; let avatarSrc = room.getAvatarUrl(mx.baseUrl, 36, 36, 'crop');
const roomName = mx.getRoom(roomId).name; avatarSrc = isDM ? room.getAvatarFallbackMember()?.getAvatarUrl(mx.baseUrl, 36, 36, 'crop') : avatarSrc;
const roomName = room.name;
const roomHeaderBtnRef = useRef(null); const roomHeaderBtnRef = useRef(null);
useEffect(() => { useEffect(() => {
@ -93,7 +94,7 @@ function RoomViewHeader({ roomId }) {
</TitleWrapper> </TitleWrapper>
<RawIcon src={ChevronBottomIC} /> <RawIcon src={ChevronBottomIC} />
</button> </button>
<IconButton onClick={() => toggleRoomSettings(tabText.SEARCH)} tooltip="Search" src={SearchIC} /> {mx.isRoomEncrypted(roomId) === false && <IconButton onClick={() => toggleRoomSettings(tabText.SEARCH)} tooltip="Search" src={SearchIC} />}
<IconButton className="room-header__drawer-btn" onClick={togglePeopleDrawer} tooltip="People" src={UserIC} /> <IconButton className="room-header__drawer-btn" onClick={togglePeopleDrawer} tooltip="People" src={UserIC} />
<IconButton className="room-header__members-btn" onClick={() => toggleRoomSettings(tabText.MEMBERS)} tooltip="Members" src={UserIC} /> <IconButton className="room-header__members-btn" onClick={() => toggleRoomSettings(tabText.MEMBERS)} tooltip="Members" src={UserIC} />
<IconButton <IconButton

View file

@ -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 />
</> </>
); );
} }

View file

@ -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,