Merge pull request #5704 from MrPetovan/bug/fix-unfollow

Fix unfollow sharing-only contacts (except connector protocols)
This commit is contained in:
Michael Vogel 2018-08-31 15:40:51 +00:00 committed by GitHub
commit 196ef0111c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 99 deletions

View file

@ -596,17 +596,12 @@ function contacts_content(App $a, $update = 0)
/// @todo Only show the following link with DFRN when the remote version supports it /// @todo Only show the following link with DFRN when the remote version supports it
$follow = ''; $follow = '';
$follow_text = ''; $follow_text = '';
if (in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) { if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) {
if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
$follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]); $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]);
$follow_text = L10n::t("Disconnect/Unfollow"); $follow_text = L10n::t("Disconnect/Unfollow");
} else {
$follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
$follow_text = L10n::t("Connect/Follow");
} }
} } else {
if ($contact['uid'] == 0) {
$follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]); $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
$follow_text = L10n::t("Connect/Follow"); $follow_text = L10n::t("Connect/Follow");
} }

View file

@ -10,53 +10,65 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User;
function unfollow_post(App $a) function unfollow_post()
{ {
$return_url = $_SESSION['return_url'];
if (!local_user()) { if (!local_user()) {
notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.'));
goaway($_SESSION['return_url']); goaway($return_url);
// NOTREACHED // NOTREACHED
} }
if ($_REQUEST['cancel']) { if ($_REQUEST['cancel']) {
goaway($_SESSION['return_url']); goaway($return_url);
} }
$uid = local_user(); $uid = local_user();
$url = notags(trim($_REQUEST['url'])); $url = notags(trim(defaults($_REQUEST, 'url', '')));
$return_url = $_SESSION['return_url'];
$condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
$uid, Contact::FRIEND, normalise_link($url), $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
normalise_link($url), $url, Protocol::STATUSNET]; normalise_link($url), $url];
$contact = DBA::selectFirst('contact', [], $condition); $contact = DBA::selectFirst('contact', [], $condition);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
notice(L10n::t("Contact wasn't found or can't be unfollowed.")); notice(L10n::t("You aren't following this contact."));
} else { goaway($return_url);
if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { // NOTREACHED
$r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
intval($uid)
);
if (DBA::isResult($r)) {
Contact::terminateFriendship($r[0], $contact);
}
}
DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
info(L10n::t('Contact unfollowed').EOL);
goaway(System::baseUrl().'/contacts/'.$contact['id']);
} }
goaway($return_url);
if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
notice(L10n::t('Unfollowing is currently not supported by your network.'));
goaway($return_url);
// NOTREACHED
}
$owner = User::getOwnerDataById($uid);
if ($owner) {
Contact::terminateFriendship($owner, $contact);
}
// Sharing-only contacts get deleted as there no relationship any more
if ($contact['rel'] == Contact::SHARING) {
Contact::remove($contact['id']);
$return_path = 'contacts';
} else {
DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
$return_path = 'contacts/' . $contact['id'];
}
info(L10n::t('Contact unfollowed'));
goaway($return_path);
// NOTREACHED // NOTREACHED
} }
function unfollow_content(App $a) function unfollow_content(App $a)
{ {
if (! local_user()) { if (!local_user()) {
notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.'));
goaway($_SESSION['return_url']); goaway($_SESSION['return_url']);
// NOTREACHED // NOTREACHED
} }
@ -64,78 +76,74 @@ function unfollow_content(App $a)
$uid = local_user(); $uid = local_user();
$url = notags(trim($_REQUEST['url'])); $url = notags(trim($_REQUEST['url']));
$submit = L10n::t('Submit Request'); $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
$condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", normalise_link($url), $url];
local_user(), Contact::FRIEND, normalise_link($url),
normalise_link($url), $url, Protocol::STATUSNET];
$contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
notice(L10n::t("You aren't a friend of this contact.").EOL); notice(L10n::t("You aren't following this contact."));
$submit = ""; goaway('contacts');
// NOTREACHED // NOTREACHED
} }
if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) { if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
notice(L10n::t("Unfollowing is currently not supported by your network.").EOL); notice(L10n::t('Unfollowing is currently not supported by your network.'));
$submit = ""; goaway('contacts/' . $contact['id']);
// NOTREACHED // NOTREACHED
} }
$request = System::baseUrl()."/unfollow"; $request = System::baseUrl() . '/unfollow';
$tpl = get_markup_template('auto_request.tpl'); $tpl = get_markup_template('auto_request.tpl');
$r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid)); $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
if (!$r) { if (!DBA::isResult($self)) {
notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.'));
goaway($_SESSION['return_url']); goaway($_SESSION['return_url']);
// NOTREACHED // NOTREACHED
} }
$myaddr = $r[0]["url"];
// Makes the connection request for friendica contacts easier // Makes the connection request for friendica contacts easier
$_SESSION["fastlane"] = $contact["url"]; $_SESSION['fastlane'] = $contact['url'];
$header = L10n::t("Disconnect/Unfollow"); $header = L10n::t('Disconnect/Unfollow');
$o = replace_macros($tpl, [ $o = replace_macros($tpl, [
'$header' => htmlentities($header), '$header' => htmlentities($header),
'$desc' => "", '$desc' => '',
'$pls_answer' => "", '$pls_answer' => '',
'$does_know_you' => "", '$does_know_you' => '',
'$add_note' => "", '$add_note' => '',
'$page_desc' => "", '$page_desc' => '',
'$friendica' => "", '$friendica' => '',
'$statusnet' => "", '$statusnet' => '',
'$diaspora' => "", '$diaspora' => '',
'$diasnote' => "", '$diasnote' => '',
'$your_address' => L10n::t('Your Identity Address:'), '$your_address' => L10n::t('Your Identity Address:'),
'$invite_desc' => "", '$invite_desc' => '',
'$emailnet' => "", '$emailnet' => '',
'$submit' => $submit, '$submit' => L10n::t('Submit Request'),
'$cancel' => L10n::t('Cancel'), '$cancel' => L10n::t('Cancel'),
'$nickname' => "", '$nickname' => '',
'$name' => $contact["name"], '$name' => $contact['name'],
'$url' => $contact["url"], '$url' => $contact['url'],
'$zrl' => Contact::magicLink($contact["url"]), '$zrl' => Contact::magicLink($contact['url']),
'$url_label' => L10n::t("Profile URL"), '$url_label' => L10n::t('Profile URL'),
'$myaddr' => $myaddr, '$myaddr' => $self['url'],
'$request' => $request, '$request' => $request,
'$keywords' => "", '$keywords' => '',
'$keywords_label' => "" '$keywords_label'=> ''
]); ]);
$a->page['aside'] = ""; $a->page['aside'] = '';
Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"])); Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
$o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]); $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
// Show last public posts // Show last public posts
$o .= Contact::getPostsFromUrl($contact["url"]); $o .= Contact::getPostsFromUrl($contact['url']);
return $o; return $o;
} }

