-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Conversation
& keep them up to date
and round down the wait time for sanity
Also updates to the js-sdk interface changes in matrix-org/matrix-js-sdk#4246
src/models/room.ts
Outdated
@@ -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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
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. |
It's a separate method to force a capabilities fetch as of matrix-org/matrix-js-sdk#4246
There was a problem hiding this 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
public async getCapabilities(): Promise<Capabilities> { | ||
const caps = this.serverCapabilitiesService.getCachedCapabilities(); | ||
if (caps) return caps; | ||
return this.serverCapabilitiesService.fetchCapabilities(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/models/room.ts
Outdated
@@ -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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
It's a separate method to force a capabilities fetch as of matrix-org/matrix-js-sdk#4246
Also updates to the js-sdk interface changes in matrix-org/matrix-js-sdk#4246
Also updates to the js-sdk interface changes in matrix-org/matrix-js-sdk#4246
* 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
* 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
& 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 thinkrunAllTimers()
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
public
/exported
symbols have accurate TSDoc documentation.