repo is here https://github.com/dtschust/fake-mastodon-instance/tree/c858a0d9427efc9c16a1c73bfcc0545bbdacb343
Best place to start looking is src/index.js
, which is the express server that acts as a Mastodon instance.
In order to mirror a user from another service in a way that Mastodon recognizes, you must implement the following:
- Webfinger ( https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/index.js#L488 )
- Example response: http://fake-mastodon-instance.herokuapp.com/.well-known/webfinger?resource=acct:nuncamind@fake-mastodon-instance.herokuapp.com
- Points to a user's profile page
- Note: my implementation assumes any user exists, you'll probably want to do some validation here to check if the user should exist first.
- User profile ( https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/index.js#L488 )
- Example response: https://fake-mastodon-instance.herokuapp.com/users/nuncamind
- Imports getUserJson which shows the actual structure of the response: https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/get-user-json.js
- Inbox ( https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/index.js#L162 )
- Hacks to avoid:
- I hardcoded to ignore any message that doesn't concern my personal account.
- I do no validation of the http signature, which you definitely want to do. See the Mastodon blog post for more.
- Inbox must accept and implement two message types:
- Follow: Must send back an Accept/Reject message in response, see here: https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/index.js#L184
- Undo with
Object.type
set to Follow: This is the equivalent unfollow event. - You must persist the list of followers on your end somehow. Note: you can receive duplicate follow or unfollow events with the same id. You should ignore them once you've dealt with them, so that you don't have to deal with race conditions.
- Posting
- I post from my
crawlTwitter
script https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/bin/crawlTwitter.js#L242 - It uses my
sendMessage
util, this is the best place to start https://github.com/dtschust/fake-mastodon-instance/blob/c858a0d9427efc9c16a1c73bfcc0545bbdacb343/src/send-message.js - Hack: mine is hardcoded to post to only my mastodon instance, a true implementation would need to keep track of all followers' instances and post to all of them when an update occurs.
- I post from my
- Hacks to avoid:
Note: I also didn't implement outbox support, which I believe is necessary for a user to be able view a profile page's history for an account that already exists.