Merge pull request #5704 from MrPetovan/bug/fix-unfollow
Fix unfollow sharing-only contacts (except connector protocols)
This commit is contained in:
commit
196ef0111c
3 changed files with 108 additions and 99 deletions
|
@ -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
|
||||
$follow = '';
|
||||
$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_text = L10n::t("Disconnect/Unfollow");
|
||||
} else {
|
||||
$follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
|
||||
$follow_text = L10n::t("Connect/Follow");
|
||||
}
|
||||
}
|
||||
|
||||
if ($contact['uid'] == 0) {
|
||||
} else {
|
||||
$follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]);
|
||||
$follow_text = L10n::t("Connect/Follow");
|
||||
}
|
||||
|
|
154
mod/unfollow.php
154
mod/unfollow.php
|
@ -10,53 +10,65 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
|
||||
function unfollow_post(App $a)
|
||||
function unfollow_post()
|
||||
{
|
||||
$return_url = $_SESSION['return_url'];
|
||||
|
||||
if (!local_user()) {
|
||||
notice(L10n::t('Permission denied.') . EOL);
|
||||
goaway($_SESSION['return_url']);
|
||||
notice(L10n::t('Permission denied.'));
|
||||
goaway($return_url);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
||||
if ($_REQUEST['cancel']) {
|
||||
goaway($_SESSION['return_url']);
|
||||
goaway($return_url);
|
||||
}
|
||||
|
||||
$uid = local_user();
|
||||
$url = notags(trim($_REQUEST['url']));
|
||||
$return_url = $_SESSION['return_url'];
|
||||
$url = notags(trim(defaults($_REQUEST, 'url', '')));
|
||||
|
||||
$condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
|
||||
$uid, Contact::FRIEND, normalise_link($url),
|
||||
normalise_link($url), $url, Protocol::STATUSNET];
|
||||
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
|
||||
$uid, Contact::SHARING, Contact::FRIEND, normalise_link($url),
|
||||
normalise_link($url), $url];
|
||||
$contact = DBA::selectFirst('contact', [], $condition);
|
||||
|
||||
if (!DBA::isResult($contact)) {
|
||||
notice(L10n::t("Contact wasn't found or can't be unfollowed."));
|
||||
} else {
|
||||
if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
|
||||
$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']);
|
||||
notice(L10n::t("You aren't following this contact."));
|
||||
goaway($return_url);
|
||||
// NOTREACHED
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
function unfollow_content(App $a)
|
||||
{
|
||||
if (! local_user()) {
|
||||
notice(L10n::t('Permission denied.') . EOL);
|
||||
if (!local_user()) {
|
||||
notice(L10n::t('Permission denied.'));
|
||||
goaway($_SESSION['return_url']);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
@ -64,78 +76,74 @@ function unfollow_content(App $a)
|
|||
$uid = local_user();
|
||||
$url = notags(trim($_REQUEST['url']));
|
||||
|
||||
$submit = L10n::t('Submit Request');
|
||||
|
||||
$condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
|
||||
local_user(), Contact::FRIEND, normalise_link($url),
|
||||
normalise_link($url), $url, Protocol::STATUSNET];
|
||||
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
|
||||
local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url),
|
||||
normalise_link($url), $url];
|
||||
|
||||
$contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);
|
||||
|
||||
if (!DBA::isResult($contact)) {
|
||||
notice(L10n::t("You aren't a friend of this contact.").EOL);
|
||||
$submit = "";
|
||||
notice(L10n::t("You aren't following this contact."));
|
||||
goaway('contacts');
|
||||
// NOTREACHED
|
||||
}
|
||||
|
||||
if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) {
|
||||
notice(L10n::t("Unfollowing is currently not supported by your network.").EOL);
|
||||
$submit = "";
|
||||
if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
|
||||
notice(L10n::t('Unfollowing is currently not supported by your network.'));
|
||||
goaway('contacts/' . $contact['id']);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
||||
$request = System::baseUrl()."/unfollow";
|
||||
$request = System::baseUrl() . '/unfollow';
|
||||
$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) {
|
||||
notice(L10n::t('Permission denied.') . EOL);
|
||||
if (!DBA::isResult($self)) {
|
||||
notice(L10n::t('Permission denied.'));
|
||||
goaway($_SESSION['return_url']);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
||||
$myaddr = $r[0]["url"];
|
||||
|
||||
// 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, [
|
||||
'$header' => htmlentities($header),
|
||||
'$desc' => "",
|
||||
'$pls_answer' => "",
|
||||
'$does_know_you' => "",
|
||||
'$add_note' => "",
|
||||
'$page_desc' => "",
|
||||
'$friendica' => "",
|
||||
'$statusnet' => "",
|
||||
'$diaspora' => "",
|
||||
'$diasnote' => "",
|
||||
'$your_address' => L10n::t('Your Identity Address:'),
|
||||
'$invite_desc' => "",
|
||||
'$emailnet' => "",
|
||||
'$submit' => $submit,
|
||||
'$cancel' => L10n::t('Cancel'),
|
||||
'$nickname' => "",
|
||||
'$name' => $contact["name"],
|
||||
'$url' => $contact["url"],
|
||||
'$zrl' => Contact::magicLink($contact["url"]),
|
||||
'$url_label' => L10n::t("Profile URL"),
|
||||
'$myaddr' => $myaddr,
|
||||
'$request' => $request,
|
||||
'$keywords' => "",
|
||||
'$keywords_label' => ""
|
||||
$o = replace_macros($tpl, [
|
||||
'$header' => htmlentities($header),
|
||||
'$desc' => '',
|
||||
'$pls_answer' => '',
|
||||
'$does_know_you' => '',
|
||||
'$add_note' => '',
|
||||
'$page_desc' => '',
|
||||
'$friendica' => '',
|
||||
'$statusnet' => '',
|
||||
'$diaspora' => '',
|
||||
'$diasnote' => '',
|
||||
'$your_address' => L10n::t('Your Identity Address:'),
|
||||
'$invite_desc' => '',
|
||||
'$emailnet' => '',
|
||||
'$submit' => L10n::t('Submit Request'),
|
||||
'$cancel' => L10n::t('Cancel'),
|
||||
'$nickname' => '',
|
||||
'$name' => $contact['name'],
|
||||
'$url' => $contact['url'],
|
||||
'$zrl' => Contact::magicLink($contact['url']),
|
||||
'$url_label' => L10n::t('Profile URL'),
|
||||
'$myaddr' => $self['url'],
|
||||
'$request' => $request,
|
||||
'$keywords' => '',
|
||||
'$keywords_label'=> ''
|
||||
]);
|
||||
|
||||
$a->page['aside'] = "";
|
||||
Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
|
||||
$a->page['aside'] = '';
|
||||
Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url']));
|
||||
|
||||
$o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]);
|
||||
|
||||
// Show last public posts
|
||||
$o .= Contact::getPostsFromUrl($contact["url"]);
|
||||
$o .= Contact::getPostsFromUrl($contact['url']);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
|
|
@ -13,27 +13,33 @@ use Friendica\Util\Network;
|
|||
*/
|
||||
class Protocol
|
||||
{
|
||||
const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
|
||||
const DIASPORA = 'dspr'; // Diaspora
|
||||
const DIASPORA2 = 'dspc'; // Diaspora connector
|
||||
const STATUSNET = 'stac'; // Statusnet connector
|
||||
const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
|
||||
const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
|
||||
const MAIL = 'mail'; // IMAP/POP
|
||||
const XMPP = 'xmpp'; // XMPP - Currently unsupported
|
||||
// Native support
|
||||
const ACTIVITYPUB = 'apub'; // ActivityPub
|
||||
const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations
|
||||
const DIASPORA = 'dspr'; // Diaspora
|
||||
const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol
|
||||
const MAIL = 'mail'; // IMAP/POP
|
||||
const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations
|
||||
|
||||
const FACEBOOK = 'face'; // Facebook API
|
||||
const LINKEDIN = 'lnkd'; // LinkedIn
|
||||
const MYSPACE = 'mysp'; // MySpace - Currently unsupported
|
||||
const GPLUS = 'goog'; // Google+
|
||||
const PUMPIO = 'pump'; // pump.io
|
||||
const TWITTER = 'twit'; // Twitter
|
||||
const NATIVE_SUPPORT = [self::DFRN, self::DIASPORA, self::OSTATUS, self::FEED, self::MAIL, self::ACTIVITYPUB];
|
||||
|
||||
// Supported through a connector
|
||||
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
|
||||
const ICALENDAR = 'ical'; // iCalendar - Currently unsupported
|
||||
const PNUT = 'pnut'; // pnut.io - Currently unsupported
|
||||
const ZOT = 'zot!'; // Zot! - Currently unsupported
|
||||
// Currently unsupported
|
||||
const ICALENDAR = 'ical'; // iCalendar
|
||||
const MYSPACE = 'mysp'; // MySpace
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue