Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post preview with blobs and mentions #462

Merged
merged 51 commits into from
Nov 11, 2020

Conversation

cryptix
Copy link
Contributor

@cryptix cryptix commented Oct 19, 2020

This PR contains the outcome from %9NXKauuXCgJCHUaIXFGbpnXucAmvZ0QyQFJOAzURspc=.sha256: @cblgh & @cryptix's sprint to add post previews and blob uploads to the post composer. Next to those two big features @cblgh also implemented a variety of visual tweaks, including a more concise thread rendering, and we found enough time to improve the @mention suggestion feature.

As such we think it should:

Screenshots

Post preview

Screenshot_2020-10-19 Publish - Oasis

This is the preview flow we implemented. If you mention someone, and the match is ambiguous we show all the probable matches as cards, with a prepared markdown link that can be copied into the text. This is less complex and than an initial idea we had (which made use of <input type:radio> for each name).

Thread view

oasis-threads1

Posts now stick together much closer. We think it makes it clearer what is a conversation with replies compared to the latest or popular view where it's just a list of (unrelated) posts.

Miscellaneous

re oasis-desktop:
Apart from one weird bug in the database server, it all went quite swell.. but that one is a bit frightning as cryptix couldn't figure out where it's comming from. The TL;dr for that one is: it randomly stopped showing names and avatar images for (some) people..

Our current bit-sized summary action plan is: make a release with just the new features (as non of that requires updating the database) and make a -beta release with most recent dependencies to test this further.

A Blobby Caveat
A caveat with the current blob upload is that, after a file has been attached, the preview needs to be rendered (by clicking the Preview button) before anything is visible in the composer. This can be slightly confusing. The alternative would be to rely on the browser native file input, which is notoriously hard to style.

other nice things

  • Blobs use the correct markdown link based on the mime-type (i.e. supports ![video:...](..) and ![audio:...](..))
  • Blob uploads are possible in all views that public posts can be composed (the publish, comment, and subtopic views)
  • Exif location data is stripped from blob uploads
  • We planned to use ssb-blob-files for the exif stripping but ran into problems with it. This would be a nice follow-up for private-blobs, tho.
  • @mentions are found with .startsWith() so you can just type the beginning if your not 100% sure how it's spelled
  • Content warnings are now able to be added in comments and subtopics, in addition to the publish post view
  • The sidebar now bolds the item representing the currently visited view, and a variety of hover styling was added to increase the feel of interactivity of the interface
  • Added a simple test for the blob upload and fixed the others (errors weren't checked AFAICT)

cryptix and others added 30 commits October 19, 2020 10:04
and cleanup blob addition to text
also make sure to only display content warning in summary for subtopics
replaces immediatly if there is one match,
but just spews multiple ones.

* add silly in-memory about:name cache

rational is also commented the code. the tl:dr; is oasis already doesnt
use ssb-about or other indexing plugins.

butt for @mentions we need a quick way to lookup names to feeds,
otherwise we block the preview flow with long query times.
lowercase the searches and see if they match the beginning of a name.
@cryptix
Copy link
Contributor Author

cryptix commented Oct 21, 2020

thanks a ton @cblgh! with 988d35a the diff against master looks like i hoped it would!

i might need to revert the changes to tests/basic.js (the t.end vs t.error) if they still timeout.

this time without cryptix's basic blob test (to see if CI completes)
after having restored the package-lock.json to that of the master branch, this
PR now uses common-good@2.0.3, which has common-good check as a command.

i ran it manually as $(npm bin)/common-good check, and fixed whatever
it complained about.
@cblgh
Copy link
Contributor

cblgh commented Oct 21, 2020

alright so i have pretty much rectified everything i can think of to make the CI pass. if anyone else has ideas on what the issue is (the timeout?) do reach out :))

as regards the code, other than the package-lock fix, i think everything was put through its paces & stable at the onset of the PR. i fear that the changes i introduced just to please the CI / common-good might have caused issues.

@khimaros
Copy link

i believe i'm able to reproduce the test failure locally. it seems that 22/22 asserts are passing, but the suite never completes and tap never exits. i added a console.log() to the end of teardown, which indicates that teardown is successful.

i've modified package.json to remove the common-goood invocation for troubleshooting purposes and have been running npm run test -- --timeout=30 to reproduce. tap is not very informative about what it's doing after teardown.

