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.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) => {
if (pub._sending) {
return;
}
if (pub.head && pub.head.webrtc) {
// Filter out unsent video call messages.
calls.push(pub.seq);
return;
}
if (topic.isSubscribed()) {
this.retrySend(pub);
}
});
if (calls.length > 0) {
topic.delMessagesList(calls, true);
}
})
.catch((err) => {
console.error("Failed subscription to", this.state.topic, err);
@@ -760,7 +770,12 @@ class MessagesView extends React.Component {
// Retry sending a message.
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:
+11 -1
View File
@@ -1007,15 +1007,25 @@ class TinodeWeb extends React.Component {
const subscribePromise =
topic.subscribe()
.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 => {
if (pub._sending || pub.seq == msg.seq) {
return;
}
if (pub.head && pub.head.webrtc) {
// Filter out unsent video call messages.
calls.push(pub.seq);
return;
}
if (topic.isSubscribed()) {
topic.publishMessage(pub);
}
});
if (calls.length > 0) {
topic.delMessagesList(calls, true);
}
});
completion.push(subscribePromise);
}