fraction / oasis

Free, open-source, peer-to-peer social application that helps you follow friends and discover new ones on Secure Scuttlebutt (SSB).
http://oasis-demo.fraction.io
GNU Affero General Public License v3.0
286 stars 42 forks source link

Issue 126: Show recipients of private messages #584

Closed lindskog closed 3 years ago

lindskog commented 3 years ago

What's the problem you solved?

In a private message you can't see who the recipients are, so you can't know the audience you're talking to.

What solution are you recommending?

Shows recipient thumbnails in the top right corner of each message (see image)

image

christianbundy commented 3 years ago

Thanks for taking on this work! I'm getting an error when I use this commit and try to visit /inbox though:

/home/christianbundy/src/fraction/oasis/src/index.js:132
    throw err;
    ^

Error: can only encode arrays
    at encode (/home/christianbundy/src/fraction/oasis/node_modules/charwise/codec/object.js:27:44)
    at encodeItem (/home/christianbundy/src/fraction/oasis/node_modules/charwise/codec/object.js:41:20)
    at Object.encode (/home/christianbundy/src/fraction/oasis/node_modules/charwise/codec/object.js:33:24)
    at Object.exports.encode (/home/christianbundy/src/fraction/oasis/node_modules/charwise/index.js:39:28)
    at Codec.encodeKey (/home/christianbundy/src/fraction/oasis/node_modules/encoding-down/node_modules/level-codec/index.js:32:45)
    at /home/christianbundy/src/fraction/oasis/node_modules/encoding-down/node_modules/level-codec/index.js:72:14
    at Array.forEach (<anonymous>)
    at Codec.encodeLtgt (/home/christianbundy/src/fraction/oasis/node_modules/encoding-down/node_modules/level-codec/index.js:70:21)
    at new Iterator (/home/christianbundy/src/fraction/oasis/node_modules/encoding-down/index.js:115:26)
    at DB._iterator (/home/christianbundy/src/fraction/oasis/node_modules/encoding-down/index.js:102:10)

This error only happens when I go to /inbox, but I'm not sure why.

Powersource commented 3 years ago

@christianbundy I think that might be an unrelated error, see %pWLkL41WTXzesxNVqUGriSCe9jI+SwdJAJv33X4eFsc=.sha256 . Good news is that cel says "this issue is fixed in latest ssb-server v15", "crash when handling certain messages recently published", bad news is that we don't use ssb-server directly so we'd have to do some more digging.

christianbundy commented 3 years ago

:beetle: Found the bug, it's in this pull request.

diff --git a/src/models.js b/src/models.js
index 92a0750d..c73d4c27 100644
--- a/src/models.js
+++ b/src/models.js
@@ -693,6 +693,7 @@ module.exports = ({ cooler, isPublic }) => {
   };

   const getUserInfo = async (feedId) => {
+    console.log({ feedId })
     const id = feedId;

     const pendingName = models.about.name(feedId);

Pass

{ feedId: "@+oaWWDs8g73EZFUMfW37R/ULtFEjwKN/DczvdYihjbU=.ed25519" }

Fail

{
  feedId: {
    link: '@+oaWWDs8g73EZFUMfW37R/ULtFEjwKN/DczvdYihjbU=.ed25519',
    name: 'Christian Bundy'
  }
}

Previously we were reading msg.value.author, which is always a string, but recps is the wild west and we need to practice some defensive driving to make sure we're passing a string rather than an { link, name } object.

christianbundy commented 3 years ago

@Powersource I don't think we use SSB-Links, so I don't think that bug is possible in Oasis. It is, however, a similar bug: https://github.com/ssbc/ssb-links/commit/d4916ed1c57c5ab055eb011bbc3a95a75a81eb97

christianbundy commented 3 years ago

Example solution:


const variants = [
  "@+oaWWDs8g73EZFUMfW37R/ULtFEjwKN/DczvdYihjbU=.ed25519",
  {
    link: "@+oaWWDs8g73EZFUMfW37R/ULtFEjwKN/DczvdYihjbU=.ed25519",
    name: "Christian Bundy",
  },
];

function getRecipientFeedId(recipient) {
  if (typeof recipient === "string") {
    return recipient;
  } else {
    return recipient.link;
  }
}

variants.map(getRecipientFeedId).every((x) => typeof x === "string"); // => true
lindskog commented 3 years ago

Oh wow thanks for noticing that bug!! I will look into it right away, I just assumed that feedId was always a String

lindskog commented 3 years ago

This is the issue for reference: https://github.com/fraction/oasis/issues/126

lindskog commented 3 years ago

@christianbundy I've committed a suggestion for a fix to the bug! But I wasn't able to reproduce the bug myself (I had to hardcode the feedId to get the error that you mention), so please double check that the bug is actually solved (and that my solution for it is ok) :)

christianbundy commented 3 years ago

This works great, thanks fr putting this patch together!