1
0
Fork 0

Merge pull request #11054 from annando/fix-api-reshare

Diaspora reshares via API are fixed now
This commit is contained in:
Hypolite Petovan 2021-12-02 06:22:03 -05:00 committed by GitHub
commit 2a5ecc5a44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 75 deletions

View file

@ -27,7 +27,6 @@ use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
@ -50,8 +49,6 @@ use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Strings;
require_once __DIR__ . '/../mod/item.php';
$API = [];
/**

View file

@ -27,11 +27,11 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Protocol\Diaspora;
/**
* Repeats a status.
@ -62,45 +62,7 @@ class Retweet extends BaseApi
$item_id = $id;
} else {
if (strpos($item['body'], "[/share]") !== false) {
$pos = strpos($item['body'], "[share");
$post = substr($item['body'], $pos);
} else {
$post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
if (!empty($item['title'])) {
$post .= '[h3]' . $item['title'] . "[/h3]\n";
}
$post .= $item['body'];
$post .= "[/share]";
}
$item = [
'uid' => $uid,
'body' => $post,
'app' => $request['source'] ?? '',
];
$owner = User::getOwnerDataById($uid);
$item['allow_cid'] = $owner['allow_cid'];
$item['allow_gid'] = $owner['allow_gid'];
$item['deny_cid'] = $owner['deny_cid'];
$item['deny_gid'] = $owner['deny_gid'];
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
$item['private'] = Item::PRIVATE;
} elseif (DI::pConfig()->get($uid, 'system', 'unlisted')) {
$item['private'] = Item::UNLISTED;
} else {
$item['private'] = Item::PUBLIC;
}
if (empty($item['app']) && !empty(self::getCurrentApplication()['name'])) {
$item['app'] = self::getCurrentApplication()['name'];
}
$item_id = Item::insert($item, true);
$item_id = Diaspora::performReshare($item['uri-id'], $uid);
}
} else {
throw new ForbiddenException();

View file

@ -22,15 +22,14 @@
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Diaspora;
/**
* Performs an activity (like, dislike, announce, attendyes, attendno, attendmaybe)
@ -52,9 +51,9 @@ class Activity extends BaseModule
$itemId = $this->parameters['id'];
if (in_array($verb, ['announce', 'unannounce'])) {
$item = Post::selectFirst(['network'], ['id' => $itemId]);
$item = Post::selectFirst(['network', 'uri-id', 'uid'], ['id' => $itemId]);
if ($item['network'] == Protocol::DIASPORA) {
self::performDiasporaReshare($itemId);
Diaspora::performReshare($item['uri-id'], $item['uid']);
}
}
@ -84,32 +83,4 @@ class Activity extends BaseModule
System::jsonExit($return);
}
private static function performDiasporaReshare(int $itemId)
{
$fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Post::selectFirst($fields, ['id' => $itemId, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (!DBA::isResult($item)) {
return;
}
if (strpos($item['body'], '[/share]') !== false) {
$pos = strpos($item['body'], '[share');
$post = substr($item['body'], $pos);
} else {
$post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
if (!empty($item['title'])) {
$post .= '[h3]' . $item['title'] . "[/h3]\n";
}
$post .= $item['body'];
$post .= '[/share]';
}
$_REQUEST['body'] = $post;
$_REQUEST['profile_uid'] = local_user();
require_once 'mod/item.php';
item_post(DI::app());
}
}

View file

@ -4053,4 +4053,53 @@ class Diaspora
return $message;
}
public static function performReshare(int $UriId, int $uid)
{
$fields = ['uri-id', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [Item::PUBLIC, Item::UNLISTED]]);
if (!DBA::isResult($item)) {
return 0;
}
if (strpos($item['body'], '[/share]') !== false) {
$pos = strpos($item['body'], '[share');
$post = substr($item['body'], $pos);
} else {
$post = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
if (!empty($item['title'])) {
$post .= '[h3]' . $item['title'] . "[/h3]\n";
}
$post .= $item['body'];
$post .= '[/share]';
}
$owner = User::getOwnerDataById($uid);
$author = Contact::getPublicIdByUserId($uid);
$item = [
'uid' => $uid,
'verb' => Activity::POST,
'contact-id' => $owner['id'],
'author-id' => $author,
'owner-id' => $author,
'body' => $post,
'allow_cid' => $owner['allow_cid'],
'allow_gid' => $owner['allow_gid'],
'deny_cid' => $owner['deny_cid'],
'deny_gid' => $owner['deny_gid'],
];
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
$item['private'] = Item::PRIVATE;
} elseif (DI::pConfig()->get($uid, 'system', 'unlisted')) {
$item['private'] = Item::UNLISTED;
} else {
$item['private'] = Item::PUBLIC;
}
return Item::insert($item, true);
}
}