We can now like and dislike
This commit is contained in:
parent
a56565fa99
commit
6df6d82427
4 changed files with 52 additions and 34 deletions
|
@ -52,7 +52,7 @@ function profile_init(App $a)
|
||||||
|
|
||||||
if (ActivityPub::isRequest()) {
|
if (ActivityPub::isRequest()) {
|
||||||
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]);
|
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $which]);
|
||||||
if (DBM::isResult($user)) {
|
if (DBA::isResult($user)) {
|
||||||
$data = ActivityPub::profile($user['uid']);
|
$data = ActivityPub::profile($user['uid']);
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
exit();
|
exit();
|
||||||
|
|
|
@ -1081,9 +1081,9 @@ class Item extends BaseObject
|
||||||
|
|
||||||
DBA::delete('item-delivery-data', ['iid' => $item['id']]);
|
DBA::delete('item-delivery-data', ['iid' => $item['id']]);
|
||||||
|
|
||||||
if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) {
|
//if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) {
|
||||||
DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]);
|
// DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]);
|
||||||
}
|
//}
|
||||||
if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
|
if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
|
||||||
DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
|
DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,7 +324,7 @@ class Post extends BaseObject
|
||||||
$owner_name_e = $this->getOwnerName();
|
$owner_name_e = $this->getOwnerName();
|
||||||
|
|
||||||
// Disable features that aren't available in several networks
|
// Disable features that aren't available in several networks
|
||||||
if (!in_array($item["network"], [Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) {
|
if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA]) && isset($buttons["dislike"])) {
|
||||||
unset($buttons["dislike"]);
|
unset($buttons["dislike"]);
|
||||||
$isevent = false;
|
$isevent = false;
|
||||||
$tagger = '';
|
$tagger = '';
|
||||||
|
|
|
@ -42,11 +42,11 @@ use Friendica\Util\LDSignature;
|
||||||
* To-do:
|
* To-do:
|
||||||
*
|
*
|
||||||
* Receiver:
|
* Receiver:
|
||||||
* - Activities: Update, Delete
|
* - Activities: Update, Delete (Activities/Notes)
|
||||||
* - Object Types: Person, Tombstome
|
* - Object Types: Person, Tombstome
|
||||||
*
|
*
|
||||||
* Transmitter:
|
* Transmitter:
|
||||||
* - Activities: Announce
|
* - Activities: Announce, Delete Notes
|
||||||
* - Object Tyoes: Person, Tombstone
|
* - Object Tyoes: Person, Tombstone
|
||||||
*
|
*
|
||||||
* General:
|
* General:
|
||||||
|
@ -139,7 +139,12 @@ class ActivityPub
|
||||||
$actor = JsonLD::fetchElement($activity, 'actor', 'id');
|
$actor = JsonLD::fetchElement($activity, 'actor', 'id');
|
||||||
$profile = ActivityPub::fetchprofile($actor);
|
$profile = ActivityPub::fetchprofile($actor);
|
||||||
|
|
||||||
$item_profile = ActivityPub::fetchprofile($item['owner-link']);
|
$item_profile = ActivityPub::fetchprofile($item['author-link']);
|
||||||
|
$exclude[] = $item['author-link'];
|
||||||
|
|
||||||
|
if ($item['gravity'] == GRAVITY_PARENT) {
|
||||||
|
$exclude[] = $item['owner-link'];
|
||||||
|
}
|
||||||
|
|
||||||
$permissions = [];
|
$permissions = [];
|
||||||
|
|
||||||
|
@ -155,7 +160,7 @@ class ActivityPub
|
||||||
if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
|
if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
|
||||||
$receiver = $item_profile['followers'];
|
$receiver = $item_profile['followers'];
|
||||||
}
|
}
|
||||||
if ($receiver != $item['owner-link']) {
|
if (!in_array($receiver, $exclude)) {
|
||||||
$permissions[$element][] = $receiver;
|
$permissions[$element][] = $receiver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +222,7 @@ class ActivityPub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]);
|
$parents = Item::select(['author-link', 'owner-link', 'gravity'], ['parent' => $item['parent']]);
|
||||||
while ($parent = Item::fetch($parents)) {
|
while ($parent = Item::fetch($parents)) {
|
||||||
$profile = self::fetchprofile($parent['author-link']);
|
$profile = self::fetchprofile($parent['author-link']);
|
||||||
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
||||||
|
@ -225,6 +230,10 @@ class ActivityPub
|
||||||
$contacts[$profile['url']] = $profile['url'];
|
$contacts[$profile['url']] = $profile['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($item['gravity'] != GRAVITY_PARENT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$profile = self::fetchprofile($parent['owner-link']);
|
$profile = self::fetchprofile($parent['owner-link']);
|
||||||
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
if (!empty($profile) && empty($contacts[$profile['url']])) {
|
||||||
$data['cc'][] = $profile['url'];
|
$data['cc'][] = $profile['url'];
|
||||||
|
@ -250,13 +259,18 @@ class ActivityPub
|
||||||
|
|
||||||
$inboxes = [];
|
$inboxes = [];
|
||||||
|
|
||||||
|
if ($item['gravity'] == GRAVITY_ACTIVITY) {
|
||||||
|
$item_profile = ActivityPub::fetchprofile($item['author-link']);
|
||||||
|
} else {
|
||||||
$item_profile = ActivityPub::fetchprofile($item['owner-link']);
|
$item_profile = ActivityPub::fetchprofile($item['owner-link']);
|
||||||
|
}
|
||||||
|
|
||||||
$elements = ['to', 'cc', 'bto', 'bcc'];
|
$elements = ['to', 'cc', 'bto', 'bcc'];
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
if (empty($permissions[$element])) {
|
if (empty($permissions[$element])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($permissions[$element] as $receiver) {
|
foreach ($permissions[$element] as $receiver) {
|
||||||
if ($receiver == $item_profile['followers']) {
|
if ($receiver == $item_profile['followers']) {
|
||||||
$contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid,
|
$contacts = DBA::select('contact', ['notify', 'batch'], ['uid' => $uid,
|
||||||
|
@ -276,14 +290,6 @@ class ActivityPub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($item_profile['sharedinbox'])) {
|
|
||||||
unset($inboxes[$item_profile['sharedinbox']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($item_profile['inbox'])) {
|
|
||||||
unset($inboxes[$item_profile['inbox']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $inboxes;
|
return $inboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,16 +311,14 @@ class ActivityPub
|
||||||
$type = 'Reject';
|
$type = 'Reject';
|
||||||
} elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
|
} elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
|
||||||
$type = 'TentativeAccept';
|
$type = 'TentativeAccept';
|
||||||
}
|
} else {
|
||||||
|
$type = '';
|
||||||
if ($item['deleted']) {
|
|
||||||
$type = 'Delete';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createActivityFromItem($item_id)
|
public static function createActivityFromItem($item_id, $object_mode = false)
|
||||||
{
|
{
|
||||||
$item = Item::selectFirst([], ['id' => $item_id]);
|
$item = Item::selectFirst([], ['id' => $item_id]);
|
||||||
|
|
||||||
|
@ -331,14 +335,24 @@ class ActivityPub
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$type = self::getTypeOfItem($item);
|
||||||
|
|
||||||
|
if (!$object_mode) {
|
||||||
$data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
|
$data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
|
||||||
['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier',
|
['ostatus' => 'http://ostatus.org#', 'uuid' => 'http://schema.org/identifier',
|
||||||
'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
|
'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
|
||||||
'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation',
|
'atomUri' => 'ostatus:atomUri', 'conversation' => 'ostatus:conversation',
|
||||||
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
|
||||||
|
|
||||||
$data['id'] = $item['uri'] . '#activity';
|
if ($item['deleted']) {
|
||||||
$data['type'] = self::getTypeOfItem($item);;
|
$type = 'Undo';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$data = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['id'] = $item['uri'] . '#' . $type;
|
||||||
|
$data['type'] = $type;
|
||||||
$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);
|
||||||
|
@ -347,20 +361,25 @@ class ActivityPub
|
||||||
$data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
|
$data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['context_id'] = $item['parent'];
|
|
||||||
$data['context'] = self::createConversationURLFromItem($item);
|
$data['context'] = self::createConversationURLFromItem($item);
|
||||||
|
|
||||||
$data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
|
$data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
|
||||||
|
|
||||||
if (in_array($data['type'], ['Create', 'Update', 'Announce'])) {
|
if (in_array($data['type'], ['Create', 'Update', 'Announce'])) {
|
||||||
$data['object'] = self::CreateNote($item);
|
$data['object'] = self::CreateNote($item);
|
||||||
|
} elseif ($data['type'] == 'Undo') {
|
||||||
|
$data['object'] = self::createActivityFromItem($item_id, true);
|
||||||
} else {
|
} else {
|
||||||
$data['object'] = $item['thr-parent'];
|
$data['object'] = $item['thr-parent'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($item['uid']);
|
$owner = User::getOwnerDataById($item['uid']);
|
||||||
|
|
||||||
|
if (!$object_mode) {
|
||||||
return LDSignature::sign($data, $owner);
|
return LDSignature::sign($data, $owner);
|
||||||
|
} else {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createObjectFromItemID($item_id)
|
public static function createObjectFromItemID($item_id)
|
||||||
|
@ -444,7 +463,6 @@ class ActivityPub
|
||||||
$data['attributedTo'] = $item['author-link'];
|
$data['attributedTo'] = $item['author-link'];
|
||||||
$data['actor'] = $item['author-link'];
|
$data['actor'] = $item['author-link'];
|
||||||
$data['sensitive'] = false; // - Query NSFW
|
$data['sensitive'] = false; // - Query NSFW
|
||||||
$data['context_id'] = $item['parent'];
|
|
||||||
$data['conversation'] = $data['context'] = self::createConversationURLFromItem($item);
|
$data['conversation'] = $data['context'] = self::createConversationURLFromItem($item);
|
||||||
|
|
||||||
if (!empty($item['title'])) {
|
if (!empty($item['title'])) {
|
||||||
|
|
Loading…
Reference in a new issue