diff --git a/ee/packages/federation-matrix/src/FederationMatrix.ts b/ee/packages/federation-matrix/src/FederationMatrix.ts index 18e3455c5be37..6e7e687da847e 100644 --- a/ee/packages/federation-matrix/src/FederationMatrix.ts +++ b/ee/packages/federation-matrix/src/FederationMatrix.ts @@ -428,7 +428,7 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS let lastEventId: { eventId: string } | null = null; for await (const file of message.files) { - const mxcUri = await MatrixMediaService.prepareLocalFileForMatrix(file._id, matrixDomain); + const mxcUri = await MatrixMediaService.prepareLocalFileForMatrix(file._id, matrixDomain, matrixRoomId); const msgtype = this.getMatrixMessageType(file.type); const fileContent = { diff --git a/ee/packages/federation-matrix/src/events/message.ts b/ee/packages/federation-matrix/src/events/message.ts index 84f266a5a16f7..93dd91856d766 100644 --- a/ee/packages/federation-matrix/src/events/message.ts +++ b/ee/packages/federation-matrix/src/events/message.ts @@ -29,6 +29,7 @@ async function handleMediaMessage( messageBody: string, user: IUser, room: IRoom, + matrixRoomId: string, eventId: EventID, tmid?: string, ): Promise<{ @@ -42,7 +43,7 @@ async function handleMediaMessage( const mimeType = fileInfo?.mimetype; const fileName = messageBody; - const fileRefId = await MatrixMediaService.downloadAndStoreRemoteFile(url, { + const fileRefId = await MatrixMediaService.downloadAndStoreRemoteFile(url, matrixRoomId, { name: messageBody, size: fileInfo?.size, type: mimeType, @@ -226,7 +227,17 @@ export function message(emitter: Emitter, serverName: const isMediaMessage = Object.values(fileTypes).includes(msgtype as FileMessageType); if (isMediaMessage && content.url) { - const result = await handleMediaMessage(content.url, content.info, msgtype, messageBody, user, room, data.event_id, thread?.tmid); + const result = await handleMediaMessage( + content.url, + content.info, + msgtype, + messageBody, + user, + room, + data.room_id, + data.event_id, + thread?.tmid, + ); await Message.saveMessageFromFederation(result); } else { const formatted = toInternalMessageFormat({ diff --git a/ee/packages/federation-matrix/src/services/MatrixMediaService.ts b/ee/packages/federation-matrix/src/services/MatrixMediaService.ts index 5e4761b1d35df..e19273f9e9a50 100644 --- a/ee/packages/federation-matrix/src/services/MatrixMediaService.ts +++ b/ee/packages/federation-matrix/src/services/MatrixMediaService.ts @@ -38,7 +38,7 @@ export class MatrixMediaService { }; } - static async prepareLocalFileForMatrix(fileId: string, serverName: string): Promise { + static async prepareLocalFileForMatrix(fileId: string, serverName: string, matrixRoomId: string): Promise { try { const file = await Uploads.findOneById(fileId); if (!file) { @@ -53,6 +53,7 @@ export class MatrixMediaService { const mxcUri = this.generateMXCUri(fileId, serverName); await Uploads.setFederationInfo(fileId, { + mrid: matrixRoomId, mxcUri, serverName, mediaId: fileId, @@ -86,6 +87,7 @@ export class MatrixMediaService { static async downloadAndStoreRemoteFile( mxcUri: string, + matrixRoomId: string, metadata: { name: string; size?: number; @@ -131,6 +133,7 @@ export class MatrixMediaService { await Uploads.setFederationInfo(uploadedFile._id, { mxcUri, + mrid: matrixRoomId, serverName: parts.serverName, mediaId: parts.mediaId, }); diff --git a/packages/core-typings/src/IUpload.ts b/packages/core-typings/src/IUpload.ts index 2eb5cf0741a73..e487151b94bf5 100644 --- a/packages/core-typings/src/IUpload.ts +++ b/packages/core-typings/src/IUpload.ts @@ -61,6 +61,7 @@ export interface IUpload { }; federation?: { mxcUri: string; + mrid: string; serverName: string; mediaId: string; };