Skip to content

Commit

Permalink
Merge pull request #34 from alkem-io/matrixClientParams
Browse files Browse the repository at this point in the history
additional startup params
  • Loading branch information
valentinyanakiev authored Jul 3, 2024
2 parents 1e935d3 + 3d2261b commit b157c3c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions service/matrix-adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ matrix:
client:
# The URL of the timeline support client
timelineSupport: ${MATRIX_CLIENT_TIMELINE_SUPPORT}:true
# The polling timeout of the timeline support client
startupPollTimeout: ${MATRIX_CLIENT_STARTUP_POLL_TIMEOUT}:100000
# The polling timeout of the timeline support client
startupInitialSyncLimit: ${MATRIX_CLIENT_STARTUP_SYNC_LIMIT}:20

admin:
# The admin account that is created / used to administer the regular users on the Synapse server
Expand Down
2 changes: 1 addition & 1 deletion service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-matrix-adapter",
"version": "0.3.3",
"version": "0.3.4",
"description": "Alkemio Matrix Adapter service",
"author": "Alkemio Foundation",
"private": false,
Expand Down
6 changes: 6 additions & 0 deletions service/src/services/matrix/agent/matrix.agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class MatrixAgentService {
matrixClient,
this.matrixRoomAdapter,
this.matrixMessageAdapter,
this.configService,
this.logger
);
}
Expand All @@ -59,6 +60,11 @@ export class MatrixAgentService {
const timelineSupport: boolean = this.configService.get(
ConfigurationTypes.MATRIX
)?.client.timelineSupport;

this.logger.verbose?.(
`Creating Matrix Client for ${operator.username} using timeline flag: ${timelineSupport}`,
LogContext.MATRIX
);
const createClientInput: ICreateClientOpts = {
baseUrl: baseUrl,
idBaseUrl: idBaseUrl,
Expand Down
30 changes: 27 additions & 3 deletions service/src/services/matrix/agent/matrix.agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogContext } from '@common/enums';
import { ConfigurationTypes, LogContext } from '@common/enums';
import { LoggerService } from '@nestjs/common';
import {
autoAcceptRoomGuardFactory,
Expand All @@ -17,7 +17,8 @@ import { MatrixMessageAdapter } from '../adapter-message/matrix.message.adapter'
import { MatrixRoomAdapter } from '../adapter-room/matrix.room.adapter';
import { IMatrixAgent } from './matrix.agent.interface';
import { Disposable } from '@src/common/interfaces/disposable.interface';
import { MatrixClient } from 'matrix-js-sdk';
import { MatrixClient, IStartClientOpts } from 'matrix-js-sdk';
import { ConfigService } from '@nestjs/config';

export type MatrixAgentStartOptions = {
registerTimelineMonitor?: boolean;
Expand All @@ -30,17 +31,20 @@ export class MatrixAgent implements IMatrixAgent, Disposable {
eventDispatcher: MatrixEventDispatcher;
roomAdapter: MatrixRoomAdapter;
messageAdapter: MatrixMessageAdapter;
configService: ConfigService;

constructor(
matrixClient: MatrixClient,
roomAdapter: MatrixRoomAdapter,
messageAdapter: MatrixMessageAdapter,
configService: ConfigService,
private logger: LoggerService
) {
this.matrixClient = matrixClient;
this.eventDispatcher = new MatrixEventDispatcher(this.matrixClient);
this.roomAdapter = roomAdapter;
this.messageAdapter = messageAdapter;
this.configService = configService;
}

attach(handler: IMatrixEventHandler) {
Expand Down Expand Up @@ -77,7 +81,27 @@ export class MatrixAgent implements IMatrixAgent, Disposable {
);
});

await this.matrixClient.startClient({});
const pollTimeout = Number(
this.configService.get(ConfigurationTypes.MATRIX)?.client
.startupPollTimeout
);

const initialSyncLimit = Number(
this.configService.get(ConfigurationTypes.MATRIX)?.client
.startupInitialSyncLimit
);

this.logger.verbose?.(
`starting up with pollTimeout: ${pollTimeout} and initialSyncLimit: ${initialSyncLimit}`,
LogContext.MATRIX
);

const startClientOptions: IStartClientOpts = {
disablePresence: true,
initialSyncLimit: initialSyncLimit,
pollTimeout: pollTimeout,
};
await this.matrixClient.startClient(startClientOptions);
await startComplete;

const eventHandler: IMatrixEventHandler = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class MatrixUserManagementService {
const timelineSupport: boolean = this.configService.get(
ConfigurationTypes.MATRIX
)?.client.timelineSupport;
this.logger.verbose?.(
`Creating Matrix Client for management using timeline flag: ${timelineSupport}`,
LogContext.MATRIX
);
const createClientInput: ICreateClientOpts = {
baseUrl: this.baseUrl,
idBaseUrl: this.idBaseUrl,
Expand Down

0 comments on commit b157c3c

Please sign in to comment.