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:
- Ignores the activity unless its
actorId equals its objectId. This is push mode, the only mode Mastodon sends or accepts.
- 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.
- 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.
- 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.
Part of #47. This issue covers what happens when an account a bot follows moves elsewhere.
Today the inbox listener chain has no
Movelistener, 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
MoveactivitiesRegister a
Movelistener in the inbox listener chain. The handler:actorIdequals itsobjectId. This is push mode, the only mode Mastodon sends or accepts.Repository.findFollowedBots(), and stops there if there are none.Moveis addressed to followers, but it can also arrive through the shared inbox for unrelated reasons.aliasIdscontains the old actor's URI. This is the same check Mastodon runs.Session.follow()on the target unless the bot already follows it, thenSession.unfollow()on the old actor, then fires the new event described below.A
Moveis often delivered more than once, and a bot can receive several copies through different inboxes. The check in step 4 againstRepository.getFollowee()makes the handler idempotent without extra bookkeeping.The
onFolloweeMoveeventAdd a
FolloweeMoveEventHandlertype to src/events.ts and anonFolloweeMoveproperty to theBotinterface andCreateBotOptions, wired through src/bot-impl.ts the same way the other handlers are:The event fires after the re-follow, mirroring how
onFollowfires afterfollowerPolicyhas 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 plainonMovewould 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: falsenext tofollowerPolicy. I lean toward not adding it until someone asks. Unfollowing from the handler covers the rare bot that wants otherwise, and every option added toCreateBotOptionsis one more thing to document and support.