partially updated Tinode from a global object to a state one

This commit is contained in:
or-else
2018-09-05 18:56:01 +03:00
parent aafa0f74d5
commit 5e0713fb3e
2 changed files with 98 additions and 96 deletions
+1
View File
@@ -41,6 +41,7 @@
<!-- the application --> <!-- the application -->
<script type="text/babel" src="src/webapp.js"></script> <script type="text/babel" src="src/webapp.js"></script>
<script type="text/babel"> <script type="text/babel">
console.log(Tinode);
ReactDOM.render( ReactDOM.render(
<TinodeWeb />, <TinodeWeb />,
document.getElementById('mountPoint') document.getElementById('mountPoint')
+97 -96
View File
@@ -342,6 +342,10 @@ function parseUrlHash(hash) {
return {path: path, params: params}; return {path: path, params: params};
} }
function navigateTo(url) {
window.location.hash = url;
}
function composeUrlHash(path, params) { function composeUrlHash(path, params) {
var url = path.join("/"); var url = path.join("/");
var args = []; var args = [];
@@ -2513,24 +2517,24 @@ class NewTopicView extends React.Component {
handleTabClick(e) { handleTabClick(e) {
e.preventDefault(); e.preventDefault();
window.location.hash = addUrlParam(window.location.hash, 'tab', e.currentTarget.dataset.id); navigateTo(addUrlParam(window.location.hash, 'tab', e.currentTarget.dataset.id));
this.setState({tabSelected: e.currentTarget.dataset.id}); this.setState({tabSelected: e.currentTarget.dataset.id});
} }
handleContactSelected(sel) { handleContactSelected(sel) {
if (this.state.tabSelected === "p2p") { if (this.state.tabSelected === "p2p") {
window.location.hash = removeUrlParam(window.location.hash, 'tab'); navigateTo(removeUrlParam(window.location.hash, 'tab'));
this.props.onCreateTopic(sel, undefined); this.props.onCreateTopic(sel, undefined);
} }
} }
handleNewGroupSubmit(name, dataUrl, priv, tags) { handleNewGroupSubmit(name, dataUrl, priv, tags) {
window.location.hash = removeUrlParam(window.location.hash, 'tab'); navigateTo(removeUrlParam(window.location.hash, 'tab'));
this.props.onCreateTopic(undefined, vcard(name, dataUrl), priv, tags); this.props.onCreateTopic(undefined, vcard(name, dataUrl), priv, tags);
} }
handleGroupByID(topicName) { handleGroupByID(topicName) {
window.location.hash = removeUrlParam(window.location.hash, 'tab'); navigateTo(removeUrlParam(window.location.hash, 'tab'));
this.props.onCreateTopic(topicName); this.props.onCreateTopic(topicName);
} }
@@ -4385,6 +4389,7 @@ class TinodeWeb extends React.Component {
let settings = localStorage.getObject("settings") || {}; let settings = localStorage.getObject("settings") || {};
return { return {
tinode: null,
connected: false, connected: false,
transport: settings.transport || null, transport: settings.transport || null,
serverAddress: settings.serverAddress || detectServerAddress(), serverAddress: settings.serverAddress || detectServerAddress(),
@@ -4425,20 +4430,22 @@ class TinodeWeb extends React.Component {
} }
componentDidMount() { componentDidMount() {
var instance = this;
window.addEventListener('resize', this.handleResize); window.addEventListener('resize', this.handleResize);
window.addEventListener('online', function(e) { instance.handleOnline(true); }); window.addEventListener('online', (e) => { this.handleOnline(true); });
window.addEventListener('offline', function(e) { instance.handleOnline(false); }); window.addEventListener('offline', (e) => { this.handleOnline(false); });
window.addEventListener('hashchange', this.handleHashRoute); window.addEventListener('hashchange', this.handleHashRoute);
// Window/tab visible or invisible for pausing timers. // Window/tab visible or invisible for pausing timers.
document.addEventListener("visibilitychange", this.handleVisibilityEvent); document.addEventListener("visibilitychange", this.handleVisibilityEvent);
this.setState({viewportWidth: document.documentElement.clientWidth}); this.setState({viewportWidth: document.documentElement.clientWidth});
Tinode.enableLogging(true, true); let tinode = TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport);
Tinode.onConnect = this.handleConnected;
Tinode.onDisconnect = this.handleDisconnect; this.setState({tinode: tinode});
TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport);
tinode.enableLogging(true, true);
tinode.onConnect = this.handleConnected;
tinode.onDisconnect = this.handleDisconnect;
var token; var token;
if (localStorage.getObject("keep-logged-in")) { if (localStorage.getObject("keep-logged-in")) {
token = localStorage.getObject("auth-token"); token = localStorage.getObject("auth-token");
@@ -4446,18 +4453,18 @@ class TinodeWeb extends React.Component {
if (token) { if (token) {
// When reading from storage, date is returned as string. // When reading from storage, date is returned as string.
token.expires = new Date(token.expires); token.expires = new Date(token.expires);
Tinode.setAuthToken(token); tinode.setAuthToken(token);
Tinode.connect().catch(function(err) { tinode.connect().catch((err) => {
// Socket error // Socket error
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
var parsed = parseUrlHash(window.location.hash); var parsed = parseUrlHash(window.location.hash);
delete parsed.params.info; delete parsed.params.info;
delete parsed.params.tab; delete parsed.params.tab;
parsed.path[0] = ''; parsed.path[0] = '';
window.location.hash = composeUrlHash(parsed.path, parsed.params); navigateTo(composeUrlHash(parsed.path, parsed.params));
} else { } else {
window.location.hash = ""; navigateTo("");
} }
this.readTimer = null; this.readTimer = null;
this.readTimerCallback = null; this.readTimerCallback = null;
@@ -4471,7 +4478,7 @@ 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) { static tnSetup(serverAddress, transport) {
Tinode.setup(APP_NAME, serverAddress, API_KEY, transport); return new Tinode(APP_NAME, serverAddress, API_KEY, transport, isSecureConnection());
} }
handleResize() { handleResize() {
@@ -4498,7 +4505,7 @@ class TinodeWeb extends React.Component {
} }
// Topic for MessagesView selector. // Topic for MessagesView selector.
if (hash.path.length > 1 && hash.path[1] != this.state.topicSelected) { if (hash.path.length > 1 && hash.path[1] != this.state.topicSelected) {
var tp = Tinode.topicType(hash.path[1]); var tp = this.state.tinode.topicType(hash.path[1]);
if (tp) { if (tp) {
this.setState({ this.setState({
topicSelected: hash.path[1], topicSelected: hash.path[1],
@@ -4564,10 +4571,10 @@ class TinodeWeb extends React.Component {
this.setState({loginDisabled: true, login: login, password: password}); this.setState({loginDisabled: true, login: login, password: password});
this.handleError("", null); this.handleError("", null);
if (Tinode.isConnected()) { if (this.state.tinode.isConnected()) {
this.doLogin(login, password, {meth: this.state.credMethod, resp: this.state.credCode}); this.doLogin(login, password, {meth: this.state.credMethod, resp: this.state.credCode});
} else { } else {
Tinode.connect().catch((err) => { this.state.tinode.connect().catch((err) => {
// Socket error // Socket error
this.setState({loginDisabled: false}); this.setState({loginDisabled: false});
this.handleError(err.message, "err"); this.handleError(err.message, "err");
@@ -4577,7 +4584,7 @@ class TinodeWeb extends React.Component {
// Connection succeeded. // Connection succeeded.
handleConnected() { handleConnected() {
var params = Tinode.getServerInfo(); var params = this.state.tinode.getServerInfo();
this.setState({ this.setState({
serverVersion: params.ver + " " + (params.build ? params.build : "none") + "; " serverVersion: params.ver + " " + (params.build ? params.build : "none") + "; "
}); });
@@ -4585,23 +4592,23 @@ class TinodeWeb extends React.Component {
} }
doLogin(login, password, cred) { doLogin(login, password, cred) {
if (Tinode.isAuthenticated()) { if (this.state.tinode.isAuthenticated()) {
// Already logged in. Go to default screen. // Already logged in. Go to default screen.
window.location.hash = ""; navigateTo("");
return; return;
} }
cred = cred ? Tinode.addCredential(null, cred) : undefined; cred = cred ? this.state.tinode.addCredential(null, cred) : undefined;
cred = cred ? cred.cred : undefined; cred = cred ? cred.cred : undefined;
// Try to login with login/password. If they are not available, try token. If no token, ask for login/password. // Try to login with login/password. If they are not available, try token. If no token, ask for login/password.
let promise = null; let promise = null;
let token = Tinode.getAuthToken(); let token = this.state.tinode.getAuthToken();
if (login && password) { if (login && password) {
this.setState({password: null}); this.setState({password: null});
promise = Tinode.loginBasic(login, password, cred); promise = this.state.tinode.loginBasic(login, password, cred);
} else if (token) { } else if (token) {
promise = Tinode.loginToken(token.token, cred); promise = this.state.tinode.loginToken(token.token, cred);
} }
if (promise) { if (promise) {
@@ -4619,12 +4626,12 @@ class TinodeWeb extends React.Component {
this.setState({loginDisabled: false, credMethod: undefined, credCode: undefined}); this.setState({loginDisabled: false, credMethod: undefined, credCode: undefined});
this.handleError(err.message, "err"); this.handleError(err.message, "err");
localStorage.removeItem("auth-token"); localStorage.removeItem("auth-token");
window.location.hash = ""; navigateTo("");
}); });
} else { } else {
// No login credentials provided. // No login credentials provided.
// Make sure we are on the login page. // Make sure we are on the login page.
window.location.hash = ""; navigateTo("");
this.setState({loginDisabled: false}); this.setState({loginDisabled: false});
} }
} }
@@ -4633,7 +4640,7 @@ class TinodeWeb extends React.Component {
var parsed = parseUrlHash(window.location.hash); var parsed = parseUrlHash(window.location.hash);
parsed.path[0] = 'cred'; parsed.path[0] = 'cred';
parsed.params['method'] = params.cred[0]; parsed.params['method'] = params.cred[0];
window.location.hash = composeUrlHash(parsed.path, parsed.params); navigateTo(composeUrlHash(parsed.path, parsed.params));
} }
handleLoginSuccessful(instance) { handleLoginSuccessful(instance) {
@@ -4641,16 +4648,16 @@ class TinodeWeb extends React.Component {
// Refresh authentication token. // Refresh authentication token.
if (localStorage.getObject("keep-logged-in")) { if (localStorage.getObject("keep-logged-in")) {
localStorage.setObject("auth-token", Tinode.getAuthToken()); localStorage.setObject("auth-token", this.state.tinode.getAuthToken());
} }
// Logged in fine, subscribe to 'me' attaching callbacks from the contacts view. // Logged in fine, subscribe to 'me' attaching callbacks from the contacts view.
var me = Tinode.getMeTopic(); var me = this.state.tinode.getMeTopic();
me.onMetaDesc = instance.tnMeMetaDesc; me.onMetaDesc = instance.tnMeMetaDesc;
instance.setState({ instance.setState({
connected: true, connected: true,
credMethod: undefined, credMethod: undefined,
credCode: undefined, credCode: undefined,
myUserId: Tinode.getCurrentUserID() myUserId: this.state.tinode.getCurrentUserID()
}); });
// Subscribe, fetch topic desc, the list of subscriptions. Messages are not fetched. // Subscribe, fetch topic desc, the list of subscriptions. Messages are not fetched.
me.subscribe( me.subscribe(
@@ -4661,9 +4668,9 @@ class TinodeWeb extends React.Component {
).catch(function(err){ ).catch(function(err){
localStorage.removeItem("auth-token"); localStorage.removeItem("auth-token");
instance.handleError(err.message, "err"); instance.handleError(err.message, "err");
window.location.hash = ""; navigateTo("");
}); });
window.location.hash = setUrlSidePanel(window.location.hash, 'contacts'); navigateTo(setUrlSidePanel(window.location.hash, 'contacts'));
} }
handleDisconnect(err) { handleDisconnect(err) {
@@ -4690,8 +4697,8 @@ class TinodeWeb extends React.Component {
// Sending "received" notifications // Sending "received" notifications
tnData(data) { tnData(data) {
let topic = Tinode.getTopic(data.topic); let topic = this.state.tinode.getTopic(data.topic);
if (topic.msgStatus(data) > Tinode.MESSAGE_STATUS_SENDING) { if (topic.msgStatus(data) > this.state.tinode.MESSAGE_STATUS_SENDING) {
clearTimeout(this.receivedTimer); clearTimeout(this.receivedTimer);
this.receivedTimer = setTimeout(() => { this.receivedTimer = setTimeout(() => {
this.receivedTimer = undefined; this.receivedTimer = undefined;
@@ -4717,7 +4724,7 @@ class TinodeWeb extends React.Component {
tnFndSubsUpdated() { tnFndSubsUpdated() {
var contacts = []; var contacts = [];
// Don't attempt to create P2P topics which already exist. Server will reject the duplicates. // Don't attempt to create P2P topics which already exist. Server will reject the duplicates.
Tinode.getFndTopic().contacts(function(s) { this.state.tinode.getFndTopic().contacts((s) => {
contacts.push(s); contacts.push(s);
}); });
this.setState({foundContacts: contacts}); this.setState({foundContacts: contacts});
@@ -4727,7 +4734,7 @@ class TinodeWeb extends React.Component {
@param query {Array} is an array of contacts to search for @param query {Array} is an array of contacts to search for
*/ */
handleSearchContacts(query) { handleSearchContacts(query) {
var fnd = Tinode.getFndTopic(); var fnd = this.state.tinode.getFndTopic();
this.setState({contactsSearchQuery: query == DEL_CHAR ? '' : query}); this.setState({contactsSearchQuery: query == DEL_CHAR ? '' : query});
fnd.setMeta({desc: {public: query}}).then((ctrl) => { fnd.setMeta({desc: {public: query}}).then((ctrl) => {
return fnd.getMeta(fnd.startMetaQuery().withSub().build()); return fnd.getMeta(fnd.startMetaQuery().withSub().build());
@@ -4741,7 +4748,7 @@ class TinodeWeb extends React.Component {
if (topicName) { if (topicName) {
// Contact selected // Contact selected
if (this.state.topicSelected != topicName) { if (this.state.topicSelected != topicName) {
window.location.hash = setUrlTopic(window.location.hash, topicName); navigateTo(setUrlTopic(window.location.hash, topicName));
} }
this.setState({ this.setState({
errorText: '', errorText: '',
@@ -4753,7 +4760,7 @@ class TinodeWeb extends React.Component {
}); });
} else { } else {
if (this.state.topicSelected) { if (this.state.topicSelected) {
window.location.hash = setUrlTopic(window.location.hash, null); navigateTo(setUrlTopic(window.location.hash, null));
} }
// Currently selected contact deleted // Currently selected contact deleted
this.setState({ this.setState({
@@ -4782,12 +4789,12 @@ class TinodeWeb extends React.Component {
this.setState({ this.setState({
mobilePanel: 'sidepanel' mobilePanel: 'sidepanel'
}); });
window.location.hash = setUrlTopic(window.location.hash, null); navigateTo(setUrlTopic(window.location.hash, null));
} }
// User is sending a message, either plain text or a drafty object with attachments. // User is sending a message, either plain text or a drafty object with attachments.
handleSendMessage(msg, promise, uploader) { handleSendMessage(msg, promise, uploader) {
let topic = Tinode.getTopic(this.state.topicSelected); let topic = this.state.tinode.getTopic(this.state.topicSelected);
let dft = Drafty.parse(msg); let dft = Drafty.parse(msg);
if (dft && !Drafty.isPlainText(dft)) { if (dft && !Drafty.isPlainText(dft)) {
msg = dft; msg = dft;
@@ -4814,15 +4821,15 @@ class TinodeWeb extends React.Component {
// User chose a Sign Up menu item. // User chose a Sign Up menu item.
handleNewAccount() { handleNewAccount() {
window.location.hash = setUrlSidePanel(window.location.hash, 'register'); navigateTo(setUrlSidePanel(window.location.hash, 'register'));
} }
// Actual registration of a new account. // Actual registration of a new account.
handleNewAccountRequest(login_, password_, public_, cred_, tags_) { handleNewAccountRequest(login_, password_, public_, cred_, tags_) {
Tinode.connect(this.state.serverAddress) this.state.tinode.connect(this.state.serverAddress)
.then(function() { .then(() => {
var params = Tinode.addCredential({public: public_, tags: tags_}, cred_); var params = this.state.tinode.addCredential({public: public_, tags: tags_}, cred_);
return Tinode.createAccountBasic(login_, password_, params); return this.state.tinode.createAccountBasic(login_, password_, params);
}).then((ctrl) => { }).then((ctrl) => {
if (ctrl.code >= 300 && ctrl.text === "validate credentials") { if (ctrl.code >= 300 && ctrl.text === "validate credentials") {
this.handleCredentialsRequest(ctrl.params); this.handleCredentialsRequest(ctrl.params);
@@ -4835,30 +4842,28 @@ class TinodeWeb extends React.Component {
} }
handleUpdateAccountRequest(password, pub, priv) { handleUpdateAccountRequest(password, pub, priv) {
var instance = this;
if (pub || priv) { if (pub || priv) {
Tinode.getMeTopic().setMeta({desc: {public: pub, private: priv}}).catch(function(err) { this.state.tinode.getMeTopic().setMeta({desc: {public: pub, private: priv}}).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
} }
if (password) { if (password) {
Tinode.updateAccountBasic(null, Tinode.getCurrentLogin(), password).catch(function(err) { this.state.tinode.updateAccountBasic(null, Tinode.getCurrentLogin(), password).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
} }
} }
handleUpdateAccountTagsRequest(tags) { handleUpdateAccountTagsRequest(tags) {
var instance = this; this.state.tinode.getFndTopic().setMeta({tags: tags})
Tinode.getFndTopic().setMeta({tags: tags}) .catch((err) => {
.catch(function(err) { this.handleError(err.message, "err");
instance.handleError(err.message, "err");
}); });
} }
// User chose Settings menu item. // User chose Settings menu item.
handleSettings() { handleSettings() {
window.location.hash = setUrlSidePanel(window.location.hash, this.state.myUserId ? 'edit' : 'settings'); navigateTo(setUrlSidePanel(window.location.hash, this.state.myUserId ? 'edit' : 'settings'));
} }
// User updated global parameters. // User updated global parameters.
@@ -4873,6 +4878,7 @@ class TinodeWeb extends React.Component {
transport: transport, transport: transport,
messageSounds: messageSounds, messageSounds: messageSounds,
desktopAlerts: desktopAlerts, desktopAlerts: desktopAlerts,
tinode: TinodeWeb.tnSetup(serverAddress, transport),
}); });
localStorage.setObject({ localStorage.setObject({
serverAddress: serverAddress, serverAddress: serverAddress,
@@ -4880,8 +4886,7 @@ class TinodeWeb extends React.Component {
transport: this.state.transport, transport: this.state.transport,
desktopAlerts: desktopAlerts desktopAlerts: desktopAlerts
}); });
window.location.hash = setUrlSidePanel(window.location.hash, ''); navigateTo(setUrlSidePanel(window.location.hash, ''));
TinodeWeb.tnSetup(serverAddress, transport);
} }
// User clicked Cancel button in Setting or Sign Up panel. // User clicked Cancel button in Setting or Sign Up panel.
@@ -4893,19 +4898,18 @@ class TinodeWeb extends React.Component {
delete parsed.params.method; delete parsed.params.method;
delete parsed.params.tab; delete parsed.params.tab;
} }
window.location.hash = composeUrlHash(parsed.path, parsed.params); navigateTo(composeUrlHash(parsed.path, parsed.params));
this.setState({errorText: '', errorLevel: null}); this.setState({errorText: '', errorLevel: null});
} }
// User clicked a (+) menu item. // User clicked a (+) menu item.
handleNewTopic() { handleNewTopic() {
window.location.hash = setUrlSidePanel(window.location.hash, 'newtpk'); navigateTo(setUrlSidePanel(window.location.hash, 'newtpk'));
} }
// Create of a new topic. New P2P topic requires peer's name. // Create of a new topic. New P2P topic requires peer's name.
handleNewTopicRequest(peerName, pub, priv, tags) { handleNewTopicRequest(peerName, pub, priv, tags) {
var instance = this; var topic = peerName ? this.state.tinode.newTopicWith(peerName) : this.state.tinode.newTopic();
var topic = peerName ? Tinode.newTopicWith(peerName) : Tinode.newTopic();
var query = topic.startMetaQuery().withDesc().withSub().withData(); var query = topic.startMetaQuery().withDesc().withSub().withData();
var setParams; var setParams;
if (!peerName) { if (!peerName) {
@@ -4914,17 +4918,17 @@ class TinodeWeb extends React.Component {
query = query.withTags(); query = query.withTags();
setParams = {desc: {public: pub, private: priv}, tags: tags}; setParams = {desc: {public: pub, private: priv}, tags: tags};
} }
topic.subscribe(query.build(), setParams).then(function() { topic.subscribe(query.build(), setParams).then(() => {
window.location.hash = setUrlSidePanel(window.location.hash, 'contacts'); navigateTo(setUrlSidePanel(window.location.hash, 'contacts'));
instance.handleTopicSelected(topic.name, undefined, Tinode.isTopicOnline(topic.name), topic.getAccessMode()); this.handleTopicSelected(topic.name, undefined,
}).catch(function(err) { this.state.tinode.isTopicOnline(topic.name), topic.getAccessMode());
instance.handleError(err.message, "err"); }).catch((err) => {
this.handleError(err.message, "err");
}); });
} }
handleTopicUpdateRequest(topicName, pub, priv, permissions) { handleTopicUpdateRequest(topicName, pub, priv, permissions) {
var instance = this; var topic = this.state.tinode.getTopic(topicName);
var topic = Tinode.getTopic(topicName);
if (topic) { if (topic) {
var params = {}; var params = {};
if (pub) { if (pub) {
@@ -4936,15 +4940,14 @@ class TinodeWeb extends React.Component {
if (permissions) { if (permissions) {
params.defacs = permissions; params.defacs = permissions;
} }
topic.setMeta({desc: params}).catch(function(err) { topic.setMeta({desc: params}).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
} }
} }
handleChangePermissions(topicName, mode, uid) { handleChangePermissions(topicName, mode, uid) {
var instance = this; var topic = this.state.tinode.getTopic(topicName);
var topic = Tinode.getTopic(topicName);
if (topic) { if (topic) {
var am = topic.getAccessMode(); var am = topic.getAccessMode();
if (uid) { if (uid) {
@@ -4954,18 +4957,18 @@ class TinodeWeb extends React.Component {
am.updateWant(mode); am.updateWant(mode);
mode = am.getWant(); mode = am.getWant();
} }
topic.setMeta({sub: {user: uid, mode: mode}}).catch(function(err) { topic.setMeta({sub: {user: uid, mode: mode}}).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
} }
} }
handleTagsUpdated(topicName, tags) { handleTagsUpdated(topicName, tags) {
var topic = Tinode.getTopic(topicName); var topic = this.state.tinode.getTopic(topicName);
if (topic) { if (topic) {
var instance = this; var instance = this;
topic.setMeta({tags: tags}).catch(function(err) { topic.setMeta({tags: tags}).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
} }
} }
@@ -4973,19 +4976,19 @@ class TinodeWeb extends React.Component {
handleLogout() { handleLogout() {
localStorage.removeItem("auth-token"); localStorage.removeItem("auth-token");
this.setState(this.getBlankState()); this.setState(this.getBlankState());
TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport); this.setState({tinode: TinodeWeb.tnSetup(this.state.serverAddress, this.state.transport)});
window.location.hash = ""; navigateTo("");
} }
handleLeaveUnsubRequest(topicName) { handleLeaveUnsubRequest(topicName) {
var topic = Tinode.getTopic(topicName); var topic = this.state.tinode.getTopic(topicName);
if (!topic) { if (!topic) {
return; return;
} }
topic.leave(true).then((ctrl) => { topic.leave(true).then((ctrl) => {
// Hide MessagesView and InfoView panels. // Hide MessagesView and InfoView panels.
window.location.hash = setUrlTopic(window.location.hash, ''); navigateTo(setUrlTopic(window.location.hash, ''));
}).catch((err) => { }).catch((err) => {
this.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
@@ -5007,7 +5010,7 @@ class TinodeWeb extends React.Component {
defaultTopicContextMenu(topicName) { defaultTopicContextMenu(topicName) {
var muted = false, blocked = false, subscribed = false, deleter = false; var muted = false, blocked = false, subscribed = false, deleter = false;
var topic = Tinode.getTopic(topicName); var topic = this.state.tinode.getTopic(topicName);
if (topic) { if (topic) {
if (topic.isSubscribed()) { if (topic.isSubscribed()) {
subscribed = true; subscribed = true;
@@ -5038,12 +5041,12 @@ class TinodeWeb extends React.Component {
} }
handleShowInfoView() { handleShowInfoView() {
window.location.hash = addUrlParam(window.location.hash, 'info', true); navigateTo(addUrlParam(window.location.hash, 'info', true));
this.setState({showInfoPanel: true}); this.setState({showInfoPanel: true});
} }
handleHideInfoView() { handleHideInfoView() {
window.location.hash = removeUrlParam(window.location.hash, 'info'); navigateTo(removeUrlParam(window.location.hash, 'info'));
this.setState({showInfoPanel: false}); this.setState({showInfoPanel: false});
} }
@@ -5052,25 +5055,23 @@ class TinodeWeb extends React.Component {
return; return;
} }
var topic = Tinode.getTopic(topicName); var topic = this.state.tinode.getTopic(topicName);
if (!topic) { if (!topic) {
return; return;
} }
var instance = this;
if (added && added.length > 0) { if (added && added.length > 0) {
added.map(function(uid) { added.map((uid) => {
topic.invite(uid, null).catch(function(err) { topic.invite(uid, null).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
}); });
} }
if (removed && removed.length > 0) { if (removed && removed.length > 0) {
removed.map(function(uid) { removed.map((uid) => {
topic.delSubscription(uid).catch(function(err) { topic.delSubscription(uid).catch((err) => {
instance.handleError(err.message, "err"); this.handleError(err.message, "err");
}); });
}); });
} }