diff --git a/app/lib/database/index.js b/app/lib/database/index.js index b385a9b63..1508d11fc 100644 --- a/app/lib/database/index.js +++ b/app/lib/database/index.js @@ -44,13 +44,44 @@ class DB { } get active() { - return this.databases.activeDB; + return this.databases.shareDB || this.databases.activeDB; + } + + get share() { + return this.databases.shareDB; + } + + set share(db) { + this.databases.shareDB = db; } get servers() { return this.databases.serversDB; } + setShareDB(database = '') { + const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//, '.'); + const dbName = `${ appGroupPath }${ path }.db`; + + const adapter = new SQLiteAdapter({ + dbName, + schema: appSchema, + migrations + }); + + this.databases.shareDB = new Database({ + adapter, + modelClasses: [ + Subscription, + Message, + Thread, + ThreadMessage, + Upload + ], + actionsEnabled: true + }); + } + setActiveDB(database = '') { const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//, '.'); const dbName = `${ appGroupPath }${ path }.db`; diff --git a/app/lib/methods/sendMessage.js b/app/lib/methods/sendMessage.js index bd383bd5d..7b9e341ec 100644 --- a/app/lib/methods/sendMessage.js +++ b/app/lib/methods/sendMessage.js @@ -10,8 +10,9 @@ export async function sendMessageCall(message) { id: _id, subscription: { id: rid }, msg, tmid } = message; try { + const sdk = this.shareSDK || this.sdk; // RC 0.60.0 - await this.sdk.post('chat.sendMessage', { + await sdk.post('chat.sendMessage', { message: { _id, rid, msg, tmid } diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index e7d2061fc..fb79d6b45 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -259,17 +259,17 @@ const RocketChat = { }, async shareExtensionInit(server) { - database.setActiveDB(server); + database.setShareDB(server); - if (this.sdk) { - this.sdk.disconnect(); - this.sdk = null; + if (this.shareSDK) { + this.shareSDK.disconnect(); + this.shareSDK = null; } // Use useSsl: false only if server url starts with http:// const useSsl = !/http:\/\//.test(server); - this.sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl }); + this.shareSDK = new RocketchatClient({ host: server, protocol: 'ddp', useSsl }); // set Server const serversDB = database.servers; @@ -298,6 +298,13 @@ const RocketChat = { log(e); } }, + closeShareExtension() { + if (this.shareSDK) { + this.shareSDK.disconnect(); + this.shareSDK = null; + } + database.share = null; + }, updateJitsiTimeout(rid) { return this.sdk.methodCall('jitsi:updateTimeout', rid); @@ -363,9 +370,10 @@ const RocketChat = { async login(params) { try { + const sdk = this.shareSDK || this.sdk; // RC 0.64.0 - await this.sdk.login(params); - const { result } = this.sdk.currentLogin; + await sdk.login(params); + const { result } = sdk.currentLogin; const user = { id: result.userId, token: result.authToken, diff --git a/app/share.js b/app/share.js index 0266ba16a..3d2484a7d 100644 --- a/app/share.js +++ b/app/share.js @@ -72,6 +72,7 @@ class Root extends React.Component { } componentWillUnmount() { + RocketChat.closeShareExtension(); unsubscribeTheme(); }