more emojireaction work and a config setting to allow messages where you are mentioned, over-riding normal permissions.

This commit is contained in:
zotlabs 2020-02-04 15:44:26 -08:00
parent 35a378c1d4
commit f7efbfc7c2
8 changed files with 49 additions and 10 deletions

View file

@ -1869,7 +1869,7 @@ class Activity {
}
if (in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject',
'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction' ])) {
'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction', 'EmojiReact' ])) {
$response_activity = true;
@ -1939,7 +1939,7 @@ class Activity {
// Hubzilla reactions
$content['content'] = (($act->tgt && $act->tgt['type'] === 'Image') ? '[img=32x32]' . $act->tgt['url'] . '[/img]' : '&#x' . $act->tgt['name'] . ';');
}
if ($act->type === 'EmojiReaction') {
if (in_array($act->type,[ 'EmojiReaction', 'EmojiReact' ])) {
// Pleroma reactions
$t = trim(self::get_textfield($act,'content'));
$e = Emoji\is_single_emoji($t);

View file

@ -21,7 +21,7 @@ class Apschema extends \Zotlabs\Web\Controller {
'copiedTo' => 'as:copiedTo',
'alsoKnownAs' => 'as:alsoKnownAs',
'inheritPrivacy' => 'as:inheritPrivacy',
'EmojiReaction' => 'as:EmojiReaction',
'EmojiReact' => 'as:EmojiReact',
'commentPolicy' => 'zot:commentPolicy',
'topicalCollection' => 'zot:topicalCollection',
'eventRepeat' => 'zot:eventRepeat',

View file

@ -248,6 +248,7 @@ class Inbox extends Controller {
case 'View':
case 'emojiReaction':
case 'EmojiReaction':
case 'EmojiReact':
// These require a resolvable object structure
if (is_array($AS->obj)) {
$item = Activity::decode_note($AS);

View file

@ -490,7 +490,7 @@ class Item extends Controller {
if (mb_strlen($_REQUEST['body']) < 10) {
$t = Emoji\is_single_emoji(trim($_REQUEST['body']));
if ($t) {
$obj_type = 'EmojiReaction';
$obj_type = 'EmojiReact';
}
}

View file

@ -169,7 +169,8 @@ class Channel {
$cal_first_day = (((x($_POST,'first_day')) && intval($_POST['first_day']) >= 0 && intval($_POST['first_day']) < 7) ? intval($_POST['first_day']) : 0);
$mailhost = ((array_key_exists('mailhost',$_POST)) ? notags(trim($_POST['mailhost'])) : '');
$profile_assign = ((x($_POST,'profile_assign')) ? notags(trim($_POST['profile_assign'])) : '');
$permit_all_mentions = (($_POST['permit_all_mentions'] == 1) ? 1: 0);
// allow a permission change to over-ride the autoperms setting from the form
if(! isset($autoperms)) {
@ -279,6 +280,7 @@ class Channel {
set_pconfig(local_channel(),'system','hyperdrive',$hyperdrive);
set_pconfig(local_channel(),'system','activitypub',$activitypub);
set_pconfig(local_channel(),'system','autoperms',$autoperms);
set_pconfig(local_channel(),'system','permit_all_mentions',$permit_all_mentions);
$r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d",
dbesc($username),
@ -613,6 +615,7 @@ class Channel {
'$apconfig' => $apconfig,
'$apheader' => $apheader,
'$apdoc' => $apdoc,
'$close' => t('Close'),
'$h_not' => t('Notifications'),
'$activity_options' => t('By default post a status message when:'),
'$post_newfriend' => array('post_newfriend', t('accepting a friend request'), $post_newfriend, '', $yes_no),
@ -651,7 +654,7 @@ class Channel {
'$vnotify16' => ((is_site_admin()) ? array('vnotify16', t('Reported content'), ($vnotify & VNOTIFY_REPORTS), VNOTIFY_REPORTS, '', $yes_no) : [] ),
'$mailhost' => [ 'mailhost', t('Email notification hub (hostname)'), get_pconfig(local_channel(),'system','email_notify_host',App::get_hostname()), sprintf( t('If your channel is mirrored to multiple locations, set this to your preferred location. This will prevent duplicate email notifications. Example: %s'),App::get_hostname()) ],
'$always_show_in_notices' => array('always_show_in_notices', t('Show new wall posts, private messages and connections under Notices'), $always_show_in_notices, 1, '', $yes_no),
'$permit_all_mentions' => [ 'permit_all_mentions', t('Accept messages from strangers which mention me'), get_pconfig(local_channel(),'system','permit_all_mentions'), t('This setting supercedes normal permissions'), $yes_no ],
'$evdays' => array('evdays', t('Notify me of events this many days in advance'), $evdays, t('Must be greater than 0')),
'$basic_addon' => $plugin['basic'],
'$sec_addon' => $plugin['security'],

View file

@ -2657,7 +2657,6 @@ function tag_deliver($uid, $item_id) {
'verb' => ACTIVITY_TAG,
'otype' => 'item'
));
}
}
if ($is_collection && $pterms) {
@ -2775,9 +2774,45 @@ function tgroup_check($uid, $item) {
return true;
}
// return true if we are mentioned and we permit delivery of mentions from strangers
if (PConfig::Get($uid, 'system','permit_all_mentions') && i_am_mentioned($u,$item)) {
return true;
}
return false;
}
function i_am_mentioned($channel,$item) {
$link = $channel['xchan_url'];
$body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']);
$tagged = false;
$matches = [];
$terms = get_terms_oftype($item['term'],TERM_MENTION);
if ($terms) {
foreach ($terms as $term) {
if ($link === $term['url']) {
$pattern = '/[\!@]\!?\[[uz]rl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/[uz]rl\]/';
if (preg_match($pattern,$body,$matches)) {
$tagged = true;
}
$pattern = '/\[[uz]rl\=' . preg_quote($term['url'],'/') . '\][\!@](.*?)\[\/[uz]rl\]/';
if (preg_match($pattern,$body,$matches)) {
$tagged = true;
}
}
}
}
return $tagged;
}
/**
* Sourced and tag-delivered posts are re-targetted for delivery to the connections of the channel
* receiving the post. This starts the second delivery chain, by resetting permissions and ensuring

View file

@ -11,7 +11,6 @@ use Zotlabs\Lib\SvgSanitizer;
use Michelf\MarkdownExtra;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use Emoji;
require_once("include/bbcode.php");

View file

@ -51,6 +51,7 @@
{{$autoperms}}
{{$anymention}}
{{include file="field_select.tpl" field=$comment_perms}}
{{include file="field_checkbox.tpl" field=$permit_all_mentions}}
<div id="advanced-perm" style="display:{{if $permissions_set}}none{{else}}block{{/if}};">
<div class="form-group">
@ -61,7 +62,7 @@
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{$lbl_p2macro}}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<button type="button" class="close" data-dismiss="modal" aria-label="{{$close}}"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
{{foreach $permiss_arr as $permit}}
@ -69,7 +70,7 @@
{{/foreach}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">{{$close}}</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->