Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ee/packages/federation-matrix/src/FederationMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
15 changes: 13 additions & 2 deletions ee/packages/federation-matrix/src/events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function handleMediaMessage(
messageBody: string,
user: IUser,
room: IRoom,
matrixRoomId: string,
eventId: EventID,
tmid?: string,
): Promise<{
Expand All @@ -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,
Expand Down Expand Up @@ -226,7 +227,17 @@ export function message(emitter: Emitter<HomeserverEventSignatures>, 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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MatrixMediaService {
};
}

static async prepareLocalFileForMatrix(fileId: string, serverName: string): Promise<string> {
static async prepareLocalFileForMatrix(fileId: string, serverName: string, matrixRoomId: string): Promise<string> {
try {
const file = await Uploads.findOneById(fileId);
if (!file) {
Expand All @@ -53,6 +53,7 @@ export class MatrixMediaService {
const mxcUri = this.generateMXCUri(fileId, serverName);

await Uploads.setFederationInfo(fileId, {
mrid: matrixRoomId,
mxcUri,
serverName,
mediaId: fileId,
Expand Down Expand Up @@ -86,6 +87,7 @@ export class MatrixMediaService {

static async downloadAndStoreRemoteFile(
mxcUri: string,
matrixRoomId: string,
metadata: {
name: string;
size?: number;
Expand Down Expand Up @@ -131,6 +133,7 @@ export class MatrixMediaService {

await Uploads.setFederationInfo(uploadedFile._id, {
mxcUri,
mrid: matrixRoomId,
serverName: parts.serverName,
mediaId: parts.mediaId,
});
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/IUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface IUpload {
};
federation?: {
mxcUri: string;
mrid: string;
serverName: string;
mediaId: string;
};
Expand Down
Loading