+
+function unfollow_process(string $url)
+{
+ $base_return_path = 'contact';
+
+ $uid = local_user();
+
+ $owner = User::getOwnerDataById($uid);
+ if (!$owner) {
+ \Friendica\Module\Security\Logout::init();
+ // NOTREACHED
+ }
+
+ $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
+ $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
+ Strings::normaliseLink($url), $url];
+ $contact = DBA::selectFirst('contact', [], $condition);
+
+ if (!DBA::isResult($contact)) {
+ notice(DI::l10n()->t("You aren't following this contact."));
+ DI::baseUrl()->redirect($base_return_path);
+ // NOTREACHED
+ }
+
+ $notice_message = '';
+ $return_path = $base_return_path . '/' . $contact['id'];
+
+ try {
+ $result = Contact::terminateFriendship($owner, $contact);
+
+ if ($result === null) {
+ $notice_message = DI::l10n()->t('Unfollowing is currently not supported by this contact\'s network.');
+ }
+
+ if ($result === false) {
+ $notice_message = DI::l10n()->t('Unable to unfollow this contact, please retry in a few minutes or contact your administrator.');
+ }
+
+ if ($result === true) {
+ $notice_message = DI::l10n()->t('Contact was successfully unfollowed');
+ }
+ } catch (Exception $e) {
+ DI::logger()->error($e->getMessage(), ['owner' => $owner, 'contact' => $contact]);
+ $notice_message = DI::l10n()->t('Unable to unfollow this contact, please contact your administrator');
+ }
+
+ notice($notice_message);
+ DI::baseUrl()->redirect($return_path);
+}