diff --git a/app/lib/database/model/ThreadMessage.js b/app/lib/database/model/ThreadMessage.js index 0d2ad16bf..d2acd6a00 100644 --- a/app/lib/database/model/ThreadMessage.js +++ b/app/lib/database/model/ThreadMessage.js @@ -78,6 +78,8 @@ export default class ThreadMessage extends Model { @field('e2e') e2e; + @field('file_path') filePath; + asPlain() { return { id: this.id, @@ -112,7 +114,8 @@ export default class ThreadMessage extends Model { autoTranslate: this.autoTranslate, translations: this.translations, draftMessage: this.draftMessage, - e2e: this.e2e + e2e: this.e2e, + filePath: this.filePath }; } } diff --git a/app/lib/database/model/migrations.js b/app/lib/database/model/migrations.js index d8f4f9dc4..02ed08379 100644 --- a/app/lib/database/model/migrations.js +++ b/app/lib/database/model/migrations.js @@ -291,6 +291,10 @@ export default schemaMigrations({ addColumns({ table: 'messages', columns: [{ name: 'file_path', type: 'string', isOptional: true }] + }), + addColumns({ + table: 'thread_messages', + columns: [{ name: 'file_path', type: 'string', isOptional: true }] }) ] } diff --git a/app/lib/database/schema/app.js b/app/lib/database/schema/app.js index af2bffca4..1ec5f42c4 100644 --- a/app/lib/database/schema/app.js +++ b/app/lib/database/schema/app.js @@ -200,7 +200,8 @@ export default appSchema({ { name: 'unread', type: 'boolean', isOptional: true }, { name: 'auto_translate', type: 'boolean', isOptional: true }, { name: 'translations', type: 'string', isOptional: true }, - { name: 'e2e', type: 'string', isOptional: true } + { name: 'e2e', type: 'string', isOptional: true }, + { name: 'file_path', type: 'string', isOptional: true } ] }), tableSchema({ diff --git a/app/lib/methods/sendFileMessage.ts b/app/lib/methods/sendFileMessage.ts index 687cabcf3..af4ae5c96 100644 --- a/app/lib/methods/sendFileMessage.ts +++ b/app/lib/methods/sendFileMessage.ts @@ -198,8 +198,10 @@ const addTheFilePath = async (msgId: string, filePath: string, tmid?: string) => const msgCollection = db.get('messages'); try { const messageRecord = await msgCollection.find(msgId); - messageRecord.prepareUpdate(m => (m.filePath = filePath)); - } catch (e) { + await messageRecord.update(m => { + m.filePath = filePath; + }); + } catch { const msgSubscribe = msgCollection .query(Q.where('id', msgId)) .observe() @@ -214,8 +216,26 @@ const addTheFilePath = async (msgId: string, filePath: string, tmid?: string) => }); } - // if (tmid) { - // const threadMessagesCollection = db.get('thread_messages'); - - // } + if (tmid) { + const threadMessagesCollection = db.get('thread_messages'); + try { + const threadMessageRecord = await threadMessagesCollection.find(msgId); + await threadMessageRecord.update(m => { + m.filePath = filePath; + }); + } catch { + const threadMsgSubscribe = threadMessagesCollection + .query(Q.where('id', msgId)) + .observe() + .subscribe(async threadMessage => { + if (threadMessage.length > 0) { + const threadMessageRecord = threadMessage[0]; + await threadMessageRecord.update(m => { + m.filePath = filePath; + }); + threadMsgSubscribe.unsubscribe(); + } + }); + } + } }; \ No newline at end of file