[FIX] Share extension doesn't reconnect to previous selected server on Android (#1429)
This commit is contained in:
parent
7b51df377d
commit
cd37a9b4ec
|
@ -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`;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -72,6 +72,7 @@ class Root extends React.Component {
|
|||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
RocketChat.closeShareExtension();
|
||||
unsubscribeTheme();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue