don't immediately subscribe to a new p2p topic, wait for the first message'
This commit is contained in:
@@ -188,11 +188,12 @@ class MessagesView extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topic && ((this.state.topic != prevState.topic) || !prevProps.ready)) {
|
if (topic && ((this.state.topic != prevState.topic) || !prevProps.ready)) {
|
||||||
if (topic._new) {
|
// Don't immediately subscribe to a new p2p topic, wait for the first message.
|
||||||
console.log('DEBUG: Fetching new topic description');
|
if (topic._new && topic.isP2PType()) {
|
||||||
// topic.getMeta(topic.startMetaQuery().withDesc().build());
|
topic.getMeta(topic.startMetaQuery().withDesc().build());
|
||||||
|
} else {
|
||||||
|
this.subscribe(topic);
|
||||||
}
|
}
|
||||||
this.subscribe(topic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +381,10 @@ class MessagesView extends React.Component {
|
|||||||
this.props.onNewTopicCreated(this.props.topic, ctrl.topic);
|
this.props.onNewTopicCreated(this.props.topic, ctrl.topic);
|
||||||
// If there are unsent messages, try sending them now.
|
// If there are unsent messages, try sending them now.
|
||||||
topic.queuedMessages((pub) => {
|
topic.queuedMessages((pub) => {
|
||||||
if (!pub._sending && topic.isSubscribed()) {
|
if (pub._sending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic.isSubscribed()) {
|
||||||
this.retrySend(pub);
|
this.retrySend(pub);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+25
-25
@@ -960,14 +960,14 @@ class TinodeWeb extends React.Component {
|
|||||||
// with attachments.
|
// with attachments.
|
||||||
// - msg - Drafty message with content
|
// - msg - Drafty message with content
|
||||||
// - promise - Promise to be resolved when the upload is completed
|
// - promise - Promise to be resolved when the upload is completed
|
||||||
// - uploader - for tracking progress
|
// - uploadCompletionPromise - for tracking progress
|
||||||
// - head - head dictionary to be attached to the message
|
// - head - head dictionary to be attached to the message
|
||||||
handleSendMessage(msg, promise, uploader, head) {
|
handleSendMessage(msg, uploadCompletionPromise, uploader, head) {
|
||||||
const topic = this.tinode.getTopic(this.state.topicSelected);
|
const topic = this.tinode.getTopic(this.state.topicSelected);
|
||||||
this.sendMessageToTopic(topic, msg, promise, uploader, head);
|
this.sendMessageToTopic(topic, msg, uploadCompletionPromise, uploader, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToTopic(topic, msg, promise, uploader, head) {
|
sendMessageToTopic(topic, msg, uploadCompletionPromise, uploader, head) {
|
||||||
msg = topic.createMessage(msg, false);
|
msg = topic.createMessage(msg, false);
|
||||||
// The uploader is used to show progress.
|
// The uploader is used to show progress.
|
||||||
msg._uploader = uploader;
|
msg._uploader = uploader;
|
||||||
@@ -976,33 +976,33 @@ class TinodeWeb extends React.Component {
|
|||||||
msg.head = Object.assign(msg.head || {}, head);
|
msg.head = Object.assign(msg.head || {}, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const completion = [];
|
||||||
|
if (uploadCompletionPromise) {
|
||||||
|
completion.push(uploadCompletionPromise);
|
||||||
|
}
|
||||||
|
|
||||||
if (!topic.isSubscribed()) {
|
if (!topic.isSubscribed()) {
|
||||||
// Topic is not subscribed yet. Subscribe.
|
// Topic is not subscribed yet. Subscribe.
|
||||||
if (!promise) {
|
const subscribePromise =
|
||||||
promise = Promise.resolve();
|
topic.subscribe()
|
||||||
}
|
.then(() => {
|
||||||
promise = promise
|
// If there are unsent messages, try sending them now.
|
||||||
.then(() => topic.subscribe())
|
topic.queuedMessages(pub => {
|
||||||
.then(() => {
|
if (pub._sending || pub.seq == msg.seq) {
|
||||||
// If there are unsent messages, try sending them now.
|
return;
|
||||||
topic.queuedMessages((pub) => {
|
}
|
||||||
if (!pub._sending && topic.isSubscribed()) {
|
if (topic.isSubscribed()) {
|
||||||
topic.publishMessage(pub);
|
topic.publishMessage(pub);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
completion.push(subscribePromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promise) {
|
topic.publishDraft(msg, Promise.all(completion))
|
||||||
promise = promise.catch((err) => {
|
.then(_ => {
|
||||||
this.handleError(err.message, 'err');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
topic.publishDraft(msg, promise)
|
|
||||||
.then((ctrl) => {
|
|
||||||
if (topic.isArchived()) {
|
if (topic.isArchived()) {
|
||||||
return topic.archive(false);
|
topic.archive(false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
+27
-22
@@ -5524,11 +5524,11 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (topic && (this.state.topic != prevState.topic || !prevProps.ready)) {
|
if (topic && (this.state.topic != prevState.topic || !prevProps.ready)) {
|
||||||
if (topic._new) {
|
if (topic._new && topic.isP2PType()) {
|
||||||
console.log('DEBUG: Fetching new topic description');
|
topic.getMeta(topic.startMetaQuery().withDesc().build());
|
||||||
|
} else {
|
||||||
|
this.subscribe(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.subscribe(topic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5720,7 +5720,11 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
|
|||||||
|
|
||||||
this.props.onNewTopicCreated(this.props.topic, ctrl.topic);
|
this.props.onNewTopicCreated(this.props.topic, ctrl.topic);
|
||||||
topic.queuedMessages(pub => {
|
topic.queuedMessages(pub => {
|
||||||
if (!pub._sending && topic.isSubscribed()) {
|
if (pub._sending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topic.isSubscribed()) {
|
||||||
this.retrySend(pub);
|
this.retrySend(pub);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -8402,12 +8406,12 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
|||||||
_lib_navigation_js__WEBPACK_IMPORTED_MODULE_16__["default"].navigateTo(_lib_navigation_js__WEBPACK_IMPORTED_MODULE_16__["default"].setUrlTopic(window.location.hash, null));
|
_lib_navigation_js__WEBPACK_IMPORTED_MODULE_16__["default"].navigateTo(_lib_navigation_js__WEBPACK_IMPORTED_MODULE_16__["default"].setUrlTopic(window.location.hash, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSendMessage(msg, promise, uploader, head) {
|
handleSendMessage(msg, uploadCompletionPromise, uploader, head) {
|
||||||
const topic = this.tinode.getTopic(this.state.topicSelected);
|
const topic = this.tinode.getTopic(this.state.topicSelected);
|
||||||
this.sendMessageToTopic(topic, msg, promise, uploader, head);
|
this.sendMessageToTopic(topic, msg, uploadCompletionPromise, uploader, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToTopic(topic, msg, promise, uploader, head) {
|
sendMessageToTopic(topic, msg, uploadCompletionPromise, uploader, head) {
|
||||||
msg = topic.createMessage(msg, false);
|
msg = topic.createMessage(msg, false);
|
||||||
msg._uploader = uploader;
|
msg._uploader = uploader;
|
||||||
|
|
||||||
@@ -8415,29 +8419,30 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
|
|||||||
msg.head = Object.assign(msg.head || {}, head);
|
msg.head = Object.assign(msg.head || {}, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!topic.isSubscribed()) {
|
const completion = [];
|
||||||
if (!promise) {
|
|
||||||
promise = Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
promise = promise.then(() => topic.subscribe()).then(() => {
|
if (uploadCompletionPromise) {
|
||||||
|
completion.push(uploadCompletionPromise);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!topic.isSubscribed()) {
|
||||||
|
const subscribePromise = topic.subscribe().then(() => {
|
||||||
topic.queuedMessages(pub => {
|
topic.queuedMessages(pub => {
|
||||||
if (!pub._sending && topic.isSubscribed()) {
|
if (pub._sending || pub.seq == msg.seq) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (topic.isSubscribed()) {
|
||||||
topic.publishMessage(pub);
|
topic.publishMessage(pub);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
completion.push(subscribePromise);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (promise) {
|
topic.publishDraft(msg, Promise.all(completion)).then(_ => {
|
||||||
promise = promise.catch(err => {
|
|
||||||
this.handleError(err.message, 'err');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
topic.publishDraft(msg, promise).then(ctrl => {
|
|
||||||
if (topic.isArchived()) {
|
if (topic.isArchived()) {
|
||||||
return topic.archive(false);
|
topic.archive(false);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.handleError(err.message, 'err');
|
this.handleError(err.message, 'err');
|
||||||
|
|||||||
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
+19
-25
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