+
+ $id = $apidata['api_arg'];
+
+ $other = $this->get_user($id);
+
+ if (!$other) {
+ $this->client_error(_('Could not follow user: User not found.'), 403, $apidata['content-type']);
+ exit();
+ }
+
+ $user = $apidata['user'];
+
+ if ($user->isSubscribed($other)) {
+ $this->client_error("Could not follow user: $other->nickname is already on your list.", 403, $apidata['content-type']);
+ exit();
+ }
+
+ $sub = new Subscription();
+
+ $sub->query('BEGIN');
+
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $other->id;
+ $sub->created = DB_DataObject_Cast::dateTime(); # current time
+
+ $result = $sub->insert();
+
+ if (!$result) {
+ $this->client_error("Could not follow user: $other->nickname.", 400, $apidata['content-type']);
+ exit();
+ }
+
+ $sub->query('COMMIT');
+
+ mail_subscribe_notify($other, $user);
+
+ $type = $apidata['content-type'];
+ $this->init_document($type);
+ $this->show_profile($other, $type);
+ $this->end_document($type);