avoid ref by getting count in setter callback
This commit is contained in:
parent
afc7273d10
commit
8a964dbff0
1 changed files with 6 additions and 13 deletions
|
@ -17,7 +17,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {useCallback, useMemo, useState, useEffect, useContext, useRef} from 'react';
|
import React, {useCallback, useMemo, useState, useEffect, useContext} from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {Group, RoomMember, User} from 'matrix-js-sdk';
|
import {Group, RoomMember, User} from 'matrix-js-sdk';
|
||||||
|
@ -137,25 +137,18 @@ function useIsEncrypted(cli, room) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function useHasCrossSigningKeys(cli, member, canVerify, setUpdating) {
|
function useHasCrossSigningKeys(cli, member, canVerify, setUpdating) {
|
||||||
// use a ref to setUpdating because we don't want to rerun
|
|
||||||
// the useAsyncMemo hook when it changes.
|
|
||||||
const updatingRef = useRef();
|
|
||||||
useEffect(() => {
|
|
||||||
updatingRef.current = setUpdating;
|
|
||||||
}, [setUpdating]);
|
|
||||||
|
|
||||||
return useAsyncMemo(async () => {
|
return useAsyncMemo(async () => {
|
||||||
if (!canVerify) {
|
if (!canVerify) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updatingRef.current(true);
|
setUpdating(true);
|
||||||
try {
|
try {
|
||||||
await cli.downloadKeys([member.userId]);
|
await cli.downloadKeys([member.userId]);
|
||||||
const xsi = cli.getStoredCrossSigningForUser(member.userId);
|
const xsi = cli.getStoredCrossSigningForUser(member.userId);
|
||||||
const key = xsi && xsi.getId();
|
const key = xsi && xsi.getId();
|
||||||
return !!key;
|
return !!key;
|
||||||
} finally {
|
} finally {
|
||||||
updatingRef.current(false);
|
setUpdating(false);
|
||||||
}
|
}
|
||||||
}, [cli, member, canVerify], false);
|
}, [cli, member, canVerify], false);
|
||||||
}
|
}
|
||||||
|
@ -1356,9 +1349,9 @@ const BasicUserInfo = ({room, member, groupId, devices, isRoomEncrypted}) => {
|
||||||
homeserverSupportsCrossSigning &&
|
homeserverSupportsCrossSigning &&
|
||||||
isRoomEncrypted && !userVerified && !isMe;
|
isRoomEncrypted && !userVerified && !isMe;
|
||||||
|
|
||||||
const setUpdating = useCallback((updating) => {
|
const setUpdating = (updating) => {
|
||||||
setPendingUpdateCount(pendingUpdateCount + (updating ? 1 : -1));
|
setPendingUpdateCount(count => count + (updating ? 1 : -1));
|
||||||
}, [setPendingUpdateCount, pendingUpdateCount]);
|
};
|
||||||
const hasCrossSigningKeys =
|
const hasCrossSigningKeys =
|
||||||
useHasCrossSigningKeys(cli, member, canVerify, setUpdating );
|
useHasCrossSigningKeys(cli, member, canVerify, setUpdating );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue