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

chore: move to matrix-* #33525

Merged
merged 83 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
58ad830
chore: move to `matrix-sdk-crypto`
ggazzo Oct 10, 2024
d894092
..
ggazzo Oct 10, 2024
534f9cc
adapt code
ggazzo Oct 10, 2024
714a27e
,,
ggazzo Oct 11, 2024
f77867b
test
debdutdeb Oct 14, 2024
fd17a95
install must stuff
debdutdeb Oct 14, 2024
2716a61
wow
debdutdeb Oct 14, 2024
0c45008
?
debdutdeb Oct 14, 2024
1fb5aed
..
debdutdeb Oct 14, 2024
e676f7d
/usr/include
debdutdeb Oct 14, 2024
43e92a9
..
debdutdeb Oct 14, 2024
90c6d85
ill be back
debdutdeb Oct 14, 2024
552511d
.
debdutdeb Oct 14, 2024
ed52d99
nice
debdutdeb Oct 14, 2024
c2a7435
i dont think path is needed
debdutdeb Oct 14, 2024
8e657bb
...
debdutdeb Oct 14, 2024
2b3ac19
:?
debdutdeb Oct 14, 2024
47812c5
.
debdutdeb Oct 14, 2024
9460898
logs
debdutdeb Oct 15, 2024
f82558e
test
debdutdeb Oct 16, 2024
0d5572a
upate
debdutdeb Oct 16, 2024
228d6b6
don't build simply pull
debdutdeb Oct 16, 2024
5f4685d
only run these
debdutdeb Oct 16, 2024
95df4bd
monolith damnit
debdutdeb Oct 16, 2024
05e93ea
read more
debdutdeb Oct 16, 2024
c0da806
come on
debdutdeb Oct 16, 2024
8746b5f
log
debdutdeb Oct 16, 2024
261cba2
not shell
debdutdeb Oct 16, 2024
47a6058
test all of it
debdutdeb Oct 16, 2024
6b2c8fb
update deps after rebase
debdutdeb Oct 18, 2024
5c3640c
remove from lockfile
debdutdeb Oct 18, 2024
4d79400
focus on this
debdutdeb Oct 18, 2024
3259a56
add matrix-bot-sdk
debdutdeb Oct 18, 2024
35310db
trigger ci
debdutdeb Oct 18, 2024
b528025
:)
debdutdeb Oct 18, 2024
1d74d0e
reduce stuff to do
debdutdeb Oct 18, 2024
e58d5a2
..
debdutdeb Oct 18, 2024
d763946
.
debdutdeb Oct 18, 2024
d1e9fb0
dumb logs
debdutdeb Oct 18, 2024
aa062d0
increase timeout for mocha
debdutdeb Oct 18, 2024
8e21c10
better logs
debdutdeb Oct 18, 2024
47cec3f
is it really the hooks?
debdutdeb Oct 18, 2024
bc345fe
eh????????
debdutdeb Oct 18, 2024
979e40e
leave as default
debdutdeb Oct 18, 2024
4ae28ca
trying to get the number down
debdutdeb Oct 18, 2024
54df34c
.
debdutdeb Oct 18, 2024
b436212
ummm
debdutdeb Oct 18, 2024
c01c864
remove timeout from updateSetting
debdutdeb Oct 18, 2024
b0d2af9
run immediately
debdutdeb Oct 18, 2024
cb12eca
...
debdutdeb Oct 18, 2024
dd44bb6
see time again
debdutdeb Oct 18, 2024
590fc09
track exec time for setting
debdutdeb Oct 18, 2024
03c1b59
...
debdutdeb Oct 18, 2024
afb507b
log timeout
debdutdeb Oct 18, 2024
4011e7e
?
debdutdeb Oct 18, 2024
906c542
.
debdutdeb Oct 18, 2024
a049dfa
ah
debdutdeb Oct 18, 2024
bb0279b
...
debdutdeb Oct 18, 2024
61b8c23
now check time for without timer
debdutdeb Oct 18, 2024
37ee816
....
debdutdeb Oct 18, 2024
aacae26
..
debdutdeb Oct 18, 2024
00bde75
..
debdutdeb Oct 18, 2024
4c5b365
...
debdutdeb Oct 18, 2024
7bab677
...
debdutdeb Oct 18, 2024
0cabae5
reset
debdutdeb Oct 18, 2024
c6ae6a7
debug?
debdutdeb Oct 18, 2024
733f233
...
debdutdeb Oct 18, 2024
14fc94a
.
debdutdeb Oct 18, 2024
e507353
trying something dumb
debdutdeb Oct 18, 2024
73d454f
??
debdutdeb Oct 18, 2024
b70d17e
simplest?
debdutdeb Oct 18, 2024
a50236e
...
debdutdeb Oct 18, 2024
9d52518
retrigger ci
debdutdeb Oct 18, 2024
2a60765
build this
debdutdeb Oct 18, 2024
3c7e535
...
debdutdeb Oct 18, 2024
9e494eb
...
debdutdeb Oct 18, 2024
fb3ef4b
Merge branch 'develop' into chore/matrix=deps
debdutdeb Oct 18, 2024
47ac5e3
Merge branch 'develop' into chore/matrix=deps
debdutdeb Oct 18, 2024
d3042c5
..
debdutdeb Oct 18, 2024
ab0364f
....
debdutdeb Oct 18, 2024
f062737
add commnet
debdutdeb Oct 18, 2024
896783a
Update .github/workflows/ci.yml
ggazzo Oct 18, 2024
d79bced
Update .github/workflows/ci.yml
KevLehman Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/actions/build-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ runs:
if: inputs.setup == 'true'
shell: bash

