diff --git a/services/gunDB/contact-api/events/index.js b/services/gunDB/contact-api/events/index.js index 9c85b218..6036a8d2 100644 --- a/services/gunDB/contact-api/events/index.js +++ b/services/gunDB/contact-api/events/index.js @@ -414,7 +414,7 @@ const processChats = debounce(() => { /** @type {Chat} */ const chat = { recipientPublicKey: out.with, - didDisconnect: incoming === null, + didDisconnect: pubToFeed[out.with] === 'disconnected', id: out.with + outID, messages: msgs, recipientAvatar: pubToAvatar[out.with] || null, @@ -424,11 +424,11 @@ const processChats = debounce(() => { newChats.push(chat) } - currentChats = newChats.filter( - c => - // initial state, means non connected - typeof pubToFeed[c.recipientPublicKey] !== 'undefined' - ) + currentChats = newChats + // initial state, means non connected + .filter(c => typeof pubToFeed[c.recipientPublicKey] !== 'undefined') + // disconnected from this side + .filter(c => pubToFeed[c.recipientPublicKey] !== null) notifyChatsListeners() }, 750) diff --git a/services/gunDB/contact-api/streams/pubToFeed.js b/services/gunDB/contact-api/streams/pubToFeed.js index ca6ae0fa..7c06c080 100644 --- a/services/gunDB/contact-api/streams/pubToFeed.js +++ b/services/gunDB/contact-api/streams/pubToFeed.js @@ -14,7 +14,7 @@ const Utils = require('../utils') const PubToIncoming = require('./pubToIncoming') /** - * @typedef {Record} Feeds + * @typedef {Record} Feeds * @typedef {(feeds: Feeds) => void} FeedsListener */ @@ -88,14 +88,14 @@ const onOpenForPubFeedPair = ([pub, feed]) => // detect remote disconnection setPubToFeed({ ...getPubToFeed(), - [pub]: null + [pub]: /** @type {'disconnected'} */ ('disconnected') }) return } const incoming = /** @type {Schema.Outgoing} */ (data) - // incomplete data + // incomplete data, let's not assume anything if ( typeof incoming.with !== 'string' || typeof incoming.messages !== 'object'