Skip to content

feat(crypto): Support verification violation composer banner#29067

Merged
BillCarsonFr merged 5 commits intodevelopfrom
valere/verification_violation_banner
Jan 31, 2025
Merged

feat(crypto): Support verification violation composer banner#29067
BillCarsonFr merged 5 commits intodevelopfrom
valere/verification_violation_banner

Conversation

@BillCarsonFr
Copy link
Copy Markdown
Member

@BillCarsonFr BillCarsonFr commented Jan 22, 2025

Draft: depends on matrix-org/matrix-js-sdk#4646

Following an initial early review, I have refactored the component to now use a viewModel 8325c0c
The update model has also been made a lot more simple, but also less optimized; as an example a UserTrustStatusChanged event will trigger a new computation of all the violations in the room. If we see performances problem this could be improoved

image
image

Following initial review,

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • I have licensed the changes to Element by completing the Contributor License Agreement (CLA)

@BillCarsonFr BillCarsonFr added the T-Feature Request to add a new feature which does not exist right now label Jan 22, 2025
@BillCarsonFr BillCarsonFr force-pushed the valere/verification_violation_banner branch from 02a2640 to 8325c0c Compare January 28, 2025 14:58
@BillCarsonFr BillCarsonFr added T-Task Tasks for the team like planning and removed T-Feature Request to add a new feature which does not exist right now labels Jan 28, 2025
@BillCarsonFr BillCarsonFr force-pushed the valere/verification_violation_banner branch from dc9ece8 to f56a743 Compare January 29, 2025 08:58
@BillCarsonFr BillCarsonFr marked this pull request as ready for review January 29, 2025 09:23
@BillCarsonFr BillCarsonFr requested a review from a team as a code owner January 29, 2025 09:23
@BillCarsonFr BillCarsonFr requested review from MidhunSureshR, dbkr, florianduros and uhoreg and removed request for MidhunSureshR January 29, 2025 09:23

export type ViolationType = "PinViolation" | "VerificationViolation";

export type ViolationPrompt = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could all of these exported things have tsdoc please?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 6b76fbc

onButtonClick: (ev: ButtonEvent) => void;
}

async function mapToViolations(cryptoApi: CryptoApi, members: RoomMember[]): Promise<ViolationPrompt[]> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also do with some doc as it's not super obvious what it does.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 6b76fbc

},
[crypto, room, loadViolations],
);
useTypedEventEmitter(cli, RoomStateEvent.Events, onRoomStateEvent);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For functions that are defined and then just used once on the next line, probably may as well just use an anonymous one inline.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6b76fbc

});
}, [loadViolations]);

let onButtonClick: (ev: ButtonEvent) => void = () => {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird to assign a different callback to the button depending on the state. Generally you would just have one callback which behaves accordingly. Also, you probably want to make it a useCallback and ideally be a bit more specific than onButtonClick (even though in this case there's only one button).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, I tried that d1509b9

Copy link
Copy Markdown
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks fine to me

Copy link
Copy Markdown
Member

@uhoreg uhoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits, but looks reasonable.

Comment thread test/unit-tests/components/views/rooms/UserIdentityWarning-test.tsx Outdated
Comment thread test/unit-tests/components/views/rooms/UserIdentityWarning-test.tsx Outdated
Comment thread test/unit-tests/components/views/rooms/UserIdentityWarning-test.tsx Outdated
Comment thread test/unit-tests/components/views/rooms/UserIdentityWarning-test.tsx Outdated
Comment on lines +599 to +606
await firstStatusPromise.promise;
callNumber++;
if (callNumber == 1) {
await sleep(40);
return new UserVerificationStatus(false, false, false, false);
} else {
return new UserVerificationStatus(false, false, false, true);
}
Copy link
Copy Markdown
Member

@richvdh richvdh Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BillCarsonFr as author and @uhoreg and @dbkr as reviewers: can any of you tell me what's going on here? On the first call to getUserVerificationStatus it blocks for 40ms, but on subsequent calls, it returns immediately: why does it sleep in the first place?

This test seems to be racy (#29266); I think we need something more resilient than sleeps for tens of ms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking further at what's happening in this PR, it looks like this test is no longer relevant. It's testing what happens when the UserTrustStatusChanged event says something different to getUserVerificationStatus, but the code no longer relies on the payload of UserTrustStatusChanged, so it feels like the test is redundant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(conclusion from discussion with @BillCarsonFr is that this test is indeed redundant)

Copy link
Copy Markdown
Member Author

@BillCarsonFr BillCarsonFr Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was testing a race that was possible in the component before the refactoring to view model.

The old component was saying:

   // For each user, we assign a sequence number to each verification status
    // that we get, or fetch.
    //
    // Since fetching a verification status is asynchronous, we could get an
    // update in the middle of fetching the verification status, which could
    // mean that the status that we fetched is out of date.  So if the current
    // sequence number is not the same as the sequence number when we started
    // the fetch, then we drop our fetched result, under the assumption that the
    // update that we received is the most up-to-date version.  If it is in fact
    // not the most up-to-date version, then we should be receiving a new update
    // soon with the newer value, so it will fix itself in the end.

So this test was trying to trigger this flow, where the initial status fetch is resolved late thus returning an outdated value, this to ensure that the component detects it and get the up to date value

It is indeed redondant with the new model (was usefull to test no regression with the old component)

richvdh added a commit that referenced this pull request Mar 3, 2025
Since the refactoring in #29067,
this test is redundant.

It is also flaky and hard to understand. Time for it to die.
github-merge-queue Bot pushed a commit that referenced this pull request Mar 3, 2025
* Remove redundant `UserIdentityWarning` test

Since the refactoring in #29067,
this test is redundant.

It is also flaky and hard to understand. Time for it to die.

* delint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Task Tasks for the team like planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants