Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch capabilities in the background #4246

Merged
merged 9 commits into from
Jun 19, 2024
Merged

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Jun 17, 2024

& keep them up to date.

I've elected to change the interface here and split it into two functions rather than re-use the same one. That way, the cached one doesn't need to return a promise. This does make it a BREAKING CHANGE. I've given both functions different names so it's obvious that they're different. It's a trivial code update so I don't really think its worth having a backwards compat function?

It also splits some code out of client.ts(!)

Any of the tests that use runAllTimers() needed replacing with something that would just run the ones they need, since this works by continually setting a timer to keep the capabilities up to date. I don't think runAllTimers() is a sensible thing to use unless you're testing a small piece of code where you know all the timers it's setting.

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.
  • Sign-off given on the changes (see CONTRIBUTING.md).

and round down the wait time for sanity
@dbkr dbkr marked this pull request as ready for review June 18, 2024 11:00
@dbkr dbkr requested review from a team as code owners June 18, 2024 11:00
dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Jun 18, 2024
@@ -611,8 +612,8 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
* Resolves to the version the room should be upgraded to.
*/
public async getRecommendedVersion(): Promise<IRecommendedVersion> {
const capabilities = await this.client.getCapabilities();
let versionCap = capabilities["m.room_versions"];
const capabilities = this.client.getCachedCapabilities();
Copy link
Member

Choose a reason for hiding this comment

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

What if getRecommendedVersion is called before the first capabilities response comes down?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've put back a function that does the same as before.

src/rendezvous/MSC3906Rendezvous.ts Outdated Show resolved Hide resolved
src/serverCapabilities.ts Outdated Show resolved Hide resolved
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

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

Should we maybe have an emitter if you wanted to watch for changes, like we do for well-known polling?

@dbkr
Copy link
Member Author

dbkr commented Jun 18, 2024

Perhaps, but I don't think it would be useful to us right now, particularly? Especially given it will only update every 6 hours, normally. I'd be inclined to keep any extra complexity out until its needed.

dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Jun 18, 2024
It's a separate method to force a capabilities fetch as of
matrix-org/matrix-js-sdk#4246
Copy link
Member

@BillCarsonFr BillCarsonFr 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 comments

src/serverCapabilities.ts Show resolved Hide resolved
public async getCapabilities(): Promise<Capabilities> {
const caps = this.serverCapabilitiesService.getCachedCapabilities();
if (caps) return caps;
return this.serverCapabilitiesService.fetchCapabilities();
Copy link
Member

Choose a reason for hiding this comment

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

So it doesn't swallow errors anymore? only rendez-vous was calling it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, swallowing errors silently and returning something seems like an awful behaviour, so I've changed it favour of having the places its used catch the exception instead, and if they choose to ignore it then that's up to them. It was used in a couple of places, not that many.

@@ -636,7 +640,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
"to be supporting a newer room version we don't know about.",
);

const caps = await this.client.getCapabilities(true);
const caps = await this.client.fetchCapabilities();
Copy link
Member

Choose a reason for hiding this comment

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

this would throw here now? instead of returning a default value? Would impact the react-sdk?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I forgot to catch the exception here actually.

@dbkr dbkr added this pull request to the merge queue Jun 19, 2024
Merged via the queue into develop with commit 819fc75 Jun 19, 2024
27 checks passed
@dbkr dbkr deleted the dbkr/fetch_capabilities_background branch June 19, 2024 10:47
github-merge-queue bot pushed a commit to matrix-org/matrix-react-sdk that referenced this pull request Jun 19, 2024
It's a separate method to force a capabilities fetch as of
matrix-org/matrix-js-sdk#4246
dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Jun 19, 2024
dbkr added a commit to matrix-org/matrix-react-sdk that referenced this pull request Jun 20, 2024
github-merge-queue bot pushed a commit to matrix-org/matrix-react-sdk that referenced this pull request Jul 2, 2024
* Disable profile controls if the HS doesn't allow them to be set

Also updates to the js-sdk interface changes in matrix-org/matrix-js-sdk#4246

* Remove unnecessary await

* Pass disabled prop to accessiblebutton in avatarsetting

* Use getCapabilities

in case there are no cached capabilities

* Fix test

* Go back to just using getCapabilities

Rather than change the other places
github-merge-queue bot pushed a commit to matrix-org/matrix-react-sdk that referenced this pull request Jul 4, 2024
* Disable profile controls if the HS doesn't allow them to be set

Also updates to the js-sdk interface changes in matrix-org/matrix-js-sdk#4246

* Remove unnecessary await

* Pass disabled prop to accessiblebutton in avatarsetting

* Move the account management button

The section it lives in with the server name goes, and the button
just lives on its own in the profile section.

* Update test

* Revert bits of previous PR that are no longer wanted

because we squash merge so git can no longer make sense of what changes
have been applied.

* More squash-merge fails

* More more squash merge fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants