| @@ -129,9 +129,32 @@ | ||
| 129 | 129 | return array( new Subscription( $term ) ); |
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return array(); | |
| 133 | + // Feeds of a user-backed friend aren't child terms of a subscription | |
| 134 | + // term but are attached to the user as object terms, see | |
| 135 | + // User::save_feeds(). | |
| 136 | + $object_ids = get_objects_in_term( $this->term->term_id, self::TAXONOMY ); | |
| 137 | + if ( is_wp_error( $object_ids ) ) { | |
| 138 | + return array(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + $users = array(); | |
| 142 | + foreach ( $object_ids as $object_id ) { | |
| 143 | + $user = User::get_user_by_id( $object_id ); | |
| 144 | + if ( ! $user ) { | |
| 145 | + continue; | |
| 146 | + } | |
| 147 | + | |
| 148 | + // The same object id can belong to an ap_actor post, so only accept | |
| 149 | + // the user if this feed really is one of theirs. | |
| 150 | + $feeds = $user->get_feeds(); | |
| 151 | + if ( isset( $feeds[ $this->term->term_id ] ) ) { | |
| 152 | + $users[] = $user; | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + return $users; | |
| 134 | 157 | } |
| 135 | 158 | |
| 136 | 159 | /** |
| 137 | 160 | * Whether the feed is active (=subscribed). |
| @@ -230,8 +253,17 @@ | ||
| 230 | 253 | public function set_ap_actor_id( $ap_actor_id ) { |
| 231 | 254 | // Ensure taxonomy is registered for ap_actor post type (may not be during cron). |
| 232 | 255 | if ( class_exists( '\Activitypub\Collection\Remote_Actors' ) ) { |
| 233 | 256 | register_taxonomy_for_object_type( self::TAXONOMY, \Activitypub\Collection\Remote_Actors::POST_TYPE ); |
| 257 | + } | |
| 258 | + | |
| 259 | + $object_ids = get_objects_in_term( $this->term->term_id, self::TAXONOMY ); | |
| 260 | + if ( ! is_wp_error( $object_ids ) ) { | |
| 261 | + foreach ( $object_ids as $object_id ) { | |
| 262 | + if ( absint( $ap_actor_id ) !== absint( $object_id ) && 'ap_actor' === get_post_type( $object_id ) ) { | |
| 263 | + wp_remove_object_terms( $object_id, $this->term->term_id, self::TAXONOMY ); | |
| 264 | + } | |
| 265 | + } | |
| 234 | 266 | } |
| 235 | 267 | |
| 236 | 268 | return wp_set_object_terms( absint( $ap_actor_id ), $this->term->term_id, self::TAXONOMY ); |
| 237 | 269 | } |