Drop unsent video call messages when synching topics.

This commit is contained in:
aforge
2022-07-17 17:03:27 +03:00
parent 6357f9227e
commit 781009b745
8 changed files with 6644 additions and 4957 deletions
+17 -2
View File
@@ -403,15 +403,25 @@ class MessagesView extends React.Component {
this.setState({topic: ctrl.topic}); this.setState({topic: ctrl.topic});
} }
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 (except video call messages),
// try sending them now. Unsent video call messages will be dropped.
let calls = [];
topic.queuedMessages((pub) => { topic.queuedMessages((pub) => {
if (pub._sending) { if (pub._sending) {
return; return;
} }
if (pub.head && pub.head.webrtc) {
// Filter out unsent video call messages.
calls.push(pub.seq);
return;
}
if (topic.isSubscribed()) { if (topic.isSubscribed()) {
this.retrySend(pub); this.retrySend(pub);
} }
}); });
if (calls.length > 0) {
topic.delMessagesList(calls, true);
}
}) })
.catch((err) => { .catch((err) => {
console.error("Failed subscription to", this.state.topic, err); console.error("Failed subscription to", this.state.topic, err);
@@ -760,7 +770,12 @@ class MessagesView extends React.Component {
// Retry sending a message. // Retry sending a message.
retrySend(pub) { retrySend(pub) {
this.props.sendMessage(pub.content, undefined, undefined, pub.head); this.props.sendMessage(pub.content, undefined, undefined, pub.head)
.then(() => {
// All good. Remove the original message draft from the cache.
const topic = this.props.tinode.getTopic(this.state.topic);
topic.delMessagesList([pub.seq], true);
});
} }
// Send attachment as Drafty message: // Send attachment as Drafty message:
+11 -1
View File
@@ -1007,15 +1007,25 @@ class TinodeWeb extends React.Component {
const subscribePromise = const subscribePromise =
topic.subscribe() topic.subscribe()
.then(() => { .then(() => {
// If there are unsent messages, try sending them now. // If there are unsent messages (except video call messages),
// try sending them now. Unsent video call messages will be dropped.
let calls = [];
topic.queuedMessages(pub => { topic.queuedMessages(pub => {
if (pub._sending || pub.seq == msg.seq) { if (pub._sending || pub.seq == msg.seq) {
return; return;
} }
if (pub.head && pub.head.webrtc) {
// Filter out unsent video call messages.
calls.push(pub.seq);
return;
}
if (topic.isSubscribed()) { if (topic.isSubscribed()) {
topic.publishMessage(pub); topic.publishMessage(pub);
} }
}); });
if (calls.length > 0) {
topic.delMessagesList(calls, true);
}
}); });
completion.push(subscribePromise); completion.push(subscribePromise);
} }
+309 -518
View File
File diff suppressed because it is too large Load Diff
+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
+6303 -4432
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