tinode setup is async now

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