Skip to content

Commit

Permalink
Add some logging to UserIdenitityWarning
Browse files Browse the repository at this point in the history
We had some reports of misbehaviour here, so adding a bit of looging to try to
track it down.
  • Loading branch information
richvdh committed Dec 13, 2024
1 parent edaf977 commit a3b4ed2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/views/rooms/UserIdentityWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,17 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
if (currentPrompt && membersNeedingApproval.has(currentPrompt.userId)) return currentPrompt;

if (membersNeedingApproval.size === 0) {
if (currentPrompt) {
// If we were previously showing a warning, log that we've stopped doing so.
logger.debug("UserIdentityWarning: no users left that need approval");
}
return undefined;
}

// We pick the user with the smallest user ID.
const keys = Array.from(membersNeedingApproval.keys()).sort((a, b) => a.localeCompare(b));
const selection = membersNeedingApproval.get(keys[0]!);
logger.debug(`UserIdentityWarning: now warning about user ${selection?.userId}`);
return selection;
});
}, []);
Expand All @@ -132,6 +137,9 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
// initialising, and we want to start by displaying a warning
// for the user with the smallest ID.
if (initialisedRef.current === InitialisationStatus.Completed) {
logger.debug(
`UserIdentityWarning: user ${userId} now needs approval; approval-pending list now [${Array.from(membersNeedingApprovalRef.current.keys())}]`,
);
updateCurrentPrompt();
}
},
Expand Down Expand Up @@ -173,6 +181,9 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
const removeMemberNeedingApproval = useCallback(
(userId: string): void => {
membersNeedingApprovalRef.current.delete(userId);
logger.debug(
`UserIdentityWarning: user ${userId} no longer needs approval; approval-pending list now [${Array.from(membersNeedingApprovalRef.current.keys())}]`,
);
updateCurrentPrompt();
},
[updateCurrentPrompt],
Expand All @@ -195,6 +206,9 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
const members = await room.getEncryptionTargetMembers();
await addMembersWhoNeedApproval(members);

logger.info(
`Initialised UserIdentityWarning component for room ${room.roomId} with approval-pending list [${Array.from(membersNeedingApprovalRef.current.keys())}]`,
);
updateCurrentPrompt();
initialisedRef.current = InitialisationStatus.Completed;
}, [crypto, room, addMembersWhoNeedApproval, updateCurrentPrompt]);
Expand Down

0 comments on commit a3b4ed2

Please sign in to comment.