i am also able to reproduce the hang by running node test/basic.js directly, which has more useful debug output. note, however, that it will not timeout.

i did notice that the tests are connecting to my real ssb-server (should this be mocked?), and if i shut the server down while the tests are hung at the end, the test throws an exception and exits (with code 7):

Exception thrown by PacketStream substream end handler Error: unexpected end of parent stream

Error: no callback provided for muxrpc close

maybe, despite app.close() completing, the server thread is hanging on join?

if i do not have an ssb-server running when i execute the tests, I do see the following console output at the end of asserts:

node_modules/ssb-db/index.js:74:          console.log("fallback to close")

@aadilayub
Copy link
Collaborator

Not sure if this is the right place to document this issue, but I was testing blob uploads just now, and kept running into an error whenever I tried to preview.

oasis

the error shown is

TypeError: Cannot read property 'startsWith' of undefined
    at handleBlobUpload (/home/aadil/.applications/ssb-oasis/src/index.js:291:19)
    at async preparePreview (/home/aadil/.applications/ssb-oasis/src/index.js:205:11)
    at async /home/aadil/.applications/ssb-oasis/src/index.js:884:25
    at async middleware (/home/aadil/.applications/ssb-oasis/src/index.js:1047:7)
    at async /home/aadil/.applications/ssb-oasis/src/index.js:1025:5
    at async /home/aadil/.applications/ssb-oasis/src/index.js:1020:5
    at async /home/aadil/.applications/ssb-oasis/src/http.js:113:5
    at async /home/aadil/.applications/ssb-oasis/node_modules/koa-mount/index.js:52:26

@khimaros
Copy link

i added a debugger; in ssb-db:75 and invoked the tests with node inspect test/basic.js, after stepping in the node debugger it seems that it is trapped in an timer/async hooks loop, which does sound like a thread that won't die:

break in node_modules/async-hook-domain/index.js:66
 64 
 65   destroy (id) {
>66     const domain = domains.get(id)
 67     debug('DESTROY', id, domain && domain.ids)
 68     if (!domain)

i am not a javascript dev and relatively unfamiliar with the node ecosystem, but hopefully this sets ya'll in the right direction.

@cblgh
Copy link
Contributor

cblgh commented Oct 21, 2020

@aadilayub which commit are you running off of? :)

@cinnamon-bun
Copy link
Collaborator

The re-indexing issue is now fixed as of commit 4d5c571. Tested by running Oasis and Patchwork 3.18.0 one at a time, back and forth.

@aadilayub
Copy link
Collaborator

@cblgh I'm running off 4d5c571df3380f7544c00af9b5411c7dfba555c2

@cblgh
Copy link
Contributor

cblgh commented Oct 23, 2020

(tiny update: just taking a little break before i begin bashing my head against ci issues again, i hate dealing with ci :)

@black-puppydog
Copy link
Collaborator

I know next to nothing about travis, and had to look up what tap is, but other people also had problems when running tap tests against koa code, with the tests not terminating:

koajs/koa#1224 (comment)

@cryptix
Copy link
Contributor Author

cryptix commented Nov 1, 2020

