aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZot <mike@macgirvin.com>2020-06-17 09:12:15 +0200
committerMario <mario@mariovavti.com>2020-06-17 09:12:15 +0200
commit36e969fd79a252e9aef7a87b8fa2d5f7c75ecd6d (patch)
tree143eabe58d54983cda8061c3e9a97bc7141d3812
parenta88233a045679f3d7ea4c14eb68e62816fb10ba7 (diff)
downloadvolse-hubzilla-36e969fd79a252e9aef7a87b8fa2d5f7c75ecd6d.tar.gz
volse-hubzilla-36e969fd79a252e9aef7a87b8fa2d5f7c75ecd6d.tar.bz2
volse-hubzilla-36e969fd79a252e9aef7a87b8fa2d5f7c75ecd6d.zip
zap group compatibility - rewrites DMs and wall-to-wall posts to group pages as new posts authored by the group with an embedded reshare. This currently has known delivery issues due to zot/zot6 xchan confusion which are already slated for resolution in hz5. Specifically "sender is not owner/author" and missing abconfig permissions on the zot6 identity for a channel we're connected with over traditional zot.
-rw-r--r--Zotlabs/Access/PermissionRoles.php4
-rw-r--r--Zotlabs/Module/Item.php26
-rwxr-xr-xinclude/items.php120
3 files changed, 147 insertions, 3 deletions
diff --git a/Zotlabs/Access/PermissionRoles.php b/Zotlabs/Access/PermissionRoles.php
index c8b4953a5..82df0c34b 100644
--- a/Zotlabs/Access/PermissionRoles.php
+++ b/Zotlabs/Access/PermissionRoles.php
@@ -100,6 +100,7 @@ class PermissionRoles {
'post_mail', 'post_like' , 'republish', 'chat'
];
$ret['limits'] = PermissionLimits::Std_Limits();
+ $ret['channel_type'] = 'group';
break;
@@ -113,6 +114,7 @@ class PermissionRoles {
'view_pages', 'view_wiki', 'post_wall', 'post_comments', 'tag_deliver',
'post_mail', 'post_like' , 'chat' ];
$ret['limits'] = PermissionLimits::Std_Limits();
+ $ret['channel_type'] = 'group';
break;
@@ -132,6 +134,7 @@ class PermissionRoles {
$ret['limits']['view_storage'] = PERMS_SPECIFIC;
$ret['limits']['view_pages'] = PERMS_SPECIFIC;
$ret['limits']['view_wiki'] = PERMS_SPECIFIC;
+ $ret['channel_type'] = 'group';
break;
@@ -187,6 +190,7 @@ class PermissionRoles {
'post_mail', 'post_like' , 'republish', 'chat', 'write_wiki'
];
$ret['limits'] = PermissionLimits::Std_Limits();
+ $ret['channel_type'] = 'group';
break;
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 95359ccad..29563a9a5 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -14,6 +14,7 @@ use Zotlabs\Web\HTTPSig;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\ThreadListener;
+use Zotlabs\Access\PermissionRoles;
use App;
require_once('include/crypto.php');
@@ -677,6 +678,25 @@ class Item extends Controller {
$str_contact_deny = $gacl['deny_cid'];
$str_group_deny = $gacl['deny_gid'];
+
+ $groupww = false;
+
+ // if this is a wall-to-wall post to a group, turn it into a direct message
+
+ $role = get_pconfig($profile_uid,'system','permissions_role');
+
+ $rolesettings = PermissionRoles::role_perms($role);
+
+ $channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
+
+ $is_group = (($channel_type === 'group') ? true : false);
+
+ if (($is_group) && ($walltowall) && (! $walltowall_comment)) {
+ $groupww = true;
+ $str_contact_allow = $owner_xchan['xchan_hash'];
+ $str_group_allow = '';
+ }
+
$post_tags = [];
if($mimetype === 'text/bbcode') {
@@ -1233,7 +1253,11 @@ class Item extends Controller {
$datarray['llink'] = z_root() . '/display/' . gen_link_id($datarray['mid']);
call_hooks('post_local_end', $datarray);
-
+
+ if ($groupww) {
+ $nopush = false;
+ }
+
if(! $nopush)
Master::Summon([ 'Notifier', $notify_type, $post_id ]);
diff --git a/include/items.php b/include/items.php
index a566ddfd9..f2db7288f 100755
--- a/include/items.php
+++ b/include/items.php
@@ -12,6 +12,7 @@ use Zotlabs\Lib\IConfig;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
use Zotlabs\Access\PermissionLimits;
+use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\AccessList;
use Zotlabs\Daemon\Master;
@@ -290,7 +291,7 @@ function is_item_normal($item) {
*/
function can_comment_on_post($observer_xchan, $item) {
-// logger('Comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG);
+ // logger('Comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG);
$x = [
'observer_hash' => $observer_xchan,
@@ -351,7 +352,8 @@ function can_comment_on_post($observer_xchan, $item) {
return true;
}
break;
- default:
+
+ default:
break;
}
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red')) {
@@ -2628,6 +2630,12 @@ function get_item_contact($item,$contacts) {
*/
function tag_deliver($uid, $item_id) {
+ $role = get_pconfig($uid,'system','permissions_role');
+ $rolesettings = PermissionRoles::role_perms($role);
+ $channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
+
+ $is_group = (($channel_type === 'group') ? true : false);
+
$mention = false;
/*
@@ -2647,6 +2655,7 @@ function tag_deliver($uid, $item_id) {
if(! $i)
return;
+ xchan_query($i,true);
$i = fetch_post_tags($i);
$item = $i[0];
@@ -2662,6 +2671,28 @@ function tag_deliver($uid, $item_id) {
return;
}
+ if ($is_group && intval($item['item_private']) === 2 && intval($item['item_thread_top'])) {
+ // group delivery via DM
+ logger('group DM delivery for ' . $u[0]['channel_address']);
+ start_delivery_chain($u[0], $item, $item_id, 0, false);
+ return;
+ }
+
+
+ if ($is_group && intval($item['item_thread_top']) && intval($item['item_wall']) && $item['author_xchan'] !== $item['owner_xchan']) {
+ if (strpos($item['body'],'[/share]')) {
+ logger('W2W post already shared');
+ return;
+ }
+ // group delivery via W2W
+ logger('rewriting W2W post for ' . $u[0]['channel_address']);
+ start_delivery_chain($u[0], $item, $item_id, 0, false);
+ q("update item set item_wall = 0 where id = %d",
+ intval($item_id)
+ );
+ return;
+ }
+
/*
* Seems like a good place to plug in a poke notification.
*/
@@ -2965,6 +2996,13 @@ function item_community_tag($channel,$item) {
*/
function tgroup_check($uid, $item) {
+
+ $role = get_pconfig($uid,'system','permissions_role');
+ $rolesettings = PermissionRoles::role_perms($role);
+ $channel_type = isset($rolesettings['channel_type']) ? $rolesettings['channel_type'] : 'normal';
+
+ $is_group = (($channel_type === 'group') ? true : false);
+
$mention = false;
// check that the message originated elsewhere and is a top-level post
@@ -2981,6 +3019,15 @@ function tgroup_check($uid, $item) {
return false;
}
+ // post to group via DM
+
+ if ($is_group) {
+ if (intval($item['item_private']) === 2 && $item['mid'] === $item['parent_mid']) {
+ return true;
+ }
+ }
+
+
// see if we already have this item. Maybe it is being updated.
$r = q("select id from item where mid = '%s' and uid = %d limit 1",
@@ -3136,6 +3183,75 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $edit = false)
}
}
+ // @todo handle edit and parent correctly
+
+ if(! $parent) {
+
+ if ($edit) {
+ return;
+ }
+
+ $arr = [];
+
+ $arr['aid'] = $channel['channel_account_id'];
+ $arr['uid'] = $channel['channel_id'];
+
+ $arr['item_private'] = (($channel['channel_allow_cid'] || $channel['channel_allow_gid']
+ || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
+
+ $arr['item_origin'] = 1;
+ $arr['item_wall'] = 1;
+
+ $arr['uuid'] = item_message_id();
+ $arr['mid'] = z_root() . '/activity/' . $arr['uuid'];
+ $arr['parent_mid'] = $arr['mid'];
+ $arr['item_thread_top'] = 1;
+
+ if (strpos($item['body'], "[/share]") !== false) {
+ $pos = strpos($item['body'], "[share");
+ $bb = substr($item['body'], $pos);
+ } else {
+ $bb = "[share author='" . urlencode($item['author']['xchan_name']).
+ "' profile='" . $item['author']['xchan_url'] .
+ "' portable_id='" . $item['author']['xchan_hash'] .
+ "' avatar='" . $item['author']['xchan_photo_s'] .
+ "' link='" . $item['plink'] .
+ "' auth='" . ((in_array($item['author']['network'], ['zot','zot6'])) ? 'true' : 'false') .
+ "' posted='" . $item['created'] .
+ "' message_id='" . $item['mid'] .
+ "']";
+ if($item['title'])
+ $bb .= '[b]'.$item['title'].'[/b]'."\r\n";
+ $bb .= $item['body'];
+ $bb .= "[/share]";
+ }
+
+ $mention = '@[zrl=' . $item['author']['xchan_url'] . ']' . $item['author']['xchan_name'] . '[/zrl]';
+ $arr['body'] = $bb;
+
+ $arr['author_xchan'] = $channel['channel_hash'];
+ $arr['owner_xchan'] = $channel['channel_hash'];
+ // $arr['obj'] = $item['obj'];
+ $arr['obj_type'] = $item['obj_type'];
+ $arr['verb'] = ACTIVITY_POST;
+
+ $arr['allow_cid'] = $channel['channel_allow_cid'];
+ $arr['allow_gid'] = $channel['channel_allow_gid'];
+ $arr['deny_cid'] = $channel['channel_deny_cid'];
+ $arr['deny_gid'] = $channel['channel_deny_gid'];
+ $arr['comment_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'],'post_comments'));
+
+ $post = item_store($arr);
+
+ $post_id = $post['item_id'];
+
+ if($post_id) {
+ Master::Summon([ 'Notifier','tgroup',$post_id ]);
+ }
+ return;
+ }
+
+
// Change this copy of the post to a forum head message and deliver to all the tgroup members
// also reset all the privacy bits to the forum default permissions