bug fix: an extra copy of a p2p topic was sometimes created

This commit is contained in:
or-else
2017-08-07 21:14:42 +03:00
parent eca16c8474
commit 17876fc4b0
+9 -15
View File
@@ -2022,7 +2022,9 @@
// Unbind the previous topic from this component. // Unbind the previous topic from this component.
if (this.state.topic) { if (this.state.topic) {
var oldTopic = Tinode.getTopic(this.state.topic); var oldTopic = Tinode.getTopic(this.state.topic);
if (oldTopic.isSubscribed()) {
oldTopic.leave(false); oldTopic.leave(false);
}
oldTopic.onData = undefined; oldTopic.onData = undefined;
oldTopic.onInfo = undefined; oldTopic.onInfo = undefined;
oldTopic.onMetaDesc = undefined; oldTopic.onMetaDesc = undefined;
@@ -2030,11 +2032,13 @@
} }
if (topic.isSubscribed()) { if (topic.isSubscribed()) {
console.log("topic " + props.topic + " is subscribed");
this.handleDescChange(topic); this.handleDescChange(topic);
topic.messages(function(msg) { topic.messages(function(msg) {
msgs = msgs.concat(msg); msgs = msgs.concat(msg);
}); });
} else { } else {
console.log("topic " + props.topic + " is NOT subscribed");
topic.subscribe({get: {desc: {}, sub: {}, data: {}}}); topic.subscribe({get: {desc: {}, sub: {}, data: {}}});
} }
@@ -2054,7 +2058,7 @@
} }
}, },
handleSubsUpdated: function(uids) { handleSubsUpdated: function(uids) {
console.log("topic subscriptions updated"); // console.log("topic subscriptions updated");
}, },
handleNewMessage: function(msg) { handleNewMessage: function(msg) {
clearTimeout(this.readTimer); clearTimeout(this.readTimer);
@@ -2573,35 +2577,25 @@
handleNewTopicRequest: function(peerName, pub) { handleNewTopicRequest: function(peerName, pub) {
var instance = this; var instance = this;
// Check if user clicked on an existing connection.
if (Tinode.getTopicType(peerName) === "p2p") {
instance.setState({
errorText: '',
topicSelected: peerName,
sidePanelSelected: 'contacts',
mobilePanel: 'topic-view',
showInfoPanel: false
});
} else {
var topic = peerName ? Tinode.newTopicWith(peerName) : Tinode.newTopic(); var topic = peerName ? Tinode.newTopicWith(peerName) : Tinode.newTopic();
var params = {get: {desc: {}, data: {}}}; var params = {get: {desc: {}, data: {}}};
if (!peerName) { if (!peerName) {
params.get.sub = {}; // Fetch subs for grp topics only. Subscriptions for a p2p topic are useless. params.get.sub = {};
params.set = {desc: {public: pub}}; params.set = {desc: {public: pub}};
} }
topic.subscribe(params).then(function() { topic.subscribe(params).then(function() {
instance.setState({ instance.setState({
errorText: '', errorText: '',
topicSelected: topic.name, topicSelected: topic.name,
sidePanelSelected: 'contacts', sidePanelSelected: 'contacts',
mobilePanel: 'topic-view', mobilePanel: 'topic-view',
showInfoPanel: true, showInfoPanel: false,
infoPanelShowMembers: true infoPanelShowMembers: peerName ? false : true
}); });
}).catch(function(err) { }).catch(function(err) {
instance.setState({errorText: err.message}); instance.setState({errorText: err.message});
}); });
}
}, },
//handleManageGroupMembers: function(topicName) { //handleManageGroupMembers: function(topicName) {