- if: ${{ matrix.platform == 'alpine' }}
uses: actions/download-artifact@v4
with:
name: napi-binary
path: /tmp/build/matrix-sdk-crypto.linux-x64-musl.node

- name: Build Docker images
shell: bash
run: |
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,46 @@ jobs:
deno-version: ${{ needs.release-versions.outputs.deno-version }}
coverage: ${{ github.event_name != 'release' }}

# TODO: this should go away once upstream builds are fixed
build-matrix-rust-bindings-for-alpine:
name: Builds matrix rust bindings against alpine
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y musl-tools libunwind-dev && find /usr/include -name stdarg.h 2>/dev/null || true
- uses: actions/checkout@v4
with:
repository: matrix-org/matrix-rust-sdk-crypto-nodejs
ref: v0.2.0-beta.1 # https://github.com/element-hq/matrix-bot-sdk/blob/e72a4c498e00c6c339a791630c45d00a351f56a8/package.json#L58

- uses: actions/setup-node@v4
with:
node-version: '20'

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: x86_64-unknown-linux-musl

- name: Install ziglang
uses: mlugg/setup-zig@v1
with:
version: 0.13.0

- name: Build
run: |
npm install --ignore-scripts
npx napi build --release --target x86_64-unknown-linux-musl --platform --zig

- name: Upload bin
uses: actions/upload-artifact@v4
with:
path: matrix-sdk-crypto.linux-x64-musl.node
name: napi-binary
if-no-files-found: error

build-gh-docker-coverage:
name: 🚢 Build Docker Images for Testing
needs: [build, release-versions]
needs: [build, release-versions, build-matrix-rust-bindings-for-alpine]
runs-on: ubuntu-20.04

