This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 831
Reload map on reconnect #8848
Merged
Merged
Reload map on reconnect #8848
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { ClientEvent, ClientEventHandlerMap } from "matrix-js-sdk/src/matrix"; | ||
import { SyncState } from "matrix-js-sdk/src/sync"; | ||
|
||
/** | ||
* Creates a MatrixClient event listener function that can be used to get notified about reconnects. | ||
* @param callback The callback to be called on reconnect | ||
*/ | ||
export const createReconnectedListener = (callback: () => void): ClientEventHandlerMap[ClientEvent.Sync] => { | ||
return (syncState: SyncState, prevState: SyncState) => { | ||
if (syncState !== SyncState.Error && prevState !== syncState) { | ||
// Consider the client reconnected if there is no error with syncing. | ||
// This means the state could be RECONNECTING, SYNCING, PREPARED or CATCHUP. | ||
callback(); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -120,6 +120,10 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] = | |||||||
"error": Array [ | ||||||||
[Function], | ||||||||
[Function], | ||||||||
[Function], | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The snapshot currently depends on the test that ran before. The map mock is set up here: https://github.com/matrix-org/matrix-react-sdk/blob/v3.47.0/__mocks__/maplibre-gl.js#L5 Jest doesn't seem to reset the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
[Function], | ||||||||
[Function], | ||||||||
[Function], | ||||||||
], | ||||||||
}, | ||||||||
"_eventsCount": 1, | ||||||||
|
@@ -130,12 +134,20 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] = | |||||||
mockConstructor {}, | ||||||||
"top-right", | ||||||||
], | ||||||||
Array [ | ||||||||
mockConstructor {}, | ||||||||
"top-right", | ||||||||
], | ||||||||
], | ||||||||
"results": Array [ | ||||||||
Object { | ||||||||
"type": "return", | ||||||||
"value": undefined, | ||||||||
}, | ||||||||
Object { | ||||||||
"type": "return", | ||||||||
"value": undefined, | ||||||||
}, | ||||||||
], | ||||||||
}, | ||||||||
"fitBounds": [MockFunction], | ||||||||
|
@@ -148,12 +160,22 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] = | |||||||
"lon": -0.1276, | ||||||||
}, | ||||||||
], | ||||||||
Array [ | ||||||||
Object { | ||||||||
"lat": 51.5076, | ||||||||
"lon": -0.1276, | ||||||||
}, | ||||||||
], | ||||||||
], | ||||||||
"results": Array [ | ||||||||
Object { | ||||||||
"type": "return", | ||||||||
"value": undefined, | ||||||||
}, | ||||||||
Object { | ||||||||
"type": "return", | ||||||||
"value": undefined, | ||||||||
}, | ||||||||
], | ||||||||
}, | ||||||||
"setStyle": [MockFunction], | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { ClientEvent, ClientEventHandlerMap } from "matrix-js-sdk/src/matrix"; | ||
import { SyncState } from "matrix-js-sdk/src/sync"; | ||
|
||
import { createReconnectedListener } from "../../src/utils/connection"; | ||
|
||
describe("createReconnectedListener", () => { | ||
let reconnectedListener: ClientEventHandlerMap[ClientEvent.Sync]; | ||
let onReconnect: jest.Mock; | ||
|
||
beforeEach(() => { | ||
onReconnect = jest.fn(); | ||
reconnectedListener = createReconnectedListener(onReconnect); | ||
}); | ||
|
||
[ | ||
[SyncState.Prepared, SyncState.Syncing], | ||
[SyncState.Syncing, SyncState.Reconnecting], | ||
[SyncState.Reconnecting, SyncState.Syncing], | ||
].forEach(([from, to]) => { | ||
it(`should invoke the callback on a transition from ${from} to ${to}`, () => { | ||
reconnectedListener(to, from); | ||
expect(onReconnect).toBeCalled(); | ||
}); | ||
}); | ||
|
||
[ | ||
[SyncState.Syncing, SyncState.Syncing], | ||
[SyncState.Catchup, SyncState.Error], | ||
[SyncState.Reconnecting, SyncState.Error], | ||
].forEach(([from, to]) => { | ||
it(`should not invoke the callback on a transition from ${from} to ${to}`, () => { | ||
reconnectedListener(to, from); | ||
expect(onReconnect).not.toBeCalled(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Copied over from here https://github.com/matrix-org/matrix-react-sdk/blob/v3.47.0/src/components/views/messages/MImageBody.tsx#L89