From bda23a840e2909b2f2b3ce118e1a1be715334a53 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 3 Apr 2026 22:58:19 +0200 Subject: [PATCH] same durations --- backend/src/db/models/File.ts | 1 + .../graphql/resolvers/attachments/attachments.ts | 6 ++++-- backend/src/graphql/types/type/File.gql | 3 ++- webapp/components/Chat/Chat.vue | 15 +++++++++++++++ webapp/graphql/Messages.js | 5 +++-- webapp/graphql/Rooms.js | 6 ++++++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/backend/src/db/models/File.ts b/backend/src/db/models/File.ts index a247d1ac9..08e5e221f 100644 --- a/backend/src/db/models/File.ts +++ b/backend/src/db/models/File.ts @@ -2,6 +2,7 @@ export default { url: { primary: true, type: 'string', uri: { allowRelative: true } }, name: { type: 'string' }, type: { type: 'string' }, + duration: { type: 'number', allow: [null] }, createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, } diff --git a/backend/src/graphql/resolvers/attachments/attachments.ts b/backend/src/graphql/resolvers/attachments/attachments.ts index 37f381d5f..b9187d17d 100644 --- a/backend/src/graphql/resolvers/attachments/attachments.ts +++ b/backend/src/graphql/resolvers/attachments/attachments.ts @@ -29,12 +29,14 @@ export interface FileInput { upload?: Promise name: string type: string + duration?: number | null } export interface File { url: string name: string type: string + duration?: number | null } export interface Attachments { @@ -143,8 +145,8 @@ export const attachments = (config: S3Config) => { uniqueFilename, }) - const { name, type } = fileInput - const file = { url, name, type, ...fileAttributes } + const { name, type, duration } = fileInput + const file = { url, name, type, ...(duration != null && { duration }), ...fileAttributes } // const mimeType = uploadFile.mimetype.split('/')[0] // const nodeType = `Mime${mimeType.replace(/^./, mimeType[0].toUpperCase())}` // CREATE (file:${['File', nodeType].filter(Boolean).join(':')}) diff --git a/backend/src/graphql/types/type/File.gql b/backend/src/graphql/types/type/File.gql index 3bd7bd400..e48837096 100644 --- a/backend/src/graphql/types/type/File.gql +++ b/backend/src/graphql/types/type/File.gql @@ -2,9 +2,9 @@ type File { url: ID! name: String type: String + duration: Float # size: Int # audio: Boolean - # duration: Float # preview: String # progress: Int } @@ -13,4 +13,5 @@ input FileInput { upload: Upload name: String type: String + duration: Float } diff --git a/webapp/components/Chat/Chat.vue b/webapp/components/Chat/Chat.vue index dd20059e6..ef21aa0ce 100644 --- a/webapp/components/Chat/Chat.vue +++ b/webapp/components/Chat/Chat.vue @@ -314,6 +314,17 @@ export default { commitUnreadRoomCount: 'chat/UPDATE_ROOM_COUNT', }), + lastMessageFiles(files) { + if (!files?.length) return undefined + return files.map((f) => { + if (f.extension) return f + const dotIndex = f.name?.lastIndexOf('.') + const ext = dotIndex > 0 ? f.name.substring(dotIndex + 1) : f.type?.split('/').pop() + const name = dotIndex > 0 ? f.name.substring(0, dotIndex) : f.name + return { ...f, name, extension: ext } + }) + }, + markAsSeen(messageIds) { if (!messageIds.length || !this.selectedRoom) return const room = this.selectedRoom @@ -635,6 +646,7 @@ export default { changedRoom.lastMessage = { ...msg, content: (msg.content || '').trim().substring(0, 30), + files: this.lastMessageFiles(msg.files), } changedRoom.lastMessageAt = msg.date changedRoom.index = new Date().toISOString() @@ -713,6 +725,7 @@ export default { ), name: file.name, type: file.type, + ...(file.duration != null && { duration: file.duration }), })) : null @@ -742,6 +755,7 @@ export default { if (roomIndex !== -1) { const changedRoom = { ...this.rooms[roomIndex] } changedRoom.lastMessage.content = (content || '').trim().substring(0, 30) + changedRoom.lastMessage.files = this.lastMessageFiles(files) changedRoom.index = new Date().toISOString() this.rooms = [changedRoom, ...this.rooms.filter((r) => r.id !== roomId)] this.$nextTick(() => { @@ -827,6 +841,7 @@ export default { ? { ...room.lastMessage, content: (room.lastMessage?.content || '').trim().substring(0, 30), + files: this.lastMessageFiles(room.lastMessage?.files), } : { content: '' }, users: room.users.map((u) => { diff --git a/webapp/graphql/Messages.js b/webapp/graphql/Messages.js index 897cf65ab..62a4be336 100644 --- a/webapp/graphql/Messages.js +++ b/webapp/graphql/Messages.js @@ -26,6 +26,7 @@ export const createMessageMutation = () => { name #size type + duration #preview } } @@ -66,7 +67,7 @@ export const messageQuery = () => { #size type #audio - #duration + duration #preview } } @@ -101,7 +102,7 @@ export const chatMessageAdded = () => { #size type #audio - #duration + duration #preview } } diff --git a/webapp/graphql/Rooms.js b/webapp/graphql/Rooms.js index 944450b51..58f92295b 100644 --- a/webapp/graphql/Rooms.js +++ b/webapp/graphql/Rooms.js @@ -66,6 +66,12 @@ export const roomQuery = () => gql` saved distributed seen + files { + url + name + type + duration + } } users { _id