tinode setup is async now
This commit is contained in:
@@ -230,8 +230,8 @@ class InfoView extends React.Component {
|
||||
avatar: makeImageUrl(topic.public ? topic.public.photo : null),
|
||||
private: topic.private ? topic.private.comment : null,
|
||||
address: topic.name,
|
||||
groupTopic: (topic.getType() == 'grp'),
|
||||
channel: topic.isChannel(),
|
||||
groupTopic: topic.isGroupType(),
|
||||
channel: topic.isChannelType(),
|
||||
showMemberPanel: false,
|
||||
access: acs ? acs.getMode() : undefined,
|
||||
modeGiven: acs ? acs.getGiven() : undefined,
|
||||
|
||||
@@ -276,7 +276,7 @@ class MessagesView extends React.Component {
|
||||
});
|
||||
}
|
||||
Object.assign(nextState, {
|
||||
channel: topic.isChannel()
|
||||
channel: topic.isChannelType()
|
||||
});
|
||||
} else {
|
||||
// Invalid topic.
|
||||
@@ -597,7 +597,7 @@ class MessagesView extends React.Component {
|
||||
const menuItems = messageSpecificMenuItems || [];
|
||||
const topic = this.props.tinode.getTopic(params.topicName);
|
||||
if (topic) {
|
||||
if (!topic.isChannel()) {
|
||||
if (!topic.isChannelType()) {
|
||||
menuItems.push('message_delete');
|
||||
}
|
||||
const acs = topic.getAccessMode();
|
||||
@@ -817,8 +817,8 @@ class MessagesView extends React.Component {
|
||||
);
|
||||
} else {
|
||||
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||
const isChannel = topic.isChannel();
|
||||
const groupTopic = topic.getType() == 'grp' && !isChannel;
|
||||
const isChannel = topic.isChannelType();
|
||||
const groupTopic = topic.isGroupType() && !isChannel;
|
||||
let messageNodes = [];
|
||||
let previousFrom = null;
|
||||
let chatBoxClass = null;
|
||||
|
||||
@@ -215,11 +215,12 @@ class TinodeWeb extends React.Component {
|
||||
const keepLoggedIn = LocalStorageUtil.getObject('keep-logged-in');
|
||||
|
||||
const {formatMessage, locale} = this.props.intl;
|
||||
this.tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport, locale, keepLoggedIn);
|
||||
new Promise((resolve, reject) => {
|
||||
this.tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport, locale, keepLoggedIn, resolve);
|
||||
this.tinode.onConnect = this.handleConnected;
|
||||
this.tinode.onDisconnect = this.handleDisconnect;
|
||||
this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration;
|
||||
|
||||
}).then(() => {
|
||||
// Initialize desktop alerts.
|
||||
if (this.state.desktopAlertsEnabled) {
|
||||
try {
|
||||
@@ -273,6 +274,7 @@ class TinodeWeb extends React.Component {
|
||||
this.readTimerCallback = null;
|
||||
|
||||
this.handleHashRoute();
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@@ -282,9 +284,9 @@ class TinodeWeb extends React.Component {
|
||||
}
|
||||
|
||||
// Setup transport (usually websocket) and server address. This will terminate connection with the server.
|
||||
static tnSetup(serverAddress, transport, locale, persist) {
|
||||
static tnSetup(serverAddress, transport, locale, persistentCache, onSetupCompleted) {
|
||||
const tinode = new Tinode({appName: APP_NAME, host: serverAddress, apiKey: API_KEY, transport: transport,
|
||||
secure: isSecureConnection(), persist: persist});
|
||||
secure: isSecureConnection(), persist: persistentCache}, onSetupCompleted);
|
||||
tinode.setHumanLanguage(locale);
|
||||
tinode.enableLogging(LOGGING_ENABLED, true);
|
||||
return tinode;
|
||||
@@ -483,7 +485,6 @@ class TinodeWeb extends React.Component {
|
||||
|
||||
if (promise) {
|
||||
promise.then((ctrl) => {
|
||||
console.log("doLogin->then", ctrl);
|
||||
if (ctrl.code >= 300 && ctrl.text === 'validate credentials') {
|
||||
this.setState({loadSpinnerVisible: false});
|
||||
if (cred) {
|
||||
@@ -819,7 +820,7 @@ class TinodeWeb extends React.Component {
|
||||
// Accept given permissions.
|
||||
const mode = topic.getAccessMode().getGiven();
|
||||
response = topic.setMeta({sub: {mode: mode}});
|
||||
if (topic.isP2P()) {
|
||||
if (topic.isP2PType()) {
|
||||
// For P2P topics change 'given' permission of the peer too.
|
||||
// In p2p topics the other user has the same name as the topic.
|
||||
response = response.then((ctrl) => {
|
||||
@@ -927,10 +928,12 @@ class TinodeWeb extends React.Component {
|
||||
const serverAddress = settings.serverAddress || this.state.serverAddress;
|
||||
const transport = settings.transport || this.state.transport;
|
||||
if (this.tinode) {
|
||||
this.tinode.clearStorage();
|
||||
this.tinode.onDisconnect = undefined;
|
||||
this.tinode.disconnect();
|
||||
}
|
||||
this.tinode = TinodeWeb.tnSetup(serverAddress, transport, this.props.intl.locale);
|
||||
this.tinode = TinodeWeb.tnSetup(serverAddress, transport, this.props.intl.locale,
|
||||
LocalStorageUtil.getObject('keep-logged-in'));
|
||||
this.tinode.onConnect = this.handleConnected;
|
||||
this.tinode.onDisconnect = this.handleDisconnect;
|
||||
|
||||
|
||||
+16
-15
@@ -2060,8 +2060,8 @@ class InfoView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
avatar: (0,_lib_blob_helpers_js__WEBPACK_IMPORTED_MODULE_14__.makeImageUrl)(topic.public ? topic.public.photo : null),
|
||||
private: topic.private ? topic.private.comment : null,
|
||||
address: topic.name,
|
||||
groupTopic: topic.getType() == 'grp',
|
||||
channel: topic.isChannel(),
|
||||
groupTopic: topic.isGroupType(),
|
||||
channel: topic.isChannelType(),
|
||||
showMemberPanel: false,
|
||||
access: acs ? acs.getMode() : undefined,
|
||||
modeGiven: acs ? acs.getGiven() : undefined,
|
||||
@@ -3095,7 +3095,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
||||
}
|
||||
|
||||
Object.assign(nextState, {
|
||||
channel: topic.isChannel()
|
||||
channel: topic.isChannelType()
|
||||
});
|
||||
} else {
|
||||
Object.assign(nextState, {
|
||||
@@ -3452,7 +3452,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
||||
const topic = this.props.tinode.getTopic(params.topicName);
|
||||
|
||||
if (topic) {
|
||||
if (!topic.isChannel()) {
|
||||
if (!topic.isChannelType()) {
|
||||
menuItems.push('message_delete');
|
||||
}
|
||||
|
||||
@@ -3659,8 +3659,8 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
||||
});
|
||||
} else {
|
||||
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||
const isChannel = topic.isChannel();
|
||||
const groupTopic = topic.getType() == 'grp' && !isChannel;
|
||||
const isChannel = topic.isChannelType();
|
||||
const groupTopic = topic.isGroupType() && !isChannel;
|
||||
let messageNodes = [];
|
||||
let previousFrom = null;
|
||||
let chatBoxClass = null;
|
||||
@@ -4716,11 +4716,12 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
formatMessage,
|
||||
locale
|
||||
} = this.props.intl;
|
||||
this.tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport, locale, keepLoggedIn);
|
||||
new Promise((resolve, reject) => {
|
||||
this.tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport, locale, keepLoggedIn, resolve);
|
||||
this.tinode.onConnect = this.handleConnected;
|
||||
this.tinode.onDisconnect = this.handleDisconnect;
|
||||
this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration;
|
||||
|
||||
}).then(() => {
|
||||
if (this.state.desktopAlertsEnabled) {
|
||||
try {
|
||||
this.fbPush = firebase_app__WEBPACK_IMPORTED_MODULE_3__.initializeApp(FIREBASE_INIT, _config_js__WEBPACK_IMPORTED_MODULE_11__.APP_NAME).messaging();
|
||||
@@ -4777,6 +4778,7 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
this.readTimer = null;
|
||||
this.readTimerCallback = null;
|
||||
this.handleHashRoute();
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@@ -4785,15 +4787,15 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
document.removeEventListener('visibilitychange', this.handleVisibilityEvent);
|
||||
}
|
||||
|
||||
static tnSetup(serverAddress, transport, locale, persist) {
|
||||
static tnSetup(serverAddress, transport, locale, persistentCache, onSetupCompleted) {
|
||||
const tinode = new (tinode_sdk__WEBPACK_IMPORTED_MODULE_5___default())({
|
||||
appName: _config_js__WEBPACK_IMPORTED_MODULE_11__.APP_NAME,
|
||||
host: serverAddress,
|
||||
apiKey: _config_js__WEBPACK_IMPORTED_MODULE_11__.API_KEY,
|
||||
transport: transport,
|
||||
secure: (0,_lib_host_name_js__WEBPACK_IMPORTED_MODULE_13__.isSecureConnection)(),
|
||||
persist: persist
|
||||
});
|
||||
persist: persistentCache
|
||||
}, onSetupCompleted);
|
||||
tinode.setHumanLanguage(locale);
|
||||
tinode.enableLogging(_config_js__WEBPACK_IMPORTED_MODULE_11__.LOGGING_ENABLED, true);
|
||||
return tinode;
|
||||
@@ -5015,8 +5017,6 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
|
||||
if (promise) {
|
||||
promise.then(ctrl => {
|
||||
console.log("doLogin->then", ctrl);
|
||||
|
||||
if (ctrl.code >= 300 && ctrl.text === 'validate credentials') {
|
||||
this.setState({
|
||||
loadSpinnerVisible: false
|
||||
@@ -5329,7 +5329,7 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
}
|
||||
});
|
||||
|
||||
if (topic.isP2P()) {
|
||||
if (topic.isP2PType()) {
|
||||
response = response.then(ctrl => {
|
||||
topic.setMeta({
|
||||
sub: {
|
||||
@@ -5450,11 +5450,12 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
||||
const transport = settings.transport || this.state.transport;
|
||||
|
||||
if (this.tinode) {
|
||||
this.tinode.clearStorage();
|
||||
this.tinode.onDisconnect = undefined;
|
||||
this.tinode.disconnect();
|
||||
}
|
||||
|
||||
this.tinode = TinodeWeb.tnSetup(serverAddress, transport, this.props.intl.locale);
|
||||
this.tinode = TinodeWeb.tnSetup(serverAddress, transport, this.props.intl.locale, _lib_local_storage_js__WEBPACK_IMPORTED_MODULE_14__.default.getObject('keep-logged-in'));
|
||||
this.tinode.onConnect = this.handleConnected;
|
||||
this.tinode.onDisconnect = this.handleDisconnect;
|
||||
this.setState({
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+77
-34
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user