View file

@ -13,27 +13,33 @@ use Friendica\Util\Network;
*/ */
class Protocol class Protocol
{ {
const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations // Native support
const DIASPORA = 'dspr'; // Diaspora const ACTIVITYPUB = 'apub'; // ActivityPub
const DIASPORA2 = 'dspc'; // Diaspora connector const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
const STATUSNET = 'stac'; // Statusnet connector const DIASPORA = 'dspr'; // Diaspora
const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol const MAIL = 'mail'; // IMAP/POP
const MAIL = 'mail'; // IMAP/POP const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
const XMPP = 'xmpp'; // XMPP - Currently unsupported
const FACEBOOK = 'face'; // Facebook API const NATIVE_SUPPORT = [self::DFRN, self::DIASPORA, self::OSTATUS, self::FEED, self::MAIL, self::ACTIVITYPUB];
const LINKEDIN = 'lnkd'; // LinkedIn
const MYSPACE = 'mysp'; // MySpace - Currently unsupported // Supported through a connector
const GPLUS = 'goog'; // Google+
const PUMPIO = 'pump'; // pump.io
const TWITTER = 'twit'; // Twitter
const APPNET = 'apdn'; // app.net - Dead protocol const APPNET = 'apdn'; // app.net - Dead protocol
const DIASPORA2 = 'dspc'; // Diaspora connector
const FACEBOOK = 'face'; // Facebook API
const GPLUS = 'goog'; // Google+
const LINKEDIN = 'lnkd'; // LinkedIn
const PUMPIO = 'pump'; // pump.io
const STATUSNET = 'stac'; // Statusnet connector
const TWITTER = 'twit'; // Twitter
const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported // Currently unsupported
const ICALENDAR = 'ical'; // iCalendar - Currently unsupported const ICALENDAR = 'ical'; // iCalendar
const PNUT = 'pnut'; // pnut.io - Currently unsupported const MYSPACE = 'mysp'; // MySpace
const ZOT = 'zot!'; // Zot! - Currently unsupported const NEWS = 'nntp'; // Network News Transfer Protocol
const PNUT = 'pnut'; // pnut.io
const XMPP = 'xmpp'; // XMPP
const ZOT = 'zot!'; // Zot!
const PHANTOM = 'unkn'; // Place holder const PHANTOM = 'unkn'; // Place holder