API: Support for the "direct" visibility
This commit is contained in:
parent
aa28761d38
commit
5539e42743
|
@ -494,7 +494,7 @@ class Item
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function expandTags(array $item)
|
public function expandTags(array $item, bool $setPermissions = false)
|
||||||
{
|
{
|
||||||
// Look for any tags and linkify them
|
// Look for any tags and linkify them
|
||||||
$item['inform'] = '';
|
$item['inform'] = '';
|
||||||
|
@ -502,6 +502,7 @@ class Item
|
||||||
$private_id = null;
|
$private_id = null;
|
||||||
$only_to_forum = false;
|
$only_to_forum = false;
|
||||||
$forum_contact = [];
|
$forum_contact = [];
|
||||||
|
$receivers = [];
|
||||||
|
|
||||||
// Convert mentions in the body to a unified format
|
// Convert mentions in the body to a unified format
|
||||||
$item['body'] = BBCode::setMentions($item['body'], $item['uid'], $item['network']);
|
$item['body'] = BBCode::setMentions($item['body'], $item['uid'], $item['network']);
|
||||||
|
@ -509,6 +510,9 @@ class Item
|
||||||
// Search for forum mentions
|
// Search for forum mentions
|
||||||
foreach (Tag::getFromBody($item['body'], Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
|
foreach (Tag::getFromBody($item['body'], Tag::TAG_CHARACTER[Tag::MENTION] . Tag::TAG_CHARACTER[Tag::EXCLUSIVE_MENTION]) as $tag) {
|
||||||
$contact = Contact::getByURLForUser($tag[2], $item['uid']);
|
$contact = Contact::getByURLForUser($tag[2], $item['uid']);
|
||||||
|
|
||||||
|
$receivers[] = $contact['id'];
|
||||||
|
|
||||||
if (!empty($item['inform'])) {
|
if (!empty($item['inform'])) {
|
||||||
$item['inform'] .= ',';
|
$item['inform'] .= ',';
|
||||||
}
|
}
|
||||||
|
@ -554,6 +558,22 @@ class Item
|
||||||
$item['allow_cid'] = '';
|
$item['allow_cid'] = '';
|
||||||
$item['allow_gid'] = '';
|
$item['allow_gid'] = '';
|
||||||
}
|
}
|
||||||
|
} elseif ($setPermissions && ($item['gravity'] == GRAVITY_PARENT)) {
|
||||||
|
if (empty($receivers)) {
|
||||||
|
// For security reasons direct posts without any receiver will be posts to yourself
|
||||||
|
$self = Contact::selectFirst(['id'], ['uid' => $item['uid'], 'self' => true]);
|
||||||
|
$receivers[] = $self['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$item['private'] = ModelItem::PRIVATE;
|
||||||
|
$item['allow_cid'] = '';
|
||||||
|
$item['allow_gid'] = '';
|
||||||
|
$item['deny_cid'] = '';
|
||||||
|
$item['deny_gid'] = '';
|
||||||
|
|
||||||
|
foreach ($receivers as $receiver) {
|
||||||
|
$item['allow_cid'] .= '<' . $receiver . '>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,8 +110,7 @@ class Statuses extends BaseApi
|
||||||
$item['private'] = Item::PRIVATE;
|
$item['private'] = Item::PRIVATE;
|
||||||
break;
|
break;
|
||||||
case 'direct':
|
case 'direct':
|
||||||
// Direct messages are currently unsupported
|
// The permissions are assigned in "expandTags"
|
||||||
DI::mstdnError()->InternalError('Direct messages are currently unsupported');
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (is_numeric($request['visibility']) && Group::exists($request['visibility'], $uid)) {
|
if (is_numeric($request['visibility']) && Group::exists($request['visibility'], $uid)) {
|
||||||
|
@ -152,7 +151,7 @@ class Statuses extends BaseApi
|
||||||
$item['object-type'] = Activity\ObjectType::NOTE;
|
$item['object-type'] = Activity\ObjectType::NOTE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = DI::contentItem()->expandTags($item);
|
$item = DI::contentItem()->expandTags($item, $request['visibility'] == 'direct');
|
||||||
|
|
||||||
if (!empty($request['media_ids'])) {
|
if (!empty($request['media_ids'])) {
|
||||||
$item['object-type'] = Activity\ObjectType::IMAGE;
|
$item['object-type'] = Activity\ObjectType::IMAGE;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user