env:
Expand Down Expand Up @@ -311,6 +348,11 @@ jobs:
build-containers: ${{ matrix.platform == 'alpine' && 'authorization-service account-service ddp-streamer-service presence-service stream-hub-service queue-worker-service omnichannel-transcript-service' || '' }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Make sure matrix bindings load
if: ${{ matrix.platform == 'alpine' }}
run: |
docker run --rm -w /app/bundle/programs/server/npm/node_modules/matrix-appservice-bridge ghcr.io/rocketchat/rocket.chat:$RC_DOCKER_TAG -e 'require(".")'

build-gh-docker:
name: 🚢 Build Docker Images for Production
needs: [build-prod, release-versions]
Expand Down Expand Up @@ -373,6 +415,7 @@ jobs:
test-api:
name: 🔨 Test API (CE)
needs: [checks, build-gh-docker-coverage, release-versions]
needs: [build-gh-docker-coverage, release-versions]
KevLehman marked this conversation as resolved.
Show resolved Hide resolved

uses: ./.github/workflows/ci-test-e2e.yml
with:
Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/.docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ RUN set -x \
&& npm cache clear --force \
&& apk del .fetch-deps

# TODO: remove hack once upstream builds are fixed
COPY matrix-sdk-crypto.linux-x64-musl.node /app/bundle/programs/server/npm/node_modules/@matrix-org/matrix-sdk-crypto-nodejs
COPY matrix-sdk-crypto.linux-x64-musl.node /app/bundle/programs/server/npm/node_modules/@vector-im/matrix-bot-sdk/node_modules/@matrix-org/matrix-sdk-crypto-nodejs

VOLUME /app/uploads

WORKDIR /app/bundle
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@
"@rocket.chat/css-in-js": "~0.31.25",
"@rocket.chat/emitter": "~0.31.25",
"@rocket.chat/favicon": "workspace:^",
"@rocket.chat/forked-matrix-appservice-bridge": "^4.0.2",
"@rocket.chat/forked-matrix-bot-sdk": "^0.6.0-beta.3",
"@rocket.chat/freeswitch": "workspace:^",
"@rocket.chat/fuselage": "^0.59.1",
"@rocket.chat/fuselage-hooks": "^0.33.1",
Expand Down Expand Up @@ -292,6 +290,7 @@
"@slack/bolt": "^3.14.0",
"@slack/rtm-api": "^6.0.0",
"@tanstack/react-query": "^4.16.1",
"@vector-im/matrix-bot-sdk": "0.7.1-element.6",
"@xmldom/xmldom": "^0.8.10",
"adm-zip": "0.5.16",
"ajv": "^8.11.0",
Expand Down Expand Up @@ -370,6 +369,8 @@
"lodash.get": "^4.4.2",
"mailparser": "^3.4.0",
"marked": "^4.2.5",
"matrix-appservice": "^2.0.0",
"matrix-appservice-bridge": "^10.3.1",
"mem": "^8.1.1",
"meteor-node-stubs": "^1.2.10",
"mime-db": "^1.52.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export abstract class AbstractFederationApplicationService {
return;
}
if (federatedUser.shouldUpdateFederationAvatar(avatarUrl)) {
await this.internalUserAdapter.setAvatar(federatedUser, this.bridge.convertMatrixUrlToHttp(federatedUser.getExternalId(), avatarUrl));
await this.internalUserAdapter.setAvatar(
federatedUser,
await this.bridge.convertMatrixUrlToHttp(federatedUser.getExternalId(), avatarUrl),
);
await this.internalUserAdapter.updateFederationAvatar(federatedUser.getInternalId(), avatarUrl);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface IFederationBridge {
fileDetails: { filename: string; fileSize: number; mimeType: string; metadata?: { width?: number; height?: number; format?: string } },
): Promise<string>;
uploadContent(externalSenderId: string, content: Buffer, options?: { name?: string; type?: string }): Promise<string | undefined>;
convertMatrixUrlToHttp(externalUserId: string, matrixUrl: string): string;
convertMatrixUrlToHttp(externalUserId: string, matrixUrl: string): Promise<string>;
sendReplyToMessage(
externalRoomId: string,
externalUserId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IMessage } from '@rocket.chat/core-typings';
import type { AppServiceOutput, Bridge } from '@rocket.chat/forked-matrix-appservice-bridge';
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import type { AppServiceOutput, Bridge } from 'matrix-appservice-bridge';

import type { IExternalUserProfileInformation, IFederationBridge, IFederationBridgeRegistrationFile } from '../../domain/IFederationBridge';
import type { RocketChatSettingsAdapter } from '../rocket-chat/adapters/Settings';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class MatrixBridge implements IFederationBridge {
this.bridgeInstance.addAppServicePath({
method: 'POST',
path: '/_matrix/app/v1/ping',
checkToken: true,
authenticate: true,
handler: (_req, res, _next) => {
/*
* https://spec.matrix.org/v1.11/application-service-api/#post_matrixappv1ping
Expand Down Expand Up @@ -489,7 +489,7 @@ export class MatrixBridge implements IFederationBridge {
}

public async getReadStreamForFileFromUrl(externalUserId: string, fileUrl: string): Promise<ReadableStream> {
const response = await fetch(this.convertMatrixUrlToHttp(externalUserId, fileUrl));
const response = await fetch(await this.convertMatrixUrlToHttp(externalUserId, fileUrl));
if (!response.body) {
throw new Error('Not able to download the file');
}
Expand Down Expand Up @@ -736,15 +736,15 @@ export class MatrixBridge implements IFederationBridge {
await this.bridgeInstance.getIntent(externalUserId).setRoomTopic(externalRoomId, roomTopic);
}

public convertMatrixUrlToHttp(externalUserId: string, matrixUrl: string): string {
public convertMatrixUrlToHttp(externalUserId: string, matrixUrl: string): Promise<string> {
return this.bridgeInstance.getIntent(externalUserId).matrixClient.mxcToHttp(matrixUrl);
}

protected async createInstance(): Promise<void> {
federationBridgeLogger.info('Performing Dynamic Import of matrix-appservice-bridge');

// Dynamic import to prevent Rocket.Chat from loading the module until needed and then handle if that fails
const { Bridge, AppServiceRegistration, MatrixUser } = await import('@rocket.chat/forked-matrix-appservice-bridge');
const { Bridge, AppServiceRegistration, MatrixUser } = await import('matrix-appservice-bridge');
MatrixUserInstance = MatrixUser;
const registrationFile = this.internalSettings.getAppServiceRegistrationObject();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MentionPill as MentionPillType } from '@rocket.chat/forked-matrix-bot-sdk';
import type { MentionPill as MentionPillType } from '@vector-im/matrix-bot-sdk';
import { marked } from 'marked';

const INTERNAL_MENTIONS_FOR_EXTERNAL_USERS_REGEX = /@([0-9a-zA-Z-_.]+(@([0-9a-zA-Z-_.]+))?):+([0-9a-zA-Z-_.]+)(?=[^<>]*(?:<\w|$))/gm; // @username:server.com excluding any <a> tags
Expand All @@ -20,23 +20,23 @@ const replaceMessageMentions = async (
};

const replaceMentionsFromLocalExternalUsersForExternalFormat = async (message: string): Promise<string> => {
const { MentionPill } = await import('@rocket.chat/forked-matrix-bot-sdk');
const { MentionPill } = await import('@vector-im/matrix-bot-sdk');

return replaceMessageMentions(message, INTERNAL_MENTIONS_FOR_EXTERNAL_USERS_REGEX, (match: string) =>
MentionPill.forUser(match.trimStart()),
);
};

const replaceInternalUsersMentionsForExternalFormat = async (message: string, homeServerDomain: string): Promise<string> => {
const { MentionPill } = await import('@rocket.chat/forked-matrix-bot-sdk');
const { MentionPill } = await import('@vector-im/matrix-bot-sdk');

return replaceMessageMentions(message, INTERNAL_MENTIONS_FOR_INTERNAL_USERS_REGEX, (match: string) =>
MentionPill.forUser(`${match.trimStart()}:${homeServerDomain}`),
);
};

const replaceInternalGeneralMentionsForExternalFormat = async (message: string, externalRoomId: string): Promise<string> => {
const { MentionPill } = await import('@rocket.chat/forked-matrix-bot-sdk');
const { MentionPill } = await import('@vector-im/matrix-bot-sdk');

return replaceMessageMentions(message, INTERNAL_GENERAL_REGEX, () => MentionPill.forRoom(externalRoomId));
};
Expand Down Expand Up @@ -79,7 +79,7 @@ export const toExternalQuoteMessageFormat = async ({
message: string;
homeServerDomain: string;
}): Promise<{ message: string; formattedMessage: string }> => {
const { RichReply } = await import('@rocket.chat/forked-matrix-bot-sdk');
const { RichReply } = await import('@vector-im/matrix-bot-sdk');

const formattedMessage = convertMarkdownToHTML(message);
const finalFormattedMessage = convertMarkdownToHTML(
Expand Down
15 changes: 13 additions & 2 deletions apps/meteor/tests/data/permissions.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ const updateManyPermissions = (permissions: { [key: string]: string[] }): Promis
.end((err?: Error) => setTimeout(() => (!err && resolve()) || reject(err), 100));
});

export const updateSetting = (setting: string, value: ISetting['value']): Promise<void | Error> =>
export const updateSetting = (setting: string, value: ISetting['value'], debounce = true): Promise<void | Error> =>
new Promise((resolve, reject) => {
void request
.post(`/api/v1/settings/${setting}`)
.set(credentials)
.send({ value })
.expect('Content-Type', 'application/json')
.expect(200)
.end((err?: Error) => setTimeout(() => (!err && resolve()) || reject(err), 100));
.end((err?: Error) => {
if (err) {
return reject(err);
}

if (debounce) {
setTimeout(resolve, 100);
return;
}

resolve();
});
});

export const getSettingValueById = async (setting: string): Promise<ISetting['value']> => {
Expand Down
22 changes: 12 additions & 10 deletions apps/meteor/tests/end-to-end/api/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import { updateSetting } from '../../data/permissions.helper';
describe('federation', () => {
before((done) => getCredentials(done));

// FIXME: why debouncing is causing timeouts here on the hooks?
// Since we don't care about the watchers on this setting, not debouncing is fine.
describe('well-known', () => {
describe('when matrix disabled', () => {
before(async () => {
await updateSetting('Federation_Matrix_enabled', false);
await updateSetting('Federation_Matrix_serve_well_known', true);
await updateSetting('Federation_Matrix_enabled', false, false);
await updateSetting('Federation_Matrix_serve_well_known', true, false);
});

after(async () => {
await updateSetting('Federation_Matrix_serve_well_known', false);
await updateSetting('Federation_Matrix_serve_well_known', false, false);
});

it('should return 404 not found', async () => {
Expand All @@ -27,12 +29,12 @@ describe('federation', () => {

describe('when matrix enabled but well-known disabled', () => {
before(async () => {
await updateSetting('Federation_Matrix_enabled', true);
await updateSetting('Federation_Matrix_serve_well_known', false);
await updateSetting('Federation_Matrix_enabled', true, false);
await updateSetting('Federation_Matrix_serve_well_known', false, false);
});

after(async () => {
await updateSetting('Federation_Matrix_enabled', false);
await updateSetting('Federation_Matrix_enabled', false, false);
});

it('should return 404 not found', async () => {
Expand All @@ -44,13 +46,13 @@ describe('federation', () => {

describe('when enabled', () => {
before(async () => {
await updateSetting('Federation_Matrix_enabled', true);
await updateSetting('Federation_Matrix_serve_well_known', true);
await updateSetting('Federation_Matrix_enabled', true, false);
await updateSetting('Federation_Matrix_serve_well_known', true, false);
});

after(async () => {
await updateSetting('Federation_Matrix_enabled', false);
await updateSetting('Federation_Matrix_serve_well_known', false);
await updateSetting('Federation_Matrix_enabled', false, false);
await updateSetting('Federation_Matrix_serve_well_known', false, false);
});

it('should return matrix information', async () => {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"underscore": "1.13.7",
"lodash": "4.17.21",
"mongodb@^4.17.1": "patch:mongodb@npm:4.17.1#.yarn/patches/mongodb-npm-4.17.1-a2fe811ff1.patch",
"@rocket.chat/forked-matrix-sdk-crypto-nodejs": "0.1.0-beta.13",
"typia@~6.9.0": "patch:typia@npm%3A6.9.0#./.yarn/patches/typia-npm-6.9.0-2fd4d85f25.patch",
"moleculer@^0.14.34": "patch:moleculer@npm%3A0.14.34#./.yarn/patches/moleculer-npm-0.14.34-440e26767d.patch",
"mongodb@npm:^4.3.1": "patch:mongodb@npm%3A4.17.2#~/.yarn/patches/mongodb-npm-4.17.2-40d1286d70.patch"
Expand Down
Loading
Loading