diff --git a/src/domain/fileUploadService.schema.ts b/src/domain/fileUploadService.schema.ts index 4575177..ff55d1c 100644 --- a/src/domain/fileUploadService.schema.ts +++ b/src/domain/fileUploadService.schema.ts @@ -41,5 +41,5 @@ export interface FileData { } export interface FileUploadProgressListener { - fileProgressUpdate: (fileId: string, allChunks: number, chunksDone: number) => void + fileProgressUpdate: (tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) => void } \ No newline at end of file diff --git a/src/services/dmService.test.ts b/src/services/dmService.test.ts index b12bc12..8d64613 100644 --- a/src/services/dmService.test.ts +++ b/src/services/dmService.test.ts @@ -23,7 +23,7 @@ describe("DmService", () => { it('should send a new message', async () => { const message = faker.internet.displayName() - const newMessage = await service.sendMessage(message) + const newMessage = await service.sendMessage("", message) expect(newMessage.message).toBe(message) }); }) \ No newline at end of file diff --git a/src/services/dmService.ts b/src/services/dmService.ts index 63c8cd2..b95c805 100644 --- a/src/services/dmService.ts +++ b/src/services/dmService.ts @@ -130,13 +130,14 @@ export class DMService { /** * Sends a new message to the chat + * @param tempMsgId * @param message * @param replyTo * @param replyToMessage * @param attachments * @param progressListener */ - async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise { + async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise { let uploadId = "" if (attachments) { const uploader = new FileUploadService(this.token) diff --git a/src/services/fileUploadService.ts b/src/services/fileUploadService.ts index e3e001a..4e71b5a 100644 --- a/src/services/fileUploadService.ts +++ b/src/services/fileUploadService.ts @@ -39,12 +39,13 @@ export class FileUploadService { /** * Automatically registers the upload, calculates chunksize and uploads each chunk and returns with an uploadId that must be provided when sending the message + * @param tempMsgId * @param roomId chatid or channelId * @param userid * @param files * @param listener */ - async uploadFiles(roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise { + async uploadFiles(tempMsgId: string, roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise { let registrations: FileUploadRegistration[] = []; files.forEach(file => { @@ -63,7 +64,7 @@ export class FileUploadService { files: registrations, }); for (let filesUploaded = 0; filesUploaded < files.length; filesUploaded++) { - await this.uploadFile(resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener) + await this.uploadFile(tempMsgId, resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener) } await this.finishUpload(roomId, userid, resp.data.uploadId) return resp.data.uploadId @@ -93,7 +94,7 @@ export class FileUploadService { } } - private async uploadFile(uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise { + private async uploadFile(tempMsgId: string, uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise { const chunkSize = this.calculateChunkSize(file.data.size); const totalChunks = Math.ceil(file.data.size / chunkSize); @@ -105,7 +106,7 @@ export class FileUploadService { const chunk = new Uint8Array(arrayBuffer.slice(start, end)); const base64 = this.uint8ToBase64(chunk); await this.uploadChunk(uploadId, roomId, userid, registration.fileId, base64); - listener.fileProgressUpdate(file.fileId, totalChunks, i) + listener.fileProgressUpdate(tempMsgId, file.fileId, totalChunks, i) } } diff --git a/src/services/textChannelService.ts b/src/services/textChannelService.ts index 97a6c5d..4725c3b 100644 --- a/src/services/textChannelService.ts +++ b/src/services/textChannelService.ts @@ -137,17 +137,18 @@ export class TextChannelServiceService { /** * Sends a new message to the chat + * @param tempMsgId * @param message * @param replyTo * @param replyToMessage * @param attachments * @param progressListener */ - async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise { + async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise { let uploadId = "" if (attachments) { const uploader = new FileUploadService(this.token) - uploadId = await uploader.uploadFiles(this.channelId, this.userid, attachments, progressListener!) + uploadId = await uploader.uploadFiles(tempMsgId, this.channelId, this.userid, attachments, progressListener!) } try { const resp = await this.client.post("network/channel/finishMessage", { diff --git a/tests/dmService.test.ts b/tests/dmService.test.ts index 2e9bdde..3212826 100644 --- a/tests/dmService.test.ts +++ b/tests/dmService.test.ts @@ -38,7 +38,7 @@ describe("DmService Integration Testing", () => { it('should send a message', async () => { const message = faker.lorem.paragraph() - const newMessage = await service.sendMessage(message) + const newMessage = await service.sendMessage("", message) expect(newMessage.message).toBe(message) }); diff --git a/tests/textChannelService.test.ts b/tests/textChannelService.test.ts index add901f..c3e657b 100644 --- a/tests/textChannelService.test.ts +++ b/tests/textChannelService.test.ts @@ -43,7 +43,7 @@ describe("DmService Integration Testing", () => { it('should send a message', async () => { const message = faker.lorem.paragraph() - const newMessage = await service.sendMessage(message) + const newMessage = await service.sendMessage("", message) expect(newMessage.message).toBe(message) });