// We can always comment on posts from these networks
if (array_key_exists('writable', $row) &&
- in_array($row['internal-network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+ in_array($row['internal-network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
$row['writable'] = true;
}
} else {
$master_table = "`item`";
}
- return "$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
+ return sprintf("$master_table.`visible` AND NOT $master_table.`deleted` AND NOT $master_table.`moderated`
+ AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
+ AND (`user-author`.`blocked` IS NULL OR NOT `user-author`.`blocked`)
+ AND (`user-author`.`ignored` IS NULL OR NOT `user-author`.`ignored` OR `item`.`gravity` != %d)
+ AND (`user-owner`.`blocked` IS NULL OR NOT `user-owner`.`blocked`)
+ AND (`user-owner`.`ignored` IS NULL OR NOT `user-owner`.`ignored` OR `item`.`gravity` != %d) ",
+ GRAVITY_PARENT, GRAVITY_PARENT);
}
/**
OR `contact`.`self` OR `item`.`gravity` != %d OR `contact`.`uid` = 0)
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked`
- LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d",
- Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid));
+ LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d
+ LEFT JOIN `user-contact` AS `user-author` ON `user-author`.`cid` = $master_table.`author-id` AND `user-author`.`uid` = %d
+ LEFT JOIN `user-contact` AS `user-owner` ON `user-owner`.`cid` = $master_table.`owner-id` AND `user-owner`.`uid` = %d",
+ Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid), intval($uid), intval($uid));
} else {
if (strpos($sql_commands, "`contact`.") !== false) {
$joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`";
DBA::delete('item-delivery-data', ['iid' => $item['id']]);
- if (!empty($item['iaid']) && !self::exists(['iaid' => $item['iaid'], 'deleted' => false])) {
- DBA::delete('item-activity', ['id' => $item['iaid']], ['cascade' => false]);
- }
+ // We don't delete the item-activity here, since we need some of the data for ActivityPub
+
if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
}
if ($notify) {
// We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
// We add the hash of our own host because our host is the original creator of the post.
- $prefix_host = get_app()->get_hostname();
+ $prefix_host = get_app()->getHostName();
} else {
$prefix_host = '';
} elseif (!empty($item['uri'])) {
$guid = self::guidFromUri($item['uri'], $prefix_host);
} else {
- $guid = System::createGUID(32, hash('crc32', $prefix_host));
+ $guid = System::createUUID(hash('crc32', $prefix_host));
}
return $guid;
* We have to check several networks since Friendica posts could be repeated
* via OStatus (maybe Diasporsa as well)
*/
- if (in_array($item['network'], [Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) {
+ if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS, ""])) {
$condition = ["`uri` = ? AND `uid` = ? AND `network` IN (?, ?, ?)",
trim($item['uri']), $item['uid'],
Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS];
return 0;
}
- // These fields aren't stored anymore in the item table, they are fetched upon request
- unset($item['author-link']);
- unset($item['author-name']);
- unset($item['author-avatar']);
-
- unset($item['owner-link']);
- unset($item['owner-name']);
- unset($item['owner-avatar']);
-
if ($item['network'] == Protocol::PHANTOM) {
logger('Missing network. Called by: '.System::callstack(), LOGGER_DEBUG);
unset($item['postopts']);
unset($item['inform']);
+ // These fields aren't stored anymore in the item table, they are fetched upon request
+ unset($item['author-link']);
+ unset($item['author-name']);
+ unset($item['author-avatar']);
+
+ unset($item['owner-link']);
+ unset($item['owner-name']);
+ unset($item['owner-avatar']);
+
DBA::transaction();
$ret = DBA::insert('item', $item);
} else {
// This shouldn't happen.
logger('Could not insert activity for URI ' . $item['uri'] . ' - should not happen');
+ Lock::release('item_insert_activity');
return false;
}
if ($locked) {
// Only distribute public items from native networks
$condition = ['id' => $itemid, 'uid' => 0,
- 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""],
+ 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""],
'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false];
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]);
if (!DBA::isResult($item)) {
$users = [];
- $condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)",
- $parent['owner-id'], Contact::SHARING, Contact::FRIEND];
+ /// @todo add a field "pcid" in the contact table that referrs to the public contact id.
+ $owner = DBA::selectFirst('contact', ['url', 'nurl', 'alias'], ['id' => $parent['owner-id']]);
+ if (!DBA::isResult($owner)) {
+ return;
+ }
+ $condition = ['nurl' => $owner['nurl'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
$contacts = DBA::select('contact', ['uid'], $condition);
+ while ($contact = DBA::fetch($contacts)) {
+ if ($contact['uid'] == 0) {
+ continue;
+ }
+ $users[$contact['uid']] = $contact['uid'];
+ }
+ DBA::close($contacts);
+
+ $condition = ['alias' => $owner['url'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
+ $contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) {
+ if ($contact['uid'] == 0) {
+ continue;
+ }
+
$users[$contact['uid']] = $contact['uid'];
}
+ DBA::close($contacts);
+
+ if (!empty($owner['alias'])) {
+ $condition = ['url' => $owner['alias'], 'rel' => [Contact::SHARING, Contact::FRIEND]];
+ $contacts = DBA::select('contact', ['uid'], $condition);
+ while ($contact = DBA::fetch($contacts)) {
+ if ($contact['uid'] == 0) {
+ continue;
+ }
+
+ $users[$contact['uid']] = $contact['uid'];
+ }
+ DBA::close($contacts);
+ }
$origin_uid = 0;
}
// is it an entry from a connector? Only add an entry for natively connected networks
- if (!in_array($item["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
+ if (!in_array($item["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
return;
}
public static function newURI($uid, $guid = "")
{
if ($guid == "") {
- $guid = System::createGUID(32);
+ $guid = System::createUUID();
}
- $hostname = self::getApp()->get_hostname();
-
- $user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]);
-
- $uri = "urn:X-dfrn:" . $hostname . ':' . $user['nickname'] . ':' . $guid;
-
- return $uri;
+ return self::getApp()->getBaseURL() . '/objects/' . $guid;
}
/**
}
// Prevent to forward already forwarded posts
- if ($datarray["app"] == $a->get_hostname()) {
+ if ($datarray["app"] == $a->getHostName()) {
logger('Already forwarded (second test)', LOGGER_DEBUG);
return false;
}
}
if ($contact['network'] != Protocol::FEED) {
- $datarray["guid"] = System::createGUID(32);
+ $datarray["guid"] = System::createUUID();
unset($datarray["plink"]);
$datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
$datarray["parent-uri"] = $datarray["uri"];
}
// returns an array of contact-ids that are allowed to see this object
- private static function enumeratePermissions($obj)
+ public static function enumeratePermissions($obj)
{
$allow_people = expand_acl($obj['allow_cid']);
$allow_groups = Group::expand(expand_acl($obj['allow_gid']));
return true;
}
- $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
+ $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE;
$new_item = [
- 'guid' => System::createGUID(32),
+ 'guid' => System::createUUID(),
'uri' => self::newURI($item['uid']),
'uid' => $item['uid'],
'contact-id' => $item_contact_id,
'parent' => $item['id'],
'parent-uri' => $item['uri'],
'thr-parent' => $item['uri'],
- 'owner-id' => $item['owner-id'],
+ 'owner-id' => $author_id,
'author-id' => $author_id,
'body' => $activity,
'verb' => $activity,