Moved acitivites
This commit is contained in:
parent
a3aab4a75a
commit
57cf384fae
|
@ -49,7 +49,6 @@ use Friendica\Network\HTTPException\NotFoundException;
|
|||
use Friendica\Network\HTTPException\TooManyRequestsException;
|
||||
use Friendica\Network\HTTPException\UnauthorizedException;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Security\BasicAuth;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Images;
|
||||
|
@ -245,83 +244,6 @@ function api_format_messages($item, $recipient, $sender)
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* return likes, dislikes and attend status for item
|
||||
*
|
||||
* @param array $item array
|
||||
* @param string $type Return type (atom, rss, xml, json)
|
||||
*
|
||||
* @return array
|
||||
* likes => int count,
|
||||
* dislikes => int count
|
||||
* @throws BadRequestException
|
||||
* @throws ImagickException
|
||||
* @throws InternalServerErrorException
|
||||
* @throws UnauthorizedException
|
||||
*/
|
||||
function api_format_items_activities($item, $type = "json")
|
||||
{
|
||||
$activities = [
|
||||
'like' => [],
|
||||
'dislike' => [],
|
||||
'attendyes' => [],
|
||||
'attendno' => [],
|
||||
'attendmaybe' => [],
|
||||
'announce' => [],
|
||||
];
|
||||
|
||||
$condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY];
|
||||
$ret = Post::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
|
||||
|
||||
while ($parent_item = Post::fetch($ret)) {
|
||||
// not used as result should be structured like other user data
|
||||
//builtin_activity_puller($i, $activities);
|
||||
|
||||
// get user data and add it to the array of the activity
|
||||
$user = DI::twitterUser()->createFromContactId($parent_item['author-id'], $item['uid'])->toArray();
|
||||
switch ($parent_item['verb']) {
|
||||
case Activity::LIKE:
|
||||
$activities['like'][] = $user;
|
||||
break;
|
||||
case Activity::DISLIKE:
|
||||
$activities['dislike'][] = $user;
|
||||
break;
|
||||
case Activity::ATTEND:
|
||||
$activities['attendyes'][] = $user;
|
||||
break;
|
||||
case Activity::ATTENDNO:
|
||||
$activities['attendno'][] = $user;
|
||||
break;
|
||||
case Activity::ATTENDMAYBE:
|
||||
$activities['attendmaybe'][] = $user;
|
||||
break;
|
||||
case Activity::ANNOUNCE:
|
||||
$activities['announce'][] = $user;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DBA::close($ret);
|
||||
|
||||
if ($type == "xml") {
|
||||
$xml_activities = [];
|
||||
foreach ($activities as $k => $v) {
|
||||
// change xml element from "like" to "friendica:like"
|
||||
$xml_activities["friendica:".$k] = $v;
|
||||
// add user data into xml output
|
||||
$k_user = 0;
|
||||
foreach ($v as $user) {
|
||||
$xml_activities["friendica:".$k][$k_user++.":user"] = $user;
|
||||
}
|
||||
}
|
||||
$activities = $xml_activities;
|
||||
}
|
||||
|
||||
return $activities;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $acl_string
|
||||
|
@ -643,7 +565,7 @@ function prepare_photo_data($type, $scale, $photo_id, $uid)
|
|||
throw new NotFoundException('Photo-related item not found.');
|
||||
}
|
||||
|
||||
$data['photo']['friendica_activities'] = api_format_items_activities($item, $type);
|
||||
$data['photo']['friendica_activities'] = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], $type);
|
||||
|
||||
// retrieve comments on photo
|
||||
$condition = ["`parent` = ? AND `uid` = ? AND `gravity` IN (?, ?)",
|
||||
|
|
|
@ -270,6 +270,14 @@ abstract class DI
|
|||
// "Factory" namespace instances
|
||||
//
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Friendica\Activities
|
||||
*/
|
||||
public static function friendicaActivities()
|
||||
{
|
||||
return self::$dice->create(Factory\Api\Friendica\Activities::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory\Api\Mastodon\Account
|
||||
*/
|
||||
|
|
|
@ -50,7 +50,7 @@ class Activities extends BaseFactory
|
|||
* @return Array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function createFromUriId(int $uriId, int $uid): array
|
||||
public function createFromUriId(int $uriId, int $uid, $type = 'json'): array
|
||||
{
|
||||
$activities = [
|
||||
'like' => [],
|
||||
|
@ -94,6 +94,20 @@ class Activities extends BaseFactory
|
|||
|
||||
DBA::close($ret);
|
||||
|
||||
if ($type == 'xml') {
|
||||
$xml_activities = [];
|
||||
foreach ($activities as $k => $v) {
|
||||
// change xml element from "like" to "friendica:like"
|
||||
$xml_activities["friendica:".$k] = $v;
|
||||
// add user data into xml output
|
||||
$k_user = 0;
|
||||
foreach ($v as $user) {
|
||||
$xml_activities['friendica:' . $k][$k_user++ . ':user'] = $user;
|
||||
}
|
||||
}
|
||||
$activities = $xml_activities;
|
||||
}
|
||||
|
||||
return $activities;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2162,8 +2162,8 @@ class ApiTest extends FixtureTest
|
|||
*/
|
||||
public function testApiFormatItemsActivities()
|
||||
{
|
||||
$item = ['uid' => 0, 'uri' => ''];
|
||||
$result = api_format_items_activities($item);
|
||||
$item = ['uid' => 0, 'uri-id' => 1];
|
||||
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid']);
|
||||
self::assertArrayHasKey('like', $result);
|
||||
self::assertArrayHasKey('dislike', $result);
|
||||
self::assertArrayHasKey('attendyes', $result);
|
||||
|
@ -2178,8 +2178,8 @@ class ApiTest extends FixtureTest
|
|||
*/
|
||||
public function testApiFormatItemsActivitiesWithXml()
|
||||
{
|
||||
$item = ['uid' => 0, 'uri' => ''];
|
||||
$result = api_format_items_activities($item, 'xml');
|
||||
$item = ['uid' => 0, 'uri-id' => 1];
|
||||
$result = DI::friendicaActivities()->createFromUriId($item['uri-id'], $item['uid'], 'xml');
|
||||
self::assertArrayHasKey('friendica:like', $result);
|
||||
self::assertArrayHasKey('friendica:dislike', $result);
|
||||
self::assertArrayHasKey('friendica:attendyes', $result);
|
||||
|
|
Loading…
Reference in a new issue