My plugin that hacks bookmarks into social shares

I’m an advanced rails dev with intermediate JS skills (not Ember, tho), so I decided to hack together a plugin for a new (not yet even soft-launched) community that lets me use my Discourse profile as a kind of blog.

Here’s the plugin: https://github.com/dotfire/sayonara

Here’s my profile on the new community site: https://talk.opensourcedefense.org/u/jonstokes

The modifications are simple:

  1. It makes your bookmarks visible to everyone
  2. It sets your /u/username default route to userActivity.bookmarks
  3. It does some minor stuff like rearranging menus and forcing the expanded profile view up top.

This was super quick-and-dirty weekend hack, so I’d like to make it better. To this end, I have a few plugin dev-related questions that I’ve not yet been able to answer. Thanks in advance for any advice or tips.

Current best practice for plugin dev on OS X

Given that I spend a lot of time in rails, setting up discourse as a rails app on OS X was easy for me. I didn’t bother with any vagrant stuff. But maybe this was a mistake. I say this for a few reasons.

First, I wasn’t able to get sidekiq working right (although I didn’t spend a bunch of time on it. It looks like Sidekiq is trying to connect to localhost:443 and throwing errors… anyway…)

But the bigger problem is that I get different results locally than I do when I deploy to EC2 via docker. For instance, I’ve overridden some JS controllers and routes, and that stuff works in prod but not in dev. I’d like to get better dev/prod parity, so maybe I need to use vagrant and ubuntu?

But I also take this mismatch as a hint that I’m Doing It Wrong and that the fact that prod works is down to some sort of quirk of loading order and asset compilation, which is bad. Which brings me to…

Overriding JS the redirect initializer.

I tried to add a new JS initializer on the model of some other plugins by just declaring it in the same folder as /initializers/url-redirects.js.es6, but that didn’t seem to work. I’ve since realized my new initializer probably needs to remove the original rewrites from rewrites in DiscourseURL, so I’ll do that later. So for now, I’m overriding url-redirects.

Well, this works fine in prod, but in dev it only half works. I redirect to the Activity page but not all the way to Bookmarks. No idea what’s going on there.

Manipulating the expanded vs. collapsed profile

At one point I had a build working locally that would expand and collapse the profile up top correctly depending on your path. So for non-viewingMe in users, user.summary and userActvity.bookmarks would show you the larger profile, and the rest would collapse. This worked in dev, not in prod, though.

I ended forcing the profile to be expanded in all /user views, which is not awesome.

Next steps

Here are some next steps I’m thinking about for this, once I get the above ironed out:

  1. The “feed”-style view is only for Bookmarks, and the rest show the normal activity feed.
  2. I got preview images half working (i.e. I pulled them into the UserAction.stream query and serialized them out, but my CSS chops suck so the front-end styling was gross so I’ll deal with it later.)
  3. Given my headaches with overriding JS, I didn’t want to deal with CSS assets so I just used style tags. So that has to be fixed.
  4. Some sort of styling that sets off a share of a reply from a share of a top-level post. That way, if I bookmark/share a reply to a post I’ve already shared, it doesn’t look like a dupe.
  5. Doing the same thing for the Groups profiles, so that a I hack together a group blog at .../groupname by adding the “bloggers” to a group and showing all their bookmarks on one feed.
  6. Moving away from a bookmarks-based hack to an actual share button that works just like bookmarks, but uses a different endpoint and gives me more control over filtering what I show and where. I basically want to be able to write my own queries against the posts and topics tables to show a feed at a location, but I’m a long ways away from untangling how to do that on the front end. (The back-end part of this would be super easy for me… I deal with this sort of API stuff and postgres all day long.)

Anyway, I didn’t mean to make the post this long. Thanks for reading!

6 Likes

Cool experiment!

I suggest you start new topics for your individual dev questions so they don’t get lost in the pile. You can link them all back here for context.

1 Like

That’s intersting an I think it’s much way “friendly” then stats about usual users don’t actually care. As a suggestion, you could rename the bookmarks tab to “My Wall” or “My public feed” and the “bookmark this” button to “Add to my wall/public feed”.

Yeah, there are a bunch of things I want to do along those lines. I didn’t rename it in this initial build because I’ll probably leave the bookmarks feature alone and add a “Share to my feed” feature on top of it – maybe by resurrecting the deleted “Star” feature and hacking it.

1 Like