-
Notifications
You must be signed in to change notification settings - Fork 13.9k
fix: federated presence is never sent #41872
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
Open
+173
−7
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3841e39
fix: federated presence is never sent
cardoso fc05bf6
chore: add changeset
cardoso 33ff43d
test: busy when no EDU is sent
cardoso add67d3
fix: remove spurious short-circuit
cardoso b70945a
chore: remove unneeded explicit generic
cardoso 9fcaebb
Actualizar federated-presence-never-sent.md
KevLehman 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 hidden or 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,5 @@ | ||
| --- | ||
| '@rocket.chat/federation-matrix': patch | ||
| --- | ||
|
|
||
| Fixes federated user presence never being sent to remote workspaces |
This file contains hidden or 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
161 changes: 161 additions & 0 deletions
161
ee/packages/federation-matrix/tests/end-to-end/presence.spec.ts
This file contains hidden or 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,161 @@ | ||
| import type { IRoomNativeFederated } from '@rocket.chat/core-typings'; | ||
| import { UserStatus } from '@rocket.chat/core-typings'; | ||
| import { Visibility } from 'matrix-js-sdk'; | ||
|
|
||
| import { api } from '../../../../../apps/meteor/tests/data/api-data'; | ||
| import { acceptRoomInvite } from '../../../../../apps/meteor/tests/data/rooms.helper'; | ||
| import { type IRequestConfig, createUser, getRequestConfig, getUserByUsername } from '../../../../../apps/meteor/tests/data/users.helper'; | ||
| import { IS_EE } from '../../../../../apps/meteor/tests/e2e/config/constants'; | ||
| import { retry } from '../../../../../apps/meteor/tests/end-to-end/api/helpers/retry'; | ||
| import { federationConfig } from '../helper/config'; | ||
| import { DDPListener } from '../helper/ddp-listener'; | ||
| import { SynapseClient } from '../helper/synapse-client'; | ||
|
|
||
| const localUser = federationConfig.rc1.additionalUser1; | ||
| const remoteUser = federationConfig.hs1.additionalUser1; | ||
|
|
||
| const PRESENCE_SETTING = 'Federation_Service_EDU_Process_Presence'; | ||
|
|
||
| (IS_EE ? describe : describe.skip)('Federation presence', () => { | ||
| let rc1AdminRequestConfig: IRequestConfig; | ||
| let rc1UserRequestConfig: IRequestConfig; | ||
| let hs1UserApp: SynapseClient; | ||
| let federatedRoomId: string; | ||
|
|
||
| const setPresenceSetting = async (value: boolean) => { | ||
| await rc1AdminRequestConfig.request | ||
| .post(api(`settings/${PRESENCE_SETTING}`)) | ||
| .set(rc1AdminRequestConfig.credentials) | ||
| .send({ value }) | ||
| .expect(200); | ||
| }; | ||
|
|
||
| const expectRemotePresence = async (expected: string) => | ||
| retry( | ||
| `waiting for ${remoteUser.username} to see ${localUser.matrixUserId} as ${expected}`, | ||
| async () => { | ||
| const status = await hs1UserApp.matrixClient.getPresence(localUser.matrixUserId); | ||
|
|
||
| expect(status.presence).toBe(expected); | ||
| }, | ||
| { retries: 10, delayMs: 2000 }, | ||
| ); | ||
|
|
||
| beforeAll(async () => { | ||
| rc1AdminRequestConfig = await getRequestConfig( | ||
| federationConfig.rc1.url, | ||
| federationConfig.rc1.adminUser, | ||
| federationConfig.rc1.adminPassword, | ||
| ); | ||
|
|
||
| const existingLocalUser = await getUserByUsername(localUser.username, rc1AdminRequestConfig); | ||
| if (!existingLocalUser?._id) { | ||
| await createUser( | ||
| { | ||
| username: localUser.username, | ||
| password: localUser.password, | ||
| email: `${localUser.username}@rocket.chat`, | ||
| name: localUser.username, | ||
| }, | ||
| rc1AdminRequestConfig, | ||
| ); | ||
| } | ||
|
|
||
| rc1UserRequestConfig = await getRequestConfig(federationConfig.rc1.url, localUser.username, localUser.password); | ||
|
|
||
| await setPresenceSetting(true); | ||
|
|
||
| hs1UserApp = new SynapseClient(federationConfig.hs1.url, remoteUser.username, remoteUser.password); | ||
| await hs1UserApp.initialize(); | ||
|
|
||
| const channelName = `fed-presence-${Date.now()}`; | ||
| const synapseRoomId = await hs1UserApp.createRoom(channelName, Visibility.Private); | ||
| await hs1UserApp.inviteUserToRoom(synapseRoomId, localUser.matrixUserId); | ||
|
|
||
| await retry( | ||
| 'waiting for the federated room to reach RC', | ||
| async () => { | ||
| const response = await rc1UserRequestConfig.request.get(api('rooms.get')).set(rc1UserRequestConfig.credentials).expect(200); | ||
|
|
||
| const rcRoom = response.body.update.find( | ||
| (room: IRoomNativeFederated) => room.federation?.mrid === synapseRoomId, | ||
| ) as IRoomNativeFederated | null; | ||
|
|
||
| expect(rcRoom).toBeTruthy(); | ||
| federatedRoomId = rcRoom!._id; | ||
| }, | ||
| { retries: 10, delayMs: 2000 }, | ||
| ); | ||
|
|
||
| const accepted = await acceptRoomInvite(federatedRoomId, rc1UserRequestConfig); | ||
| expect(accepted).toHaveProperty('success', true); | ||
| }, 120000); | ||
|
|
||
| afterAll(async () => { | ||
| if (rc1AdminRequestConfig) { | ||
| await setPresenceSetting(false); | ||
| } | ||
| await hs1UserApp?.close(); | ||
| }); | ||
|
|
||
| const setLocalStatus = async (status: UserStatus) => { | ||
| const response = await rc1UserRequestConfig.request | ||
| .post(api('users.setStatus')) | ||
| .set(rc1UserRequestConfig.credentials) | ||
| .send({ status, message: '' }) | ||
| .expect(200); | ||
|
|
||
| expect(response.body).toHaveProperty('success', true); | ||
| }; | ||
|
|
||
| it('should share a federated room with the remote user', async () => { | ||
| const response = await rc1UserRequestConfig.request | ||
| .get(api('subscriptions.getOne')) | ||
| .set(rc1UserRequestConfig.credentials) | ||
| .query({ roomId: federatedRoomId }) | ||
| .expect(200); | ||
|
|
||
| expect(response.body.subscription).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should reach the remote server when the local user goes online', async () => { | ||
| await setLocalStatus(UserStatus.ONLINE); | ||
|
|
||
| await expectRemotePresence('online'); | ||
| }, 60000); | ||
|
|
||
| describe('with a connected client', () => { | ||
| let ddp: DDPListener; | ||
|
|
||
| beforeAll(async () => { | ||
| ddp = new DDPListener(federationConfig.rc1.url, rc1UserRequestConfig); | ||
| await ddp.connect(); | ||
| }, 60000); | ||
|
|
||
| afterAll(() => { | ||
| ddp?.disconnect(); | ||
| }); | ||
|
|
||
| // away and busy both collapse to the Matrix `unavailable` state | ||
| it('should reach the remote server when the local user goes away', async () => { | ||
| await setLocalStatus(UserStatus.AWAY); | ||
|
|
||
| await expectRemotePresence('unavailable'); | ||
| }, 60000); | ||
|
|
||
| it('should reach the remote server when the local user goes busy', async () => { | ||
| await setLocalStatus(UserStatus.ONLINE); | ||
| await expectRemotePresence('online'); | ||
|
|
||
| await setLocalStatus(UserStatus.BUSY); | ||
|
|
||
| await expectRemotePresence('unavailable'); | ||
| }, 60000); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it('should reach the remote server when the local user comes back online', async () => { | ||
| await setLocalStatus(UserStatus.ONLINE); | ||
|
|
||
| await expectRemotePresence('online'); | ||
| }, 60000); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.