better handling of remote disconnection

This commit is contained in:
Daniel Lugo 2020-02-15 11:52:56 -04:00
parent a6ab80ac1e
commit cf0100d105
2 changed files with 9 additions and 9 deletions

View file

@ -414,7 +414,7 @@ const processChats = debounce(() => {
/** @type {Chat} */ /** @type {Chat} */
const chat = { const chat = {
recipientPublicKey: out.with, recipientPublicKey: out.with,
didDisconnect: incoming === null, didDisconnect: pubToFeed[out.with] === 'disconnected',
id: out.with + outID, id: out.with + outID,
messages: msgs, messages: msgs,
recipientAvatar: pubToAvatar[out.with] || null, recipientAvatar: pubToAvatar[out.with] || null,
@ -424,11 +424,11 @@ const processChats = debounce(() => {
newChats.push(chat) newChats.push(chat)
} }
currentChats = newChats.filter( currentChats = newChats
c => // initial state, means non connected
// initial state, means non connected .filter(c => typeof pubToFeed[c.recipientPublicKey] !== 'undefined')
typeof pubToFeed[c.recipientPublicKey] !== 'undefined' // disconnected from this side
) .filter(c => pubToFeed[c.recipientPublicKey] !== null)
notifyChatsListeners() notifyChatsListeners()
}, 750) }, 750)

View file

@ -14,7 +14,7 @@ const Utils = require('../utils')
const PubToIncoming = require('./pubToIncoming') const PubToIncoming = require('./pubToIncoming')
/** /**
* @typedef {Record<string, Message[]|null|undefined>} Feeds * @typedef {Record<string, Message[]|null|undefined|'disconnected'>} Feeds
* @typedef {(feeds: Feeds) => void} FeedsListener * @typedef {(feeds: Feeds) => void} FeedsListener
*/ */
@ -88,14 +88,14 @@ const onOpenForPubFeedPair = ([pub, feed]) =>
// detect remote disconnection // detect remote disconnection
setPubToFeed({ setPubToFeed({
...getPubToFeed(), ...getPubToFeed(),
[pub]: null [pub]: /** @type {'disconnected'} */ ('disconnected')
}) })
return return
} }
const incoming = /** @type {Schema.Outgoing} */ (data) const incoming = /** @type {Schema.Outgoing} */ (data)
// incomplete data // incomplete data, let's not assume anything
if ( if (
typeof incoming.with !== 'string' || typeof incoming.with !== 'string' ||
typeof incoming.messages !== 'object' typeof incoming.messages !== 'object'