H5YR / High5YouRock

H5YR website build with Umbraco 10
8 stars 17 forks source link

Replaced home view tweets with Mastodon statuses #21

Closed abjerner closed 1 year ago

abjerner commented 1 year ago

Hi @OwainWilliams

Following your suggestion last week, I had a look at updating the current code base to show Mastodon statuses instead of Twitter tweets.

As mentioned on Mastodon, I've started developer an API wrapper for the Mastodon API, so I've added Skybrud.Social.Mastodon as a dependency.

I haven't really touched the Twitter logic, so that still exists in the code base. Locally I've commented parts of the TwitterAPICountHostedService so it wouldn't run in the background and cause issues. I'm not entirely sure how this runs on the live site, so I haven't committed my change for this class.

The Mastodon API offers unauthenticated access to to public data, which is why there isn't any access tokens specified in the new implementation.

Service class

Similar to how you have the TwitterHelper class (in the H5YR.Core.Services namespace), I've implemented a MastodonService class that handles much of the Mastodon logic. It appears that Mastodon doesn't support a way to get the status count of a hashtag, so I haven't covered this part.

View component

For the display, I've created a new Mastodon view component that replaces the existing Twitter view component. Like mentioned above, I don't see a way to get the #h4yr status count, so this part is commented out in the view. I also don't see a way Mastodon supports intents, I've also out commented the reply, retweet and like intents.

Styling

The Mastodon API exposes status contents as HTML, so this looks a bit wrong by default:

image

So I've also made some minor style changes to address this:

image

Unfortunately the gulp job fails when I try to run it locally. Not sure if I'm doing anything wrong.

Caching?

I initially thought the tweets in the old implementation were cached, but unless there is some view component caching I haven't spotted, it seems that the 12 tweets were fetched on each request (only the tweet count seems to be cached). I've went with the same approach for Mastodon, but ideally the Mastodon statuses should be fetched in a background task. This is generally a better approach, as it keeps the requests down, and doesn't "spam" the API if the site has a lot of visitors.

OwainWilliams commented 1 year ago

This is amazing @abjerner thanks for the great explanation and the work you've done in this.

I'll try and make sure this is tagged so it goes towards hacktoberfest. 👍

I'll have a look at the code over the next day or so and get it merged and troubleshoot anything that might pop up.

Thanks for this! #h5yr