@aadilayub I just ran into the error you described (#462 (comment)). I believe it's some kind of race and looking at the code again, I think i have a better way of doing that. There was no reason to have the hasBlob variable, really. Patch incoming.

fixes TypeError: Cannot read property 'startsWith' of undefined
@cblgh
Copy link
Contributor

cblgh commented Nov 11, 2020

i'm back at it again! the plan is to spend today reconnoitering around the spooky timeouts which cause Travis to fall on his face

@cblgh
Copy link
Contributor

cblgh commented Nov 11, 2020

👀

now to see if it works without uncommenting a particularly troublesome route, all while leaving the workaround to definitively stop the server intact in the function call that should definitively stop the server

@christianbundy
Copy link
Member

Nice! 🎉

I spent a bit of time on this yesterday too -- I thought it was the setInterval(), but commenting that out didn't fix it.

Which route is troublesome? I've put in lots of work to avoid process.exit() in the past, letting Node just close on its own when all of the work is done, but I'd be okay with a quickfix here as long as there's documentation on what's broken and why we need the duct tape.

@christianbundy
Copy link
Member

nvm, looks like you nailed the problem down to the summaries route? that's very surprising, that's been around for a while and hasn't been on my radar as a trouble-maker

@christianbundy
Copy link
Member

christianbundy commented Nov 11, 2020

Good news: I found the problem!

Bad news: The only fix I've tried is "delete the entire chunk of code". Here's a diff against e567443:

click to expand
diff --git a/src/index.js b/src/index.js
index 18e02ee..012f5b4 100755
--- a/src/index.js
+++ b/src/index.js
@@ -1059,9 +1059,6 @@ const app = http({ host, port, middleware, allowHost });
 // stream closing" errors everywhere and breaks the tests. :/
 app._close = () => {
   cooler.close();
-  setTimeout(() => {
-    process.exit();
-  }, 20000);
 };
 
 module.exports = app;
diff --git a/src/models.js b/src/models.js
index 3e91d19..08eb994 100644
--- a/src/models.js
+++ b/src/models.js
@@ -195,55 +195,6 @@ module.exports = ({ cooler, isPublic }) => {
     });
   };
 
-  cooler.open().then((ssb) => {
-    console.time("about-name-warmup"); // benchmark the time it takes to stream all existing about messages
-    pull(
-      ssb.query.read({
-        live: true, // keep streaming new messages as they arrive
-        query: [
-          {
-            $filter: {
-              // all messages of type:about that have a name field that is typeof string
-              value: {
-                content: {
-                  type: "about",
-                  name: { $is: "string" },
-                },
-              },
-            },
-          },
-        ],
-      }),
-      pull.filter((msg) => {
-        // backlog of data is done, only new values from now on
-        if (msg.sync && msg.sync === true) {
-          console.timeEnd("about-name-warmup");
-          transposeLookupTable(); // fire once now
-          setInterval(transposeLookupTable, 1000 * 60); // and then every 60 seconds
-          return false;
-        }
-        // only pick messages about self
-        return msg.value.author == msg.value.content.about;
-      }),
-      pull.drain((msg) => {
-        const name = msg.value.content.name;
-        const ts = msg.value.timestamp;
-        const feed = msg.value.author;
-
-        const newEntry = { name, ts };
-        const currentEntry = feeds_to_name[feed];
-        if (typeof currentEntry == "undefined") {
-          dirty = true;
-          feeds_to_name[feed] = newEntry;
-        } else if (currentEntry.ts < ts) {
-          // overwrite entry if it's newer
-          dirty = true;
-          feeds_to_name[feed] = newEntry;
-        }
-      })
-    );
-  });
-
   models.about = {
     publicWebHosting: async (feedId) => {
       const result = await getAbout({
diff --git a/test/basic.js b/test/basic.js
index 2f0fca5..ef50631 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -15,7 +15,7 @@ const paths = [
   "/profile/edit",
   "/public/latest",
   "/public/latest/extended",
-  // "/public/latest/summaries",
+  "/public/latest/summaries",
   "/public/latest/threads",
   "/public/latest/topics",
   "/public/popular/day",

I've tried only deleting the setInterval() and that doesn't fix it -- maybe we need to abort the stream when the app closes? I think this is our only pull-stream that exists outside of a route (?), so maybe that's the new pattern we need to develop support for.

@christianbundy christianbundy merged commit 4e0960d into fraction:master Nov 11, 2020
christianbundy added a commit to christianbundy/oasis that referenced this pull request Nov 11, 2020
Problem: Recently there was a PR [0] merged with a quickfix to avoid
some test failures, which is something I've been trying to avoid. While
`process.exit()` works fine, I'm worried that it means we don't
understand what's happening under the hood, *plus* I have the [maybe
unjustified?] worry that it might kill the process during a database
write or something dangerous. It looks like this particular test hang
was caused by both a stream and some number of intervals that were left
open.

Solution: Provide a way to close the stream and intervals in `index.js`
and ensure that we do that before closing the server.

[0]: fraction#462
@christianbundy
Copy link
Member

Thanks for this patch, I'm super excited to have it in!

@cblgh
Copy link
Contributor

cblgh commented Nov 11, 2020

yaaaaaaay!!!!!!!!!!!!!!!!!!!!!!

@cblgh cblgh mentioned this pull request Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
8 participants