diff --git a/src/AddTagSubscriptionAttribute.php b/src/AddTagSubscriptionAttribute.php index 438f275..3f95270 100644 --- a/src/AddTagSubscriptionAttribute.php +++ b/src/AddTagSubscriptionAttribute.php @@ -38,7 +38,10 @@ public function __invoke(TagSerializer $serializer, Tag $tag, array $attributes) */ public function getStateFor(Tag $tag, User $actor): TagState { - if (!$tag->relationLoaded('state') || $tag->state->user_id !== $actor->id) { + // If $tag->state is loaded *and* null, this might be because the actor doesn't have tag-specific state + // OR because the wrong actor has been used for loading it. `$tag->stateFor()` will return the correct state. + // If it doesn't exist, it returns a dummy state with the correct actor & tag IDs. + if (!$tag->relationLoaded('state') || is_null($tag->state) || $tag->state->user_id !== $actor->id) { $tag->setRelation('state', $tag->stateFor($actor)); }