mirror of
https://github.com/friendica/friendica
synced 2025-04-22 17:50:11 +00:00
Fix follow/unfollow
This commit is contained in:
parent
26f8392754
commit
534db0d09a
23 changed files with 236 additions and 90 deletions
|
@ -43,9 +43,9 @@ class Block extends BaseApi
|
|||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, true);
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$contact = Contact::getById($cdata['user']);
|
||||
$ucid = Contact::getUserContactId($this->parameters['id'], $uid);
|
||||
if ($ucid) {
|
||||
$contact = Contact::getById($ucid);
|
||||
if (!empty($contact)) {
|
||||
// Mastodon-expected behavior: relationship is severed on block
|
||||
Contact::terminateFriendship($contact);
|
||||
|
|
|
@ -51,9 +51,9 @@ class Lists extends BaseApi
|
|||
|
||||
$lists = [];
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($id, $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$circles = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]);
|
||||
$ucid = Contact::getUserContactId($id, $uid);
|
||||
if ($ucid) {
|
||||
$circles = DBA::select('group_member', ['gid'], ['contact-id' => $ucid]);
|
||||
while ($circle = DBA::fetch($circles)) {
|
||||
$lists[] = DI::mstdnList()->createFromCircleId($circle['gid']);
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ class Note extends BaseApi
|
|||
'comment' => '',
|
||||
], $request);
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
$ucid = Contact::getUserContactId($this->parameters['id'], $uid);
|
||||
if (!$ucid) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
|
||||
Contact::update(['info' => $request['comment']], ['id' => $ucid]);
|
||||
|
||||
$this->jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ class Unfollow extends BaseApi
|
|||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
$ucid = Contact::getUserContactId($this->parameters['id'], $uid);
|
||||
if (!$ucid) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cdata['user']);
|
||||
$contact = Contact::getById($ucid);
|
||||
|
||||
Contact::unfollow($contact);
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace Friendica\Module\Api\Mastodon;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
@ -47,12 +46,12 @@ class FollowRequests extends BaseApi
|
|||
$this->checkAllowedScope(self::SCOPE_FOLLOW);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
$ucid = Contact::getUserContactId($this->parameters['id'], $uid);
|
||||
if (!$ucid) {
|
||||
throw new HTTPException\NotFoundException('Contact not found');
|
||||
}
|
||||
|
||||
$introduction = DI::intro()->selectForContact($cdata['user']);
|
||||
$introduction = DI::intro()->selectForContact($ucid);
|
||||
|
||||
$contactId = $introduction->cid;
|
||||
|
||||
|
|
|
@ -110,8 +110,7 @@ class ListTimeline extends BaseApi
|
|||
|
||||
private function getStatusesForGroup(int $uid, array $request): array
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID((int)substr($this->parameters['id'], 6), $uid);
|
||||
$cid = $cdata['public'];
|
||||
$cid = Contact::getPublicContactId((int)substr($this->parameters['id'], 6), $uid);
|
||||
|
||||
$condition = ["(`uid` = ? OR (`uid` = ? AND NOT `global`))", 0, $uid];
|
||||
|
||||
|
|
|
@ -81,9 +81,9 @@ class NewDM extends BaseApi
|
|||
}
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
$ucid = Contact::getUserContactId($cid, $uid);
|
||||
|
||||
$id = Mail::send($uid, $cdata['user'], $request['text'], $sub, $replyto);
|
||||
$id = Mail::send($uid, $ucid, $request['text'], $sub, $replyto);
|
||||
|
||||
if ($id > -1) {
|
||||
$ret = $this->directMessage->createFromMailId($id, $uid, $this->getRequestValue($request, 'getText', ''));
|
||||
|
|
|
@ -88,9 +88,9 @@ abstract class DirectMessagesEndpoint extends BaseApi
|
|||
|
||||
$cid = BaseApi::getContactIDForSearchterm($this->getRequestValue($request, 'screen_name', ''), $this->getRequestValue($request, 'profileurl', ''), $this->getRequestValue($request, 'user_id', 0), 0);
|
||||
if (!empty($cid)) {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`contact-id` = ?", $cdata['user']]);
|
||||
$ucid = Contact::getUserContactId($cid, $uid);
|
||||
if ($ucid) {
|
||||
$condition = DBA::mergeConditions($condition, ["`contact-id` = ?", $ucid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,13 +71,13 @@ class Destroy extends ContactEndpoint
|
|||
}
|
||||
|
||||
// Get Contact by given id
|
||||
$cdata = Contact::getPublicAndUserContactID($contact_id, $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$ucid = Contact::getUserContactId($contact_id, $uid);
|
||||
if (!$ucid) {
|
||||
Logger::notice(BaseApi::LOG_PREFIX . 'Not following contact', ['module' => 'api', 'action' => 'friendships_destroy']);
|
||||
throw new HTTPException\NotFoundException('Not following Contact');
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cdata['user']);
|
||||
$contact = Contact::getById($ucid);
|
||||
$user = $this->twitterUser->createFromContactId($contact_id, $uid, true)->toArray();
|
||||
|
||||
try {
|
||||
|
|
|
@ -55,9 +55,9 @@ class Show extends ContactEndpoint
|
|||
$following = false;
|
||||
|
||||
if ($source_cid == Contact::getPublicIdByUserId($uid)) {
|
||||
$cdata = Contact::getPublicAndUserContactID($target_cid, $uid);
|
||||
if (!empty($cdata['user'])) {
|
||||
$usercontact = Contact::getById($cdata['user'], ['rel']);
|
||||
$ucid = Contact::getUserContactId($target_cid, $uid);
|
||||
if ($ucid) {
|
||||
$usercontact = Contact::getById($ucid, ['rel']);
|
||||
switch ($usercontact['rel'] ?? Contact::NOTHING) {
|
||||
case Contact::FOLLOWER:
|
||||
$follower = true;
|
||||
|
|
|
@ -253,7 +253,7 @@ class Contact extends BaseModule
|
|||
$sql_extra = " AND `archive` AND NOT `blocked` AND NOT `pending`";
|
||||
break;
|
||||
case 'pending':
|
||||
$sql_extra = " AND `pending` AND NOT `archive` AND NOT `failed` AND ((`rel` = ?)
|
||||
$sql_extra = " AND `pending` AND NOT `archive` AND ((`rel` = ?)
|
||||
OR `id` IN (SELECT `contact-id` FROM `intro` WHERE `intro`.`uid` = ? AND NOT `ignore`))";
|
||||
$sql_values[] = Model\Contact::SHARING;
|
||||
$sql_values[] = DI::userSession()->getLocalUserId();
|
||||
|
|
|
@ -215,7 +215,7 @@ class Follow extends BaseModule
|
|||
|
||||
$this->baseUrl->redirect($returnPath);
|
||||
} elseif (!empty($result['cid'])) {
|
||||
$this->baseUrl->redirect('contact/' . $result['cid']);
|
||||
$this->baseUrl->redirect('contact/' . Contact::getPublicContactId($result['cid'], $this->session->getLocalUserId()));
|
||||
}
|
||||
|
||||
$this->sysMessages->addNotice($this->t('The contact could not be added.'));
|
||||
|
|
|
@ -91,8 +91,8 @@ class Profile extends BaseModule
|
|||
|
||||
// Backward compatibility: The update still needs a user-specific contact ID
|
||||
// Change to user-contact table check by version 2022.03
|
||||
$cdata = Contact::getPublicAndUserContactID($contact_id, $this->session->getLocalUserId());
|
||||
if (empty($cdata['user']) || !$this->db->exists('contact', ['id' => $cdata['user'], 'deleted' => false])) {
|
||||
$ucid = Contact::getUserContactId($contact_id, $this->session->getLocalUserId());
|
||||
if (!$ucid || !$this->db->exists('contact', ['id' => $ucid, 'deleted' => false])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,14 +134,14 @@ class Profile extends BaseModule
|
|||
}
|
||||
|
||||
if (isset($request['channel_frequency'])) {
|
||||
Contact\User::setChannelFrequency($cdata['user'], $this->session->getLocalUserId(), $request['channel_frequency']);
|
||||
Contact\User::setChannelFrequency($ucid, $this->session->getLocalUserId(), $request['channel_frequency']);
|
||||
}
|
||||
|
||||
if (isset($request['channel_only'])) {
|
||||
Contact\User::setChannelOnly($cdata['user'], $this->session->getLocalUserId(), $request['channel_only']);
|
||||
Contact\User::setChannelOnly($ucid, $this->session->getLocalUserId(), $request['channel_only']);
|
||||
}
|
||||
|
||||
if (!Contact::update($fields, ['id' => $cdata['user'], 'uid' => $this->session->getLocalUserId()])) {
|
||||
if (!Contact::update($fields, ['id' => $ucid, 'uid' => $this->session->getLocalUserId()])) {
|
||||
$this->systemMessages->addNotice($this->t('Failed to update contact record.'));
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,18 @@ class Profile extends BaseModule
|
|||
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
|
||||
}
|
||||
|
||||
// Fetch the protocol from the user's contact.
|
||||
$usercontact = Contact::getById($data['user'], ['network', 'protocol']);
|
||||
if ($this->db->isResult($usercontact)) {
|
||||
$contact['network'] = $usercontact['network'];
|
||||
$contact['protocol'] = $usercontact['protocol'];
|
||||
}
|
||||
|
||||
if (empty($contact['network']) && Contact::isLocal($contact['url']) ) {
|
||||
$contact['network'] = Protocol::DFRN;
|
||||
$contact['protocol'] = Protocol::ACTIVITYPUB;
|
||||
}
|
||||
|
||||
// Don't display contacts that are about to be deleted
|
||||
if ($this->db->isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
|
||||
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
|
||||
|
|
|
@ -30,6 +30,7 @@ use Friendica\Core\Renderer;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model;
|
||||
use Friendica\Model\Contact as ModelContact;
|
||||
use Friendica\Module\Contact;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Module\Security\Login;
|
||||
|
@ -90,7 +91,7 @@ class Revoke extends BaseModule
|
|||
|
||||
DI::sysmsg()->addNotice($this->t('Follow was successfully revoked.'));
|
||||
|
||||
$this->baseUrl->redirect('contact/' . $this->parameters['id']);
|
||||
$this->baseUrl->redirect('contact/' . ModelContact::getPublicContactId($this->parameters['id'], DI::userSession()->getLocalUserId()));
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
|
|
|
@ -168,7 +168,7 @@ class Unfollow extends \Friendica\BaseModule
|
|||
$this->baseUrl->redirect($base_return_path);
|
||||
}
|
||||
|
||||
$return_path = $base_return_path . '/' . $contact['id'];
|
||||
$return_path = $base_return_path . '/' . Contact::getPublicContactId($contact['id'], $uid);
|
||||
|
||||
try {
|
||||
Contact::unfollow($contact);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue