mirror of
https://github.com/friendica/friendica
synced 2025-04-19 11:50:12 +00:00
Use reshare with Diaspora like with ActivityPub
This commit is contained in:
parent
ed805d1af2
commit
ca8a89ed1c
11 changed files with 108 additions and 84 deletions
|
@ -29,6 +29,7 @@ use Friendica\DI;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/statuses/
|
||||
|
@ -49,12 +50,14 @@ class Reblog extends BaseApi
|
|||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
if (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
Diaspora::performReshare($this->parameters['id'], $uid);
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])));
|
||||
} else {
|
||||
Item::performActivity($item['id'], 'announce', $uid);
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'announce', $uid);
|
||||
|
||||
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,12 +49,21 @@ class Unreblog extends BaseApi
|
|||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
if (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'origin' => true, 'uid' => $uid]);
|
||||
if (empty($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
if (!Item::markForDeletionById($item['id'])) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
DI::mstdnError()->UnprocessableEntity(DI::l10n()->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])));
|
||||
} else {
|
||||
Item::performActivity($item['id'], 'unannounce', $uid);
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'unannounce', $uid);
|
||||
|
||||
System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid)->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,17 +46,26 @@ class Activity extends BaseModule
|
|||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$verb = $this->parameters['verb'];
|
||||
$itemId = $this->parameters['id'];
|
||||
$verb = $this->parameters['verb'];
|
||||
$itemId = $this->parameters['id'];
|
||||
$handled = false;
|
||||
|
||||
if (in_array($verb, ['announce', 'unannounce'])) {
|
||||
$item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [DI::userSession()->getLocalUserId(), 0]]);
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
|
||||
$quote = Post::selectFirst(['id'], ['quote-uri-id' => $item['uri-id'], 'origin' => true, 'uid' => DI::userSession()->getLocalUserId()]);
|
||||
if (!empty($quote['id'])) {
|
||||
if (!Item::markForDeletionById($quote['id'])) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
} else {
|
||||
Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
|
||||
}
|
||||
$handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
|
||||
if (!$handled && !Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue