From 0088b7d8cf6b4affcd4711caae3adbda995a3570 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 23 Jul 2020 20:16:10 -0400 Subject: [PATCH] sendMessageNew(), returns the created RES --- services/gunDB/contact-api/actions.js | 25 ++++++++++++++++--- .../contact-api/events/onReceivedReqs.js | 1 - 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index a0ae6171..699d3c62 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -631,9 +631,9 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { * @param {string} body * @param {UserGUNNode} user * @param {ISEA} SEA - * @returns {Promise} The message id. + * @returns {Promise} The message id. */ -const sendMessage = async (recipientPublicKey, body, user, SEA) => { +const sendMessageNew = async (recipientPublicKey, body, user, SEA) => { if (!user.is) { throw new Error(ErrorCode.NOT_AUTH) } @@ -691,12 +691,28 @@ const sendMessage = async (recipientPublicKey, body, user, SEA) => { if (ack.err) { rej(new Error(ack.err)) } else { - res(msgNode._.get) + res({ + body, + id: msgNode._.get, + outgoing: true, + timestamp: newMessage.timestamp + }) } }) }) } +/** + * Returns the message id. + * @param {string} recipientPublicKey + * @param {string} body + * @param {UserGUNNode} user + * @param {ISEA} SEA + * @returns {Promise} The message id. + */ +const sendMessage = async (recipientPublicKey, body, user, SEA) => + (await sendMessageNew(recipientPublicKey, body, user, SEA)).id + /** * @param {string} recipientPub * @param {string} msgID @@ -1589,5 +1605,6 @@ module.exports = { deletePost, follow, unfollow, - initWall + initWall, + sendMessageNew } diff --git a/services/gunDB/contact-api/events/onReceivedReqs.js b/services/gunDB/contact-api/events/onReceivedReqs.js index 9a18a29b..a0b74e30 100644 --- a/services/gunDB/contact-api/events/onReceivedReqs.js +++ b/services/gunDB/contact-api/events/onReceivedReqs.js @@ -98,7 +98,6 @@ const listenerForAddr = addr => data => { } logger.info('data for address length: ' + size(addr)) - logger.info(JSON.stringify(data, null, 4)) react() }