mirror of
https://github.com/friendica/friendica
synced 2025-04-25 22:30:10 +00:00
Private forums are now working via ActivityPub
This commit is contained in:
parent
cdee2b44db
commit
e394143148
13 changed files with 97 additions and 154 deletions
|
@ -100,7 +100,7 @@ class Item
|
|||
'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
|
||||
'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
|
||||
'signed_text', 'network', 'wall', 'contact-id', 'plink', 'origin',
|
||||
'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail',
|
||||
'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-summary', 'event-desc', 'event-location', 'event-type',
|
||||
|
@ -114,7 +114,7 @@ class Item
|
|||
'postopts', 'plink', 'resource-id', 'event-id', 'inform',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason',
|
||||
'private', 'pubmail', 'visible', 'starred',
|
||||
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
|
||||
'unseen', 'deleted', 'origin', 'mention', 'global', 'network',
|
||||
'title', 'content-warning', 'body', 'location', 'coord', 'app',
|
||||
'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
|
||||
|
@ -655,7 +655,7 @@ class Item
|
|||
$fields = ['uid', 'uri', 'parent-uri', 'id', 'deleted',
|
||||
'uri-id', 'parent-uri-id',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
'wall', 'private', 'forum_mode', 'origin', 'author-id'];
|
||||
'wall', 'private', 'origin', 'author-id'];
|
||||
$condition = ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']];
|
||||
$params = ['order' => ['id' => false]];
|
||||
$parent = Post::selectFirst($fields, $condition, $params);
|
||||
|
@ -881,10 +881,15 @@ class Item
|
|||
$item['parent-uri'] = $toplevel_parent['uri'];
|
||||
$item['parent-uri-id'] = $toplevel_parent['uri-id'];
|
||||
$item['deleted'] = $toplevel_parent['deleted'];
|
||||
$item['allow_cid'] = $toplevel_parent['allow_cid'];
|
||||
$item['allow_gid'] = $toplevel_parent['allow_gid'];
|
||||
$item['deny_cid'] = $toplevel_parent['deny_cid'];
|
||||
$item['deny_gid'] = $toplevel_parent['deny_gid'];
|
||||
|
||||
// Reshares have to keep their permissions to allow forums to work
|
||||
if (!$item['origin'] || ($item['verb'] != Activity::ANNOUNCE)) {
|
||||
$item['allow_cid'] = $toplevel_parent['allow_cid'];
|
||||
$item['allow_gid'] = $toplevel_parent['allow_gid'];
|
||||
$item['deny_cid'] = $toplevel_parent['deny_cid'];
|
||||
$item['deny_gid'] = $toplevel_parent['deny_gid'];
|
||||
}
|
||||
|
||||
$parent_origin = $toplevel_parent['origin'];
|
||||
|
||||
// Don't federate received participation messages
|
||||
|
@ -905,15 +910,6 @@ class Item
|
|||
$item['private'] = $toplevel_parent['private'];
|
||||
}
|
||||
|
||||
/*
|
||||
* Edge case. We host a public forum that was originally posted to privately.
|
||||
* The original author commented, but as this is a comment, the permissions
|
||||
* weren't fixed up so it will still show the comment as private unless we fix it here.
|
||||
*/
|
||||
if ((intval($toplevel_parent['forum_mode']) == 1) && ($toplevel_parent['private'] != self::PUBLIC)) {
|
||||
$item['private'] = self::PUBLIC;
|
||||
}
|
||||
|
||||
// If its a post that originated here then tag the thread as "mention"
|
||||
if ($item['origin'] && $item['uid']) {
|
||||
DBA::update('post-thread-user', ['mention' => true], ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
|
||||
|
@ -1451,7 +1447,6 @@ class Item
|
|||
unset($item['pinned']);
|
||||
unset($item['ignored']);
|
||||
unset($item['pubmail']);
|
||||
unset($item['forum_mode']);
|
||||
|
||||
unset($item['event-id']);
|
||||
unset($item['hidden']);
|
||||
|
@ -1928,41 +1923,18 @@ class Item
|
|||
|
||||
Logger::info('Community post will be distributed', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
|
||||
|
||||
self::performActivity($item['id'], 'announce', $uid);
|
||||
if ($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) {
|
||||
Group::getMembersForForum($owner['id']);
|
||||
|
||||
/**
|
||||
* All the following lines are only needed for private forums and compatibility to older systems without AP support.
|
||||
* A possible way would be that the followers list of a forum would always be readable by all followers.
|
||||
* So this would mean that the comment distribution could be done exactly for the intended audience.
|
||||
* Or possibly we could store the receivers that had been in the "announce" message above and use this.
|
||||
*/
|
||||
|
||||
// also reset all the privacy bits to the forum default permissions
|
||||
if ($owner['allow_cid'] || $owner['allow_gid'] || $owner['deny_cid'] || $owner['deny_gid']) {
|
||||
$private = self::PRIVATE;
|
||||
} elseif (DI::pConfig()->get($owner['uid'], 'system', 'unlisted')) {
|
||||
$private = self::UNLISTED;
|
||||
$allow_cid = '<' . $owner['id'] . '>';
|
||||
$allow_gid = '<' . Group::getIdForForum($owner['id']) . '>';
|
||||
$deny_cid = '';
|
||||
$deny_gid = '';
|
||||
self::performActivity($item['id'], 'announce', $uid, $allow_cid, $allow_gid, $deny_cid, $deny_gid);
|
||||
} else {
|
||||
$private = self::PUBLIC;
|
||||
self::performActivity($item['id'], 'announce', $uid);
|
||||
}
|
||||
|
||||
$permissionSet = DI::permissionSet()->selectOrCreate(
|
||||
DI::permissionSetFactory()->createFromString(
|
||||
$owner['uid'],
|
||||
$owner['allow_cid'],
|
||||
$owner['allow_gid'],
|
||||
$owner['deny_cid'],
|
||||
$owner['deny_gid']
|
||||
));
|
||||
|
||||
$forum_mode = ($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) ? 2 : 1;
|
||||
|
||||
$fields = ['wall' => true, 'origin' => true, 'forum_mode' => $forum_mode, 'contact-id' => $owner['id'],
|
||||
'owner-id' => Contact::getPublicIdByUserId($uid), 'private' => $private, 'psid' => $permissionSet->id];
|
||||
self::update($fields, ['id' => $item['id']]);
|
||||
|
||||
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']);
|
||||
|
||||
Logger::info('Community post had been distributed', ['uri' => $item['uri'], 'uid' => $uid, 'id' => $item_id, 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
|
||||
return false;
|
||||
}
|
||||
|
@ -2325,12 +2297,17 @@ class Item
|
|||
*
|
||||
* Toggle activities as like,dislike,attend of an item
|
||||
*
|
||||
* @param int $item_id
|
||||
* @param int $item_id
|
||||
* @param string $verb
|
||||
* Activity verb. One of
|
||||
* like, unlike, dislike, undislike, attendyes, unattendyes,
|
||||
* attendno, unattendno, attendmaybe, unattendmaybe,
|
||||
* announce, unannouce
|
||||
* @param int $uid
|
||||
* @param string $allow_cid
|
||||
* @param string $allow_gid
|
||||
* @param string $deny_cid
|
||||
* @param string $deny_gid
|
||||
* @return bool
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
|
@ -2338,7 +2315,7 @@ class Item
|
|||
* array $arr
|
||||
* 'post_id' => ID of posted item
|
||||
*/
|
||||
public static function performActivity(int $item_id, string $verb, int $uid)
|
||||
public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null)
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return false;
|
||||
|
@ -2479,6 +2456,11 @@ class Item
|
|||
return true;
|
||||
}
|
||||
|
||||
$allow_cid = $allow_cid ?? $item['allow_cid'];
|
||||
$allow_gid = $allow_gid ?? $item['allow_gid'];
|
||||
$deny_cid = $deny_cid ?? $item['deny_cid'];
|
||||
$deny_gid = $deny_gid ?? $item['deny_gid'];
|
||||
|
||||
$objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE;
|
||||
|
||||
$new_item = [
|
||||
|
@ -2499,10 +2481,10 @@ class Item
|
|||
'body' => $activity,
|
||||
'verb' => $activity,
|
||||
'object-type' => $objtype,
|
||||
'allow_cid' => $item['allow_cid'],
|
||||
'allow_gid' => $item['allow_gid'],
|
||||
'deny_cid' => $item['deny_cid'],
|
||||
'deny_gid' => $item['deny_gid'],
|
||||
'allow_cid' => $allow_cid,
|
||||
'allow_gid' => $allow_gid,
|
||||
'deny_cid' => $deny_cid,
|
||||
'deny_gid' => $deny_gid,
|
||||
'visible' => 1,
|
||||
'unseen' => 1,
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue