return $redirect;
}
+ /**
+ * Remove a contact from all groups
+ *
+ * @param integer $contact_id
+ *
+ * @return boolean Success
+ */
public static function removeFromGroups($contact_id)
{
return DBA::delete('group_member', ['contact-id' => $contact_id]);
}
+
+ /**
+ * Is the contact a forum?
+ *
+ * @param integer $contactid ID of the contact
+ *
+ * @return boolean "true" if it is a forum
+ */
+ public static function isForum($contactid)
+ {
+ $fields = ['forum', 'prv'];
+ $condition = ['id' => $contactid];
+ $contact = DBA::selectFirst('contact', $fields, $condition);
+ if (!DBA::isResult($contact)) {
+ return false;
+ }
+
+ // Is it a forum?
+ return ($contact['forum'] || $contact['prv']);
+ }
}
return $ret;
}
+
+ /**
+ * Is the given item array a post that is sent as starting post to a forum?
+ *
+ * @param array $item
+ * @param array $owner
+ *
+ * @return boolean "true" when it is a forum post
+ */
+ public static function isForumPost(array $item, array $owner = [])
+ {
+ if (empty($owner)) {
+ $owner = User::getOwnerDataById($item['uid']);
+ if (empty($owner)) {
+ return false;
+ }
+ }
+
+ if (($item['author-id'] == $item['owner-id']) ||
+ ($owner['id'] == $item['contact-id']) ||
+ ($item['uri'] != $item['parent-uri']) ||
+ $item['origin']) {
+ return false;
+ }
+
+ return Contact::isForum($item['contact-id']);
+ }
}
/**
* Creates an array of permissions from an item thread
*
- * @param array $item
- * @param boolean $blindcopy
- * @param boolean $last_id
+ * @param array $item Item array
+ * @param boolean $blindcopy addressing via "bcc" or "cc"?
+ * @param integer $last_id Last item id for adding receivers
+ * @param boolean $forum_mode "true" means that we are sending content to a forum
*
* @return array with permission data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0)
+ private static function createPermissionBlockForItem($item, $blindcopy, $last_id = 0, $forum_mode = false)
{
if ($last_id == 0) {
$last_id = $item['id'];
}
} else {
// Public thread parent post always are directed to the followes
- if (!$item['private']) {
+ if (!$item['private'] && !$forum_mode) {
$data['cc'][] = $actor_profile['followers'];
}
}
/**
* Fetches an array of inboxes for the given item and user
*
- * @param array $item
- * @param integer $uid User ID
- * @param boolean $personal fetch personal inboxes
- * @param integer $last_id Last item id for adding receivers
- *
+ * @param array $item Item array
+ * @param integer $uid User ID
+ * @param boolean $personal fetch personal inboxes
+ * @param integer $last_id Last item id for adding receivers
+ * @param boolean $forum_mode "true" means that we are sending content to a forum
* @return array with inboxes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0)
+ public static function fetchTargetInboxes($item, $uid, $personal = false, $last_id = 0, $forum_mode = false)
{
- $permissions = self::createPermissionBlockForItem($item, true, $last_id);
+ $permissions = self::createPermissionBlockForItem($item, true, $last_id, $forum_mode);
if (empty($permissions)) {
return [];
}
return false;
}
- if ($item['wall']) {
+ if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
$owner = User::getOwnerDataById($item['uid']);
if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
$type = 'Announce';
$data['id'] = $item['uri'] . '#' . $type;
$data['type'] = $type;
- $data['actor'] = $item['owner-link'];
+
+ if (Item::isForumPost($item) && ($type != 'Announce')) {
+ $data['actor'] = $item['author-link'];
+ } else {
+ $data['actor'] = $item['owner-link'];
+ }
$data['published'] = DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM);
$parent = $items[0];
if (!self::isRemovalActivity($cmd, $owner, Protocol::ACTIVITYPUB)) {
- $delivery_queue_count += self::activityPubDelivery($cmd, $target_item, $parent, $a->queue['priority'], $a->queue['created']);
+ $delivery_queue_count += self::activityPubDelivery($cmd, $target_item, $parent, $a->queue['priority'], $a->queue['created'], $owner);
}
$fields = ['network', 'author-id', 'owner-id'];
}
// Special treatment for forum posts
- if (self::isForumPost($target_item, $owner)) {
+ if (Item::isForumPost($target_item, $owner)) {
$relay_to_owner = true;
$direct_forum_delivery = true;
}
// Avoid that comments in a forum thread are sent to OStatus
- if (self::isForumPost($parent, $owner)) {
+ if (Item::isForumPost($parent, $owner)) {
$direct_forum_delivery = true;
}
// Add the relay to the list, avoid duplicates.
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
- if (!$followup && !self::isForumPost($target_item, $owner)) {
+ if (!$followup && !Item::isForumPost($target_item, $owner)) {
$relay_list = Diaspora::relayList($target_id, $relay_list);
}
}
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function activityPubDelivery($cmd, array $target_item, array $parent, $priority, $created)
+ private static function activityPubDelivery($cmd, array $target_item, array $parent, $priority, $created, $owner)
{
$inboxes = [];
if ($target_item['origin']) {
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
Logger::log('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
+ } elseif (Item::isForumPost($target_item, $owner)) {
+ $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid, false, 0, true);
+ Logger::log('Forum item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG);
} elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG);
return 0;
return count($inboxes);
}
-
- private static function isForumPost(array $item, array $owner)
- {
- if (($item['author-id'] == $item['owner-id']) ||
- ($owner['id'] == $item['contact-id']) ||
- ($item['uri'] != $item['parent-uri'])) {
- return false;
- }
-
- return self::isForum($item['contact-id']);
- }
-
- private static function isForum($contactid)
- {
- $fields = ['forum', 'prv'];
- $condition = ['id' => $contactid];
- $contact = DBA::selectFirst('contact', $fields, $condition);
- if (!DBA::isResult($contact)) {
- // Should never happen
- return false;
- }
-
- // Is it a forum?
- return ($contact['forum'] || $contact['prv']);
- }
}