+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ return;
+ }
+
+ $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']);
+ return;
+ }
+
+ $user = $apidata['user'];
+
+ if ($user->isSubscribed($other)) {
+ $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
+ $this->client_error($errmsg, 403, $apidata['content-type']);
+ return;
+ }
+
+ $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) {
+ $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
+ $this->client_error($errmsg, 400, $apidata['content-type']);
+ return;
+ }
+
+ $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);
+