mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-17 20:50:29 +03:00
handle error in loading screen (#1823)
* handle client boot error in loading screen * use sync state hook in client root * add loading screen options * removed extra condition in loading finish * add sync connection status bar
This commit is contained in:
parent
e046c59f7c
commit
e2228a18c1
62 changed files with 609 additions and 510 deletions
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './CreateRoom.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import { openReusableContextMenu } from '../../../client/action/navigation';
|
||||
|
|
@ -32,6 +31,7 @@ import SpaceGlobeIC from '../../../../public/res/ic/outlined/space-globe.svg';
|
|||
import ChevronBottomIC from '../../../../public/res/ic/outlined/chevron-bottom.svg';
|
||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function CreateRoomContent({ isSpace, parentId, onRequestClose }) {
|
||||
const [joinRule, setJoinRule] = useState(parentId ? 'restricted' : 'invite');
|
||||
|
|
@ -46,7 +46,7 @@ function CreateRoomContent({ isSpace, parentId, onRequestClose }) {
|
|||
|
||||
const addressRef = useRef(null);
|
||||
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const userHs = getIdServer(mx.getUserId());
|
||||
|
||||
const handleSubmit = async (evt) => {
|
||||
|
|
@ -69,7 +69,7 @@ function CreateRoomContent({ isSpace, parentId, onRequestClose }) {
|
|||
const powerLevel = roleIndex === 1 ? 101 : undefined;
|
||||
|
||||
try {
|
||||
const data = await roomActions.createRoom({
|
||||
const data = await roomActions.createRoom(mx, {
|
||||
name,
|
||||
topic,
|
||||
joinRule,
|
||||
|
|
@ -113,7 +113,7 @@ function CreateRoomContent({ isSpace, parentId, onRequestClose }) {
|
|||
if (roomAlias === '') return;
|
||||
const roomAddress = `#${roomAlias}:${userHs}`;
|
||||
|
||||
if (await isRoomAliasAvailable(roomAddress)) {
|
||||
if (await isRoomAliasAvailable(mx, roomAddress)) {
|
||||
setIsValidAddress(true);
|
||||
} else {
|
||||
setIsValidAddress(false);
|
||||
|
|
@ -278,7 +278,7 @@ function useWindowToggle() {
|
|||
function CreateRoom() {
|
||||
const [create, onRequestClose] = useWindowToggle();
|
||||
const { isSpace, parentId } = create ?? {};
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(parentId);
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './EmojiVerification.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import { hasPrivateKey } from '../../../client/state/secretStorageKeys';
|
||||
|
|
@ -18,23 +17,24 @@ import Dialog from '../../molecules/dialog/Dialog';
|
|||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { accessSecretStorage } from '../settings/SecretStorageAccess';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function EmojiVerificationContent({ data, requestClose }) {
|
||||
const [sas, setSas] = useState(null);
|
||||
const [process, setProcess] = useState(false);
|
||||
const { request, targetDevice } = data;
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const mountStore = useStore();
|
||||
const beginStore = useStore();
|
||||
|
||||
const beginVerification = async () => {
|
||||
if (
|
||||
isCrossVerified(mx.deviceId) &&
|
||||
isCrossVerified(mx, mx.deviceId) &&
|
||||
(mx.getCrossSigningId() === null ||
|
||||
(await mx.crypto.crossSigningInfo.isStoredInKeyCache('self_signing')) === false)
|
||||
) {
|
||||
if (!hasPrivateKey(getDefaultSSKey())) {
|
||||
const keyData = await accessSecretStorage('Emoji verification');
|
||||
if (!hasPrivateKey(getDefaultSSKey(mx))) {
|
||||
const keyData = await accessSecretStorage(mx, 'Emoji verification');
|
||||
if (!keyData) {
|
||||
request.cancel();
|
||||
return;
|
||||
|
|
@ -158,7 +158,7 @@ EmojiVerificationContent.propTypes = {
|
|||
|
||||
function useVisibilityToggle() {
|
||||
const [data, setData] = useState(null);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
|
||||
useEffect(() => {
|
||||
const handleOpen = (request, targetDevice) => {
|
||||
|
|
@ -170,7 +170,7 @@ function useVisibilityToggle() {
|
|||
navigation.removeListener(cons.events.navigation.EMOJI_VERIFICATION_OPENED, handleOpen);
|
||||
mx.removeListener('crypto.verification.request', handleOpen);
|
||||
};
|
||||
}, []);
|
||||
}, [mx]);
|
||||
|
||||
const requestClose = () => setData(null);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './InviteUser.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import * as roomActions from '../../../client/action/room';
|
||||
import { hasDevices } from '../../../util/matrixUtil';
|
||||
|
||||
|
|
@ -18,6 +17,7 @@ import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
|||
import UserIC from '../../../../public/res/ic/outlined/user.svg';
|
||||
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
||||
import { getDMRoomFor } from '../../utils/matrix';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function InviteUser({ isOpen, roomId, searchTerm, onRequestClose }) {
|
||||
const [isSearching, updateIsSearching] = useState(false);
|
||||
|
|
@ -34,7 +34,7 @@ function InviteUser({ isOpen, roomId, searchTerm, onRequestClose }) {
|
|||
|
||||
const usernameRef = useRef(null);
|
||||
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
|
||||
function getMapCopy(myMap) {
|
||||
|
|
@ -118,7 +118,7 @@ function InviteUser({ isOpen, roomId, searchTerm, onRequestClose }) {
|
|||
procUserError.delete(userId);
|
||||
updateUserProcError(getMapCopy(procUserError));
|
||||
|
||||
const result = await roomActions.createDM(userId, await hasDevices(userId));
|
||||
const result = await roomActions.createDM(mx, userId, await hasDevices(mx, userId));
|
||||
roomIdToUserId.set(result.room_id, userId);
|
||||
updateRoomIdToUserId(getMapCopy(roomIdToUserId));
|
||||
onDMCreated(result.room_id);
|
||||
|
|
@ -137,7 +137,7 @@ function InviteUser({ isOpen, roomId, searchTerm, onRequestClose }) {
|
|||
procUserError.delete(userId);
|
||||
updateUserProcError(getMapCopy(procUserError));
|
||||
|
||||
await roomActions.invite(roomId, userId);
|
||||
await mx.invite(roomId, userId);
|
||||
|
||||
invitedUserIds.add(userId);
|
||||
updateInvitedUserIds(new Set(Array.from(invitedUserIds)));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './JoinAlias.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import { join } from '../../../client/action/room';
|
||||
|
|
@ -18,6 +17,7 @@ import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
|||
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
const ALIAS_OR_ID_REG = /^[#|!].+:.+\..+$/;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ function JoinAliasContent({ term, requestClose }) {
|
|||
const [process, setProcess] = useState(false);
|
||||
const [error, setError] = useState(undefined);
|
||||
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const mountStore = useStore();
|
||||
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
|
|
@ -63,7 +63,7 @@ function JoinAliasContent({ term, requestClose }) {
|
|||
}
|
||||
}
|
||||
try {
|
||||
const roomId = await join(alias, false, via);
|
||||
const roomId = await join(mx, alias, false, via);
|
||||
if (!mountStore.getItem()) return;
|
||||
openRoom(roomId);
|
||||
} catch {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import colorMXID from '../../../util/colorMXID';
|
||||
|
||||
import Text from '../../atoms/text/Text';
|
||||
|
|
@ -14,10 +13,11 @@ import PencilIC from '../../../../public/res/ic/outlined/pencil.svg';
|
|||
import { confirmDialog } from '../../molecules/confirm-dialog/ConfirmDialog';
|
||||
|
||||
import './ProfileEditor.scss';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function ProfileEditor({ userId }) {
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const user = mx.getUser(mx.getUserId());
|
||||
|
||||
const displayNameRef = useRef(null);
|
||||
|
|
@ -37,7 +37,7 @@ function ProfileEditor({ userId }) {
|
|||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [userId]);
|
||||
}, [mx, userId]);
|
||||
|
||||
const handleAvatarUpload = async (url) => {
|
||||
if (url === null) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './ProfileViewer.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import { openReusableContextMenu } from '../../../client/action/navigation';
|
||||
|
|
@ -36,9 +35,10 @@ import { useForceUpdate } from '../../hooks/useForceUpdate';
|
|||
import { confirmDialog } from '../../molecules/confirm-dialog/ConfirmDialog';
|
||||
import { useRoomNavigate } from '../../hooks/useRoomNavigate';
|
||||
import { getDMRoomFor } from '../../utils/matrix';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function ModerationTools({ roomId, userId }) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
const roomMember = room.getMember(userId);
|
||||
|
||||
|
|
@ -56,13 +56,13 @@ function ModerationTools({ roomId, userId }) {
|
|||
const handleKick = (e) => {
|
||||
e.preventDefault();
|
||||
const kickReason = e.target.elements['kick-reason']?.value.trim();
|
||||
roomActions.kick(roomId, userId, kickReason !== '' ? kickReason : undefined);
|
||||
mx.kick(roomId, userId, kickReason !== '' ? kickReason : undefined);
|
||||
};
|
||||
|
||||
const handleBan = (e) => {
|
||||
e.preventDefault();
|
||||
const banReason = e.target.elements['ban-reason']?.value.trim();
|
||||
roomActions.ban(roomId, userId, banReason !== '' ? banReason : undefined);
|
||||
mx.ban(roomId, userId, banReason !== '' ? banReason : undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -90,7 +90,7 @@ ModerationTools.propTypes = {
|
|||
function SessionInfo({ userId }) {
|
||||
const [devices, setDevices] = useState(null);
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
|
||||
useEffect(() => {
|
||||
let isUnmounted = false;
|
||||
|
|
@ -111,7 +111,7 @@ function SessionInfo({ userId }) {
|
|||
return () => {
|
||||
isUnmounted = true;
|
||||
};
|
||||
}, [userId]);
|
||||
}, [mx, userId]);
|
||||
|
||||
function renderSessionChips() {
|
||||
if (!isVisible) return null;
|
||||
|
|
@ -139,7 +139,7 @@ function SessionInfo({ userId }) {
|
|||
>
|
||||
<Text variant="b2">{`View ${
|
||||
devices?.length > 0
|
||||
? `${devices.length} ${devices.length == 1 ? 'session' : 'sessions'}`
|
||||
? `${devices.length} ${devices.length === 1 ? 'session' : 'sessions'}`
|
||||
: 'sessions'
|
||||
}`}</Text>
|
||||
</MenuItem>
|
||||
|
|
@ -155,10 +155,10 @@ SessionInfo.propTypes = {
|
|||
function ProfileFooter({ roomId, userId, onRequestClose }) {
|
||||
const [isCreatingDM, setIsCreatingDM] = useState(false);
|
||||
const [isIgnoring, setIsIgnoring] = useState(false);
|
||||
const [isUserIgnored, setIsUserIgnored] = useState(initMatrix.matrixClient.isUserIgnored(userId));
|
||||
const mx = useMatrixClient();
|
||||
const [isUserIgnored, setIsUserIgnored] = useState(mx.isUserIgnored(userId));
|
||||
|
||||
const isMountedRef = useRef(true);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const { navigateRoom } = useRoomNavigate();
|
||||
const room = mx.getRoom(roomId);
|
||||
const member = room.getMember(userId);
|
||||
|
|
@ -182,10 +182,10 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
setIsUserIgnored(initMatrix.matrixClient.isUserIgnored(userId));
|
||||
setIsUserIgnored(mx.isUserIgnored(userId));
|
||||
setIsIgnoring(false);
|
||||
setIsInviting(false);
|
||||
}, [userId]);
|
||||
}, [mx, userId]);
|
||||
|
||||
const openDM = async () => {
|
||||
// Check and open if user already have a DM with userId.
|
||||
|
|
@ -199,7 +199,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
// Create new DM
|
||||
try {
|
||||
setIsCreatingDM(true);
|
||||
const result = await roomActions.createDM(userId, await hasDevices(userId));
|
||||
const result = await roomActions.createDM(mx, userId, await hasDevices(mx, userId));
|
||||
onCreated(result.room_id);
|
||||
} catch {
|
||||
if (isMountedRef.current === false) return;
|
||||
|
|
@ -213,9 +213,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
try {
|
||||
setIsIgnoring(true);
|
||||
if (isIgnored) {
|
||||
await roomActions.unignore([userId]);
|
||||
await roomActions.unignore(mx, [userId]);
|
||||
} else {
|
||||
await roomActions.ignore([userId]);
|
||||
await roomActions.ignore(mx, [userId]);
|
||||
}
|
||||
|
||||
if (isMountedRef.current === false) return;
|
||||
|
|
@ -230,9 +230,9 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
try {
|
||||
setIsInviting(true);
|
||||
let isInviteSent = false;
|
||||
if (isInvited) await roomActions.kick(roomId, userId);
|
||||
if (isInvited) await mx.kick(roomId, userId);
|
||||
else {
|
||||
await roomActions.invite(roomId, userId);
|
||||
await mx.invite(roomId, userId);
|
||||
isInviteSent = true;
|
||||
}
|
||||
if (isMountedRef.current === false) return;
|
||||
|
|
@ -249,7 +249,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
|||
{isCreatingDM ? 'Creating room...' : 'Message'}
|
||||
</Button>
|
||||
{isBanned && canIKick && (
|
||||
<Button variant="positive" onClick={() => roomActions.unban(roomId, userId)}>
|
||||
<Button variant="positive" onClick={() => mx.unban(roomId, userId)}>
|
||||
Unban
|
||||
</Button>
|
||||
)}
|
||||
|
|
@ -306,7 +306,7 @@ function useToggleDialog() {
|
|||
}
|
||||
|
||||
function useRerenderOnProfileChange(roomId, userId) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const [, forceUpdate] = useForceUpdate();
|
||||
useEffect(() => {
|
||||
const handleProfileChange = (mEvent, member) => {
|
||||
|
|
@ -323,19 +323,19 @@ function useRerenderOnProfileChange(roomId, userId) {
|
|||
mx.removeListener('RoomMember.powerLevel', handleProfileChange);
|
||||
mx.removeListener('RoomMember.membership', handleProfileChange);
|
||||
};
|
||||
}, [roomId, userId]);
|
||||
}, [mx, roomId, userId]);
|
||||
}
|
||||
|
||||
function ProfileViewer() {
|
||||
const [isOpen, roomId, userId, closeDialog, handleAfterClose] = useToggleDialog();
|
||||
useRerenderOnProfileChange(roomId, userId);
|
||||
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
const renderProfile = () => {
|
||||
const roomMember = room.getMember(userId);
|
||||
const username = roomMember ? getUsernameOfRoomMember(roomMember) : getUsername(userId);
|
||||
const username = roomMember ? getUsernameOfRoomMember(roomMember) : getUsername(mx, userId);
|
||||
const avatarMxc = roomMember?.getMxcAvatarUrl?.() || mx.getUser(userId)?.avatarUrl;
|
||||
const avatarUrl =
|
||||
avatarMxc && avatarMxc !== 'null' ? mx.mxcUrlToHttp(avatarMxc, 80, 80, 'crop') : null;
|
||||
|
|
@ -364,9 +364,9 @@ function ProfileViewer() {
|
|||
'caution'
|
||||
);
|
||||
if (!isConfirmed) return;
|
||||
roomActions.setPowerLevel(roomId, userId, newPowerLevel);
|
||||
roomActions.setPowerLevel(mx, roomId, userId, newPowerLevel);
|
||||
} else {
|
||||
roomActions.setPowerLevel(roomId, userId, newPowerLevel);
|
||||
roomActions.setPowerLevel(mx, roomId, userId, newPowerLevel);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './RoomSettings.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
|
||||
|
|
@ -30,6 +29,7 @@ import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
|||
import { confirmDialog } from '../../molecules/confirm-dialog/ConfirmDialog';
|
||||
import PopupWindow from '../../molecules/popup-window/PopupWindow';
|
||||
import IconButton from '../../atoms/button/IconButton';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
const tabText = {
|
||||
GENERAL: 'General',
|
||||
|
|
@ -68,7 +68,7 @@ const tabItems = [
|
|||
];
|
||||
|
||||
function GeneralSettings({ roomId }) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
return (
|
||||
|
|
@ -155,7 +155,8 @@ function RoomSettings() {
|
|||
const [window, requestClose] = useWindowToggle(setSelectedTab);
|
||||
const isOpen = window !== null;
|
||||
const roomId = window?.roomId;
|
||||
const room = initMatrix.matrixClient.getRoom(roomId);
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
const handleTabChange = (tabItem) => {
|
||||
setSelectedTab(tabItem);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@ import React, { useState, useEffect, useRef, useCallback } from 'react';
|
|||
import { useAtomValue } from 'jotai';
|
||||
import './Search.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import AsyncSearch from '../../../util/AsyncSearch';
|
||||
import { joinRuleToIconSrc } from '../../../util/matrixUtil';
|
||||
import { roomIdByActivity } from '../../../util/sort';
|
||||
|
||||
import Text from '../../atoms/text/Text';
|
||||
import RawIcon from '../../atoms/system-icons/RawIcon';
|
||||
|
|
@ -27,6 +25,8 @@ import { allRoomsAtom } from '../../state/room-list/roomList';
|
|||
import { mDirectAtom } from '../../state/mDirectList';
|
||||
import { useKeyDown } from '../../hooks/useKeyDown';
|
||||
import { openSearch } from '../../../client/action/navigation';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { factoryRoomIdByActivity } from '../../utils/sort';
|
||||
|
||||
function useVisiblityToggle(setResult) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
|
@ -77,9 +77,7 @@ function useVisiblityToggle(setResult) {
|
|||
return [isOpen, requestClose];
|
||||
}
|
||||
|
||||
function mapRoomIds(roomIds, directs, roomIdToParents) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
|
||||
function mapRoomIds(mx, roomIds, directs, roomIdToParents) {
|
||||
return roomIds.map((roomId) => {
|
||||
const room = mx.getRoom(roomId);
|
||||
const parentSet = roomIdToParents.get(roomId);
|
||||
|
|
@ -107,7 +105,7 @@ function Search() {
|
|||
const [asyncSearch] = useState(new AsyncSearch());
|
||||
const [isOpen, requestClose] = useVisiblityToggle(setResult);
|
||||
const searchRef = useRef(null);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const { navigateRoom, navigateSpace } = useRoomNavigate();
|
||||
const mDirects = useAtomValue(mDirectAtom);
|
||||
const spaces = useSpaces(mx, allRoomsAtom);
|
||||
|
|
@ -141,8 +139,8 @@ function Search() {
|
|||
ids = [...rooms].concat([...directs], [...spaces]);
|
||||
}
|
||||
|
||||
ids.sort(roomIdByActivity);
|
||||
const mappedIds = mapRoomIds(ids, directs, roomToParents);
|
||||
ids.sort(factoryRoomIdByActivity(mx));
|
||||
const mappedIds = mapRoomIds(mx, ids, directs, roomToParents);
|
||||
asyncSearch.setup(mappedIds, { keys: 'name', isContain: true, limit: 20 });
|
||||
if (prefix) handleSearchResults(mappedIds, prefix);
|
||||
else asyncSearch.search(term);
|
||||
|
|
@ -150,7 +148,7 @@ function Search() {
|
|||
|
||||
const loadRecentRooms = () => {
|
||||
const recentRooms = [];
|
||||
handleSearchResults(mapRoomIds(recentRooms, directs, roomToParents).reverse());
|
||||
handleSearchResults(mapRoomIds(mx, recentRooms, directs, roomToParents).reverse());
|
||||
};
|
||||
|
||||
const handleAfterOpen = () => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './AuthRequest.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { openReusableDialog } from '../../../client/action/navigation';
|
||||
|
||||
import Text from '../../atoms/text/Text';
|
||||
|
|
@ -11,6 +10,7 @@ import Input from '../../atoms/input/Input';
|
|||
import Spinner from '../../atoms/spinner/Spinner';
|
||||
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { getSecret } from '../../../client/state/auth';
|
||||
|
||||
let lastUsedPassword;
|
||||
const getAuthId = (password) => ({
|
||||
|
|
@ -18,7 +18,7 @@ const getAuthId = (password) => ({
|
|||
password,
|
||||
identifier: {
|
||||
type: 'm.id.user',
|
||||
user: initMatrix.matrixClient.getUserId(),
|
||||
user: getSecret().userId,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import './CrossSigning.scss';
|
|||
import FileSaver from 'file-saver';
|
||||
import { Formik } from 'formik';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { openReusableDialog } from '../../../client/action/navigation';
|
||||
import { copyToClipboard } from '../../../util/common';
|
||||
import { clearSecretStorageKeys } from '../../../client/state/secretStorageKeys';
|
||||
|
|
@ -17,6 +16,7 @@ import SettingTile from '../../molecules/setting-tile/SettingTile';
|
|||
|
||||
import { authRequest } from './AuthRequest';
|
||||
import { useCrossSigningStatus } from '../../hooks/useCrossSigningStatus';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
const failedDialog = () => {
|
||||
const renderFailure = (requestClose) => (
|
||||
|
|
@ -73,9 +73,9 @@ const securityKeyDialog = (key) => {
|
|||
function CrossSigningSetup() {
|
||||
const initialValues = { phrase: '', confirmPhrase: '' };
|
||||
const [genWithPhrase, setGenWithPhrase] = useState(undefined);
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const setup = async (securityPhrase = undefined) => {
|
||||
const mx = initMatrix.matrixClient;
|
||||
setGenWithPhrase(typeof securityPhrase === 'string');
|
||||
const recoveryKey = await mx.createRecoveryKeyFromPassphrase(securityPhrase);
|
||||
clearSecretStorageKeys();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import './DeviceManage.scss';
|
||||
import dateFormat from 'dateformat';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { isCrossVerified } from '../../../util/matrixUtil';
|
||||
import { openReusableDialog, openEmojiVerification } from '../../../client/action/navigation';
|
||||
|
||||
|
|
@ -26,6 +25,7 @@ import { useStore } from '../../hooks/useStore';
|
|||
import { useDeviceList } from '../../hooks/useDeviceList';
|
||||
import { useCrossSigningStatus } from '../../hooks/useCrossSigningStatus';
|
||||
import { accessSecretStorage } from './SecretStorageAccess';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
const promptDeviceName = async (deviceName) => new Promise((resolve) => {
|
||||
let isCompleted = false;
|
||||
|
|
@ -63,14 +63,14 @@ const promptDeviceName = async (deviceName) => new Promise((resolve) => {
|
|||
|
||||
function DeviceManage() {
|
||||
const TRUNCATED_COUNT = 4;
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const isCSEnabled = useCrossSigningStatus();
|
||||
const deviceList = useDeviceList();
|
||||
const [processing, setProcessing] = useState([]);
|
||||
const [truncated, setTruncated] = useState(true);
|
||||
const mountStore = useStore();
|
||||
mountStore.setItem(true);
|
||||
const isMeVerified = isCrossVerified(mx.deviceId);
|
||||
const isMeVerified = isCrossVerified(mx, mx.deviceId);
|
||||
|
||||
useEffect(() => {
|
||||
setProcessing([]);
|
||||
|
|
@ -130,7 +130,7 @@ function DeviceManage() {
|
|||
};
|
||||
|
||||
const verifyWithKey = async (device) => {
|
||||
const keyData = await accessSecretStorage('Session verification');
|
||||
const keyData = await accessSecretStorage(mx, 'Session verification');
|
||||
if (!keyData) return;
|
||||
addToProcessing(device);
|
||||
await mx.checkOwnCrossSigningTrust();
|
||||
|
|
@ -191,7 +191,7 @@ function DeviceManage() {
|
|||
)}
|
||||
{isCurrentDevice && (
|
||||
<Text style={{ marginTop: 'var(--sp-ultra-tight)' }} variant="b3">
|
||||
{`Session Key: ${initMatrix.matrixClient.getDeviceEd25519Key().match(/.{1,4}/g).join(' ')}`}
|
||||
{`Session Key: ${mx.getDeviceEd25519Key().match(/.{1,4}/g).join(' ')}`}
|
||||
</Text>
|
||||
)}
|
||||
</>
|
||||
|
|
@ -204,7 +204,7 @@ function DeviceManage() {
|
|||
const verified = [];
|
||||
const noEncryption = [];
|
||||
deviceList.sort((a, b) => b.last_seen_ts - a.last_seen_ts).forEach((device) => {
|
||||
const isVerified = isCrossVerified(device.device_id);
|
||||
const isVerified = isCrossVerified(mx, device.device_id);
|
||||
if (isVerified === true) {
|
||||
verified.push(device);
|
||||
} else if (isVerified === false) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './KeyBackup.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { openReusableDialog } from '../../../client/action/navigation';
|
||||
import { deletePrivateKey } from '../../../client/state/secretStorageKeys';
|
||||
|
||||
|
|
@ -22,10 +21,11 @@ import DownloadIC from '../../../../public/res/ic/outlined/download.svg';
|
|||
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { useCrossSigningStatus } from '../../hooks/useCrossSigningStatus';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function CreateKeyBackupDialog({ keyData }) {
|
||||
const [done, setDone] = useState(false);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const mountStore = useStore();
|
||||
|
||||
const doBackup = async () => {
|
||||
|
|
@ -80,7 +80,7 @@ CreateKeyBackupDialog.propTypes = {
|
|||
|
||||
function RestoreKeyBackupDialog({ keyData }) {
|
||||
const [status, setStatus] = useState(false);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const mountStore = useStore();
|
||||
|
||||
const restoreBackup = async () => {
|
||||
|
|
@ -150,7 +150,7 @@ RestoreKeyBackupDialog.propTypes = {
|
|||
|
||||
function DeleteKeyBackupDialog({ requestClose }) {
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const mountStore = useStore();
|
||||
|
||||
const deleteBackup = async () => {
|
||||
|
|
@ -187,7 +187,7 @@ DeleteKeyBackupDialog.propTypes = {
|
|||
};
|
||||
|
||||
function KeyBackup() {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const isCSEnabled = useCrossSigningStatus();
|
||||
const [keyBackup, setKeyBackup] = useState(undefined);
|
||||
const mountStore = useStore();
|
||||
|
|
@ -215,7 +215,7 @@ function KeyBackup() {
|
|||
}, [isCSEnabled]);
|
||||
|
||||
const openCreateKeyBackup = async () => {
|
||||
const keyData = await accessSecretStorage('Create Key Backup');
|
||||
const keyData = await accessSecretStorage(mx, 'Create Key Backup');
|
||||
if (keyData === null) return;
|
||||
|
||||
openReusableDialog(
|
||||
|
|
@ -228,7 +228,7 @@ function KeyBackup() {
|
|||
};
|
||||
|
||||
const openRestoreKeyBackup = async () => {
|
||||
const keyData = await accessSecretStorage('Restore Key Backup');
|
||||
const keyData = await accessSecretStorage(mx, 'Restore Key Backup');
|
||||
if (keyData === null) return;
|
||||
|
||||
openReusableDialog(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
|
|||
import './SecretStorageAccess.scss';
|
||||
import { deriveKey } from 'matrix-js-sdk/lib/crypto/key_passphrase';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { openReusableDialog } from '../../../client/action/navigation';
|
||||
import { getDefaultSSKey, getSSKeyInfo } from '../../../util/matrixUtil';
|
||||
import { storePrivateKey, hasPrivateKey, getPrivateKey } from '../../../client/state/secretStorageKeys';
|
||||
|
|
@ -14,11 +13,12 @@ import Input from '../../atoms/input/Input';
|
|||
import Spinner from '../../atoms/spinner/Spinner';
|
||||
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function SecretStorageAccess({ onComplete }) {
|
||||
const mx = initMatrix.matrixClient;
|
||||
const sSKeyId = getDefaultSSKey();
|
||||
const sSKeyInfo = getSSKeyInfo(sSKeyId);
|
||||
const mx = useMatrixClient();
|
||||
const sSKeyId = getDefaultSSKey(mx);
|
||||
const sSKeyInfo = getSSKeyInfo(mx, sSKeyId);
|
||||
const isPassphrase = !!sSKeyInfo.passphrase;
|
||||
const [withPhrase, setWithPhrase] = useState(isPassphrase);
|
||||
const [process, setProcess] = useState(false);
|
||||
|
|
@ -98,12 +98,13 @@ SecretStorageAccess.propTypes = {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {MatrixClient} mx Matrix client
|
||||
* @param {string} title Title of secret storage access dialog
|
||||
* @returns {Promise<keyData | null>} resolve to keyData or null
|
||||
*/
|
||||
export const accessSecretStorage = (title) => new Promise((resolve) => {
|
||||
export const accessSecretStorage = (mx, title) => new Promise((resolve) => {
|
||||
let isCompleted = false;
|
||||
const defaultSSKey = getDefaultSSKey();
|
||||
const defaultSSKey = getDefaultSSKey(mx);
|
||||
if (hasPrivateKey(defaultSSKey)) {
|
||||
resolve({ keyId: defaultSSKey, privateKey: getPrivateKey(defaultSSKey) });
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import './Settings.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import { clearCacheAndReload, logoutClient } from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import settings from '../../../client/state/settings';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
|
|
@ -47,6 +47,7 @@ import { useSetting } from '../../state/hooks/settings';
|
|||
import { settingsAtom } from '../../state/settings';
|
||||
import { isMacOS } from '../../utils/user-agent';
|
||||
import { KeySymbol } from '../../utils/key-symbol';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
|
||||
function AppearanceSection() {
|
||||
const [, updateState] = useState({});
|
||||
|
|
@ -332,6 +333,8 @@ function SecuritySection() {
|
|||
}
|
||||
|
||||
function AboutSection() {
|
||||
const mx = useMatrixClient();
|
||||
|
||||
return (
|
||||
<div className="settings-about">
|
||||
<div className="settings-about__card">
|
||||
|
|
@ -348,7 +351,7 @@ function AboutSection() {
|
|||
<div className="settings-about__btns">
|
||||
<Button onClick={() => window.open('https://github.com/ajbura/cinny')}>Source code</Button>
|
||||
<Button onClick={() => window.open('https://cinny.in/#sponsor')}>Support</Button>
|
||||
<Button onClick={() => initMatrix.clearCacheAndReload()} variant="danger">Clear cache & reload</Button>
|
||||
<Button onClick={() => clearCacheAndReload(mx)} variant="danger">Clear cache & reload</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -437,11 +440,12 @@ function useWindowToggle(setSelectedTab) {
|
|||
function Settings() {
|
||||
const [selectedTab, setSelectedTab] = useState(tabItems[0]);
|
||||
const [isOpen, requestClose] = useWindowToggle(setSelectedTab);
|
||||
const mx = useMatrixClient();
|
||||
|
||||
const handleTabChange = (tabItem) => setSelectedTab(tabItem);
|
||||
const handleLogout = async () => {
|
||||
if (await confirmDialog('Logout', 'Are you sure that you want to logout your session?', 'Logout', 'danger')) {
|
||||
initMatrix.logout();
|
||||
logoutClient(mx);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -462,7 +466,7 @@ function Settings() {
|
|||
>
|
||||
{isOpen && (
|
||||
<div className="settings-window__content">
|
||||
<ProfileEditor userId={initMatrix.matrixClient.getUserId()} />
|
||||
<ProfileEditor userId={mx.getUserId()} />
|
||||
<Tabs
|
||||
items={tabItems}
|
||||
defaultSelected={tabItems.findIndex((tab) => tab.text === selectedTab.text)}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
import './SpaceSettings.scss';
|
||||
|
||||
import initMatrix from '../../../client/initMatrix';
|
||||
import cons from '../../../client/state/cons';
|
||||
import navigation from '../../../client/state/navigation';
|
||||
|
||||
|
|
@ -59,8 +58,8 @@ const tabItems = [
|
|||
];
|
||||
|
||||
function GeneralSettings({ roomId }) {
|
||||
const roomName = initMatrix.matrixClient.getRoom(roomId)?.name;
|
||||
const mx = useMatrixClient();
|
||||
const roomName = mx.getRoom(roomId)?.name;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -124,7 +123,7 @@ function SpaceSettings() {
|
|||
const isOpen = window !== null;
|
||||
const roomId = window?.roomId;
|
||||
|
||||
const mx = initMatrix.matrixClient;
|
||||
const mx = useMatrixClient();
|
||||
const room = mx.getRoom(roomId);
|
||||
|
||||
const handleTabChange = (tabItem) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue