We can now like and dislike
This commit is contained in:
parent
8d72c864b2
commit
ca574e1027
|
@ -42,12 +42,12 @@ use Friendica\Util\LDSignature;
|
||||||
* To-do:
|
* To-do:
|
||||||
*
|
*
|
||||||
* Receiver:
|
* Receiver:
|
||||||
* - Activities: Dislike, Update, Delete
|
* - Activities: Update, Delete
|
||||||
* - Object Types: Person, Tombstome
|
* - Object Types: Person, Tombstome
|
||||||
*
|
*
|
||||||
* Transmitter:
|
* Transmitter:
|
||||||
* - Activities: Like, Dislike, Update, Delete, Announce
|
* - Activities: Announce
|
||||||
* - Object Tyoes: Article, Person, Tombstone
|
* - Object Tyoes: Person, Tombstone
|
||||||
*
|
*
|
||||||
* General:
|
* General:
|
||||||
* - Endpoints: Outbox, Follower, Following
|
* - Endpoints: Outbox, Follower, Following
|
||||||
|
@ -287,6 +287,33 @@ class ActivityPub
|
||||||
return $inboxes;
|
return $inboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getTypeOfItem($item)
|
||||||
|
{
|
||||||
|
if ($item['verb'] == ACTIVITY_POST) {
|
||||||
|
if ($item['created'] == $item['edited']) {
|
||||||
|
$type = 'Create';
|
||||||
|
} else {
|
||||||
|
$type = 'Update';
|
||||||
|
}
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_LIKE) {
|
||||||
|
$type = 'Like';
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_DISLIKE) {
|
||||||
|
$type = 'Dislike';
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_ATTEND) {
|
||||||
|
$type = 'Accept';
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
|
||||||
|
$type = 'Reject';
|
||||||
|
} elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
|
||||||
|
$type = 'TentativeAccept';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($item['deleted']) {
|
||||||
|
$type = 'Delete';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
public static function createActivityFromItem($item_id)
|
public static function createActivityFromItem($item_id)
|
||||||
{
|
{
|
||||||
$item = Item::selectFirst([], ['id' => $item_id]);
|
$item = Item::selectFirst([], ['id' => $item_id]);
|
||||||
|
@ -311,7 +338,7 @@ class ActivityPub
|
||||||
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
||||||
|
|
||||||
$data['id'] = $item['uri'] . '#activity';
|
$data['id'] = $item['uri'] . '#activity';
|
||||||
$data['type'] = 'Create';
|
$data['type'] = self::getTypeOfItem($item);;
|
||||||
$data['actor'] = $item['author-link'];
|
$data['actor'] = $item['author-link'];
|
||||||
|
|
||||||
$data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
|
$data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
|
||||||
|
@ -325,7 +352,11 @@ class ActivityPub
|
||||||
|
|
||||||
$data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
|
$data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
|
||||||
|
|
||||||
$data['object'] = self::createObjectTypeFromItem($item);
|
if (in_array($data['type'], ['Create', 'Update', 'Announce'])) {
|
||||||
|
$data['object'] = self::CreateNote($item);
|
||||||
|
} else {
|
||||||
|
$data['object'] = $item['thr-parent'];
|
||||||
|
}
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($item['uid']);
|
$owner = User::getOwnerDataById($item['uid']);
|
||||||
|
|
||||||
|
@ -346,7 +377,7 @@ class ActivityPub
|
||||||
'conversation' => 'ostatus:conversation',
|
'conversation' => 'ostatus:conversation',
|
||||||
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
||||||
|
|
||||||
$data = array_merge($data, self::createObjectTypeFromItem($item));
|
$data = array_merge($data, self::CreateNote($item));
|
||||||
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -383,7 +414,7 @@ class ActivityPub
|
||||||
return $conversation_uri;
|
return $conversation_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function createObjectTypeFromItem($item)
|
private static function CreateNote($item)
|
||||||
{
|
{
|
||||||
if (!empty($item['title'])) {
|
if (!empty($item['title'])) {
|
||||||
$type = 'Article';
|
$type = 'Article';
|
||||||
|
@ -875,6 +906,7 @@ class ActivityPub
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Dislike':
|
case 'Dislike':
|
||||||
|
self::dislikeItem($object_data, $body);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Update':
|
case 'Update':
|
||||||
|
@ -1022,7 +1054,7 @@ class ActivityPub
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG);
|
logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG);
|
||||||
$data = self::createObjectTypeFromItem($item);
|
$data = self::CreateNote($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data['type'])) {
|
if (empty($data['type'])) {
|
||||||
|
@ -1239,6 +1271,17 @@ class ActivityPub
|
||||||
self::postItem($activity, $item, $body);
|
self::postItem($activity, $item, $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function dislikeItem($activity, $body)
|
||||||
|
{
|
||||||
|
$item = [];
|
||||||
|
$item['verb'] = ACTIVITY_DISLIKE;
|
||||||
|
$item['parent-uri'] = $activity['object'];
|
||||||
|
$item['gravity'] = GRAVITY_ACTIVITY;
|
||||||
|
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||||
|
|
||||||
|
self::postItem($activity, $item, $body);
|
||||||
|
}
|
||||||
|
|
||||||
private static function postItem($activity, $item, $body)
|
private static function postItem($activity, $item, $body)
|
||||||
{
|
{
|
||||||
/// @todo What to do with $activity['context']?
|
/// @todo What to do with $activity['context']?
|
||||||
|
|
Loading…
Reference in a new issue