[FIX] Share extension doesn't reconnect to previous selected server on Android (#1429)

This commit is contained in:
Diego Mello 2019-12-04 13:41:37 -03:00 committed by GitHub
parent 7b51df377d
commit cd37a9b4ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 9 deletions

View File

@ -44,13 +44,44 @@ class DB {
} }
get active() { 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() { get servers() {
return this.databases.serversDB; 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 = '') { setActiveDB(database = '') {
const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//, '.'); const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//, '.');
const dbName = `${ appGroupPath }${ path }.db`; const dbName = `${ appGroupPath }${ path }.db`;

View File

@ -10,8 +10,9 @@ export async function sendMessageCall(message) {
id: _id, subscription: { id: rid }, msg, tmid id: _id, subscription: { id: rid }, msg, tmid
} = message; } = message;
try { try {
const sdk = this.shareSDK || this.sdk;
// RC 0.60.0 // RC 0.60.0
await this.sdk.post('chat.sendMessage', { await sdk.post('chat.sendMessage', {
message: { message: {
_id, rid, msg, tmid _id, rid, msg, tmid
} }

View File

@ -259,17 +259,17 @@ const RocketChat = {
}, },
async shareExtensionInit(server) { async shareExtensionInit(server) {
database.setActiveDB(server); database.setShareDB(server);
if (this.sdk) { if (this.shareSDK) {
this.sdk.disconnect(); this.shareSDK.disconnect();
this.sdk = null; this.shareSDK = null;
} }
// Use useSsl: false only if server url starts with http:// // Use useSsl: false only if server url starts with http://
const useSsl = !/http:\/\//.test(server); 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 // set Server
const serversDB = database.servers; const serversDB = database.servers;
@ -298,6 +298,13 @@ const RocketChat = {
log(e); log(e);
} }
}, },
closeShareExtension() {
if (this.shareSDK) {
this.shareSDK.disconnect();
this.shareSDK = null;
}
database.share = null;
},
updateJitsiTimeout(rid) { updateJitsiTimeout(rid) {
return this.sdk.methodCall('jitsi:updateTimeout', rid); return this.sdk.methodCall('jitsi:updateTimeout', rid);
@ -363,9 +370,10 @@ const RocketChat = {
async login(params) { async login(params) {
try { try {
const sdk = this.shareSDK || this.sdk;
// RC 0.64.0 // RC 0.64.0
await this.sdk.login(params); await sdk.login(params);
const { result } = this.sdk.currentLogin; const { result } = sdk.currentLogin;
const user = { const user = {
id: result.userId, id: result.userId,
token: result.authToken, token: result.authToken,

View File

@ -72,6 +72,7 @@ class Root extends React.Component {
} }
componentWillUnmount() { componentWillUnmount() {
RocketChat.closeShareExtension();
unsubscribeTheme(); unsubscribeTheme();
} }