From e0fe2e96bafcb503f08fc883ea98873345c589ad Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 28 Jan 2020 16:57:02 -0400 Subject: [PATCH] chats now have ids --- services/gunDB/contact-api/events.js | 6 ++++-- services/gunDB/contact-api/schema.js | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/gunDB/contact-api/events.js b/services/gunDB/contact-api/events.js index 0513e195..c50ad89d 100644 --- a/services/gunDB/contact-api/events.js +++ b/services/gunDB/contact-api/events.js @@ -586,7 +586,8 @@ const onChats = (cb, gun, user, SEA) => { recipientAvatar: '', recipientDisplayName: Utils.defaultName(recipientPK), recipientPublicKey: recipientPK, - didDisconnect + didDisconnect, + id: recipientPK + incomingID } } @@ -625,7 +626,8 @@ const onChats = (cb, gun, user, SEA) => { recipientAvatar: '', recipientDisplayName: Utils.defaultName(recipientPK), recipientPublicKey: recipientPK, - didDisconnect + didDisconnect, + id: recipientPK + incomingFeedID } } diff --git a/services/gunDB/contact-api/schema.js b/services/gunDB/contact-api/schema.js index fceb2d11..e7dc0b5b 100644 --- a/services/gunDB/contact-api/schema.js +++ b/services/gunDB/contact-api/schema.js @@ -65,6 +65,8 @@ exports.isChatMessage = item => { * outgoing/incoming feed paradigm. It combines both the outgoing and incoming * messages into one data structure plus metada about the chat. * @typedef {object} Chat + * @prop {string} id Chats now have IDs because of disconnect. + * RecipientPublicKey will no longer be unique. * @prop {string|null} recipientAvatar Base64 encoded image. * @prop {string} recipientPublicKey A way to uniquely identify each chat. * @prop {ChatMessage[]} messages Sorted from most recent to least recent. @@ -107,6 +109,10 @@ exports.isChat = item => { return false } + if (typeof obj.id !== 'string') { + return false + } + return obj.messages.every(msg => exports.isChatMessage(msg)) }