dont't crash on logout
This commit is contained in:
+10
-8
@@ -3603,7 +3603,7 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.leave();
|
this.leave(this.state.topic);
|
||||||
if (this.messagesScroller) {
|
if (this.messagesScroller) {
|
||||||
this.messagesScroller.removeEventListener('scroll', this.fetchMoreMessages);
|
this.messagesScroller.removeEventListener('scroll', this.fetchMoreMessages);
|
||||||
}
|
}
|
||||||
@@ -3615,8 +3615,8 @@ class MessagesView extends React.Component {
|
|||||||
|
|
||||||
propsChange(props) {
|
propsChange(props) {
|
||||||
if (!props || !props.topic) {
|
if (!props || !props.topic) {
|
||||||
this.setState({messages: [], onlineSubs: [], topic: null});
|
let oldTopic = this.state.topic;
|
||||||
this.leave();
|
this.setState({messages: [], onlineSubs: [], topic: null}, this.leave(oldTopic));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3646,7 +3646,7 @@ class MessagesView extends React.Component {
|
|||||||
topic.onSubsUpdated = this.handleSubsUpdated;
|
topic.onSubsUpdated = this.handleSubsUpdated;
|
||||||
topic.onPres = this.handleSubsUpdated;
|
topic.onPres = this.handleSubsUpdated;
|
||||||
// Unbind the previous topic from this component.
|
// Unbind the previous topic from this component.
|
||||||
this.leave();
|
this.leave(this.state.topic);
|
||||||
|
|
||||||
this.handleDescChange(topic);
|
this.handleDescChange(topic);
|
||||||
topic.subscribers((sub) => {
|
topic.subscribers((sub) => {
|
||||||
@@ -3710,13 +3710,15 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leave() {
|
leave(oldTopicName) {
|
||||||
if (!this.state.topic) {
|
if (!oldTopicName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let oldTopic = this.props.tinode.getTopic(this.state.topic);
|
let oldTopic = this.props.tinode.getTopic(oldTopicName);
|
||||||
if (oldTopic && oldTopic.isSubscribed()) {
|
if (oldTopic && oldTopic.isSubscribed()) {
|
||||||
oldTopic.leave(false).finally(() => {
|
oldTopic.leave(false)
|
||||||
|
.catch(() => { /* do nothing here */ })
|
||||||
|
.finally(() => {
|
||||||
// We don't care if the request succeeded or failed.
|
// We don't care if the request succeeded or failed.
|
||||||
// The topic is dead regardless.
|
// The topic is dead regardless.
|
||||||
this.setState({fetchingMessages: false});
|
this.setState({fetchingMessages: false});
|
||||||
|
|||||||
Reference in New Issue
Block a user