- $other_nickname = $this->arg('unsubscribeto');
- $result=subs_unsubscribe_user($user,$other_nickname);
- if($result!=true) {
- common_user_error($result);
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ // TRANS: Client error displayed when the session token does not match or is not given.
+ $this->clientError(_('There was a problem with your session token. ' .
+ 'Try again, please.'));
+ }
+
+ $other_id = $this->arg('unsubscribeto');
+
+ if (!$other_id) {
+ // TRANS: Client error displayed when trying to unsubscribe without providing a profile ID.
+ $this->clientError(_('No profile ID in request.'));
+ }
+
+ $other = Profile::getKV('id', $other_id);
+
+ if (!($other instanceof Profile)) {
+ // TRANS: Client error displayed when trying to unsubscribe while providing a non-existing profile ID.
+ $this->clientError(_('No profile with that ID.'));
+ }
+
+ try {
+ Subscription::cancel($this->scoped, $other);
+ } catch (Exception $e) {
+ $this->clientError($e->getMessage());
+ }