From bd2ee581d31f014c5e9a5055ebc1cd9958abb5d5 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Dec 2021 06:33:19 +0000 Subject: [PATCH 1/3] Diaspora reshares via API are fixed now --- include/api.php | 3 -- src/Module/Api/Twitter/Statuses/Retweet.php | 42 +---------------- src/Module/Item/Activity.php | 42 ++++------------- src/Protocol/Diaspora.php | 51 +++++++++++++++++++++ 4 files changed, 62 insertions(+), 76 deletions(-) diff --git a/include/api.php b/include/api.php index f3b268ffc4..9b9850f6fa 100644 --- a/include/api.php +++ b/include/api.php @@ -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 = []; /** diff --git a/src/Module/Api/Twitter/Statuses/Retweet.php b/src/Module/Api/Twitter/Statuses/Retweet.php index ef9a1412a1..15fc26925f 100644 --- a/src/Module/Api/Twitter/Statuses/Retweet.php +++ b/src/Module/Api/Twitter/Statuses/Retweet.php @@ -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(); diff --git a/src/Module/Item/Activity.php b/src/Module/Item/Activity.php index f82d1b4305..e731b05b80 100644 --- a/src/Module/Item/Activity.php +++ b/src/Module/Item/Activity.php @@ -22,15 +22,15 @@ namespace Friendica\Module\Item; use Friendica\BaseModule; -use Friendica\Content\Text\BBCode; +use Friendica\Core\Logger; 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) @@ -50,13 +50,17 @@ class Activity extends BaseModule $verb = $this->parameters['verb']; $itemId = $this->parameters['id']; - +Logger::info('Blubb-1', ['id' => $itemId, 'verb' => $verb]); if (in_array($verb, ['announce', 'unannounce'])) { - $item = Post::selectFirst(['network'], ['id' => $itemId]); + $item = Post::selectFirst(['network', 'uri-id', 'uid'], ['id' => $itemId]); + Logger::info('Blubb-2', ['id' => $itemId, 'item' => $item]); if ($item['network'] == Protocol::DIASPORA) { - self::performDiasporaReshare($itemId); + Logger::info('Blubb-3', ['id' => $itemId]); + $id = Diaspora::performReshare($item['uri-id'], $item['uid']); + Logger::info('Blubb-ende', ['id' => $id]); } } + Logger::info('Blubb-activity', ['id' => $itemId]); if (!Item::performActivity($itemId, $verb, local_user())) { throw new HTTPException\BadRequestException(); @@ -84,32 +88,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()); - } } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 02d6d270a6..5fe4149c02 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4053,4 +4053,55 @@ 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)) { + Logger::info('Blubb-4', ['uri-id' => $UriId, 'uid' => $uid]); + 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; + } + Logger::info('Blubb-5', ['uri-id' => $UriId, 'uid' => $uid, 'item' => $item]); + + return Item::insert($item, true); + } } From 4a90e6b1f04b3cc9d20a096b268db6e67c6f1e52 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Dec 2021 06:36:09 +0000 Subject: [PATCH 2/3] Test code removed --- src/Module/Item/Activity.php | 8 ++------ src/Protocol/Diaspora.php | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Module/Item/Activity.php b/src/Module/Item/Activity.php index e731b05b80..33ea0558e5 100644 --- a/src/Module/Item/Activity.php +++ b/src/Module/Item/Activity.php @@ -50,17 +50,13 @@ class Activity extends BaseModule $verb = $this->parameters['verb']; $itemId = $this->parameters['id']; -Logger::info('Blubb-1', ['id' => $itemId, 'verb' => $verb]); + if (in_array($verb, ['announce', 'unannounce'])) { $item = Post::selectFirst(['network', 'uri-id', 'uid'], ['id' => $itemId]); - Logger::info('Blubb-2', ['id' => $itemId, 'item' => $item]); if ($item['network'] == Protocol::DIASPORA) { - Logger::info('Blubb-3', ['id' => $itemId]); - $id = Diaspora::performReshare($item['uri-id'], $item['uid']); - Logger::info('Blubb-ende', ['id' => $id]); + Diaspora::performReshare($item['uri-id'], $item['uid']); } } - Logger::info('Blubb-activity', ['id' => $itemId]); if (!Item::performActivity($itemId, $verb, local_user())) { throw new HTTPException\BadRequestException(); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 5fe4149c02..57f3502cc9 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4059,7 +4059,6 @@ class Diaspora $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)) { - Logger::info('Blubb-4', ['uri-id' => $UriId, 'uid' => $uid]); return 0; } @@ -4100,7 +4099,6 @@ class Diaspora } else { $item['private'] = Item::PUBLIC; } - Logger::info('Blubb-5', ['uri-id' => $UriId, 'uid' => $uid, 'item' => $item]); return Item::insert($item, true); } From 5e912c2965b6d93a7a16f44aa67c0ec7835f200e Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Dec 2021 06:37:06 +0000 Subject: [PATCH 3/3] Unused use removed --- src/Module/Item/Activity.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Module/Item/Activity.php b/src/Module/Item/Activity.php index 33ea0558e5..b788167662 100644 --- a/src/Module/Item/Activity.php +++ b/src/Module/Item/Activity.php @@ -22,7 +22,6 @@ namespace Friendica\Module\Item; use Friendica\BaseModule; -use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\DI;