Skip to content

Follow accounts that move while a bot follows them #49

Description

@dahlia

Part of #47. This issue covers what happens when an account a bot follows moves elsewhere.

Today the inbox listener chain has no Move listener, so the activity is dropped. The bot keeps following the old account, which usually goes quiet after the move, and the bot silently stops seeing that person's new posts. Bots that repost or aggregate the accounts they follow feel this the most.

Mastodon users following the same account get moved over automatically, and FEP-7628 requires receivers to either follow the target or tell the user that the account moved. A bot has no user to tell, so it should follow.

Handling incoming Move activities

Register a Move listener in the inbox listener chain. The handler:

  1. Ignores the activity unless its actorId equals its objectId. This is push mode, the only mode Mastodon sends or accepts.
  2. Finds the bots that follow the old actor with Repository.findFollowedBots(), and stops there if there are none. Move is addressed to followers, but it can also arrive through the shared inbox for unrelated reasons.
  3. Fetches the target with the bot's document loader rather than trusting an embedded object, and ignores the activity unless the target's aliasIds contains the old actor's URI. This is the same check Mastodon runs.
  4. For each of those bots, calls Session.follow() on the target unless the bot already follows it, then Session.unfollow() on the old actor, then fires the new event described below.

A Move is often delivered more than once, and a bot can receive several copies through different inboxes. The check in step 4 against Repository.getFollowee() makes the handler idempotent without extra bookkeeping.

The onFolloweeMove event

Add a FolloweeMoveEventHandler type to src/events.ts and an onFolloweeMove property to the Bot interface and CreateBotOptions, wired through src/bot-impl.ts the same way the other handlers are:

export type FolloweeMoveEventHandler<TContextData> = (
  session: Session<TContextData>,
  oldActor: Actor,
  newActor: Actor,
) => void | Promise<void>;

The event fires after the re-follow, mirroring how onFollow fires after followerPolicy has already accepted a request. A bot that doesn't want to follow the new account can unfollow it from the handler. The name spells out followee because a plain onMove would read as the bot itself moving, which is what #50 is about.

Open question

Automatic re-following could be a policy option instead of a fixed behavior, something like followMovedAccounts: false next to followerPolicy. I lean toward not adding it until someone asks. Unfollowing from the handler covers the rare bot that wants otherwise, and every option added to CreateBotOptions is one more thing to document and support.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions