Forum posts with "!" are now created directly as forum post

This commit is contained in:
Michael 2017-11-02 20:15:14 +00:00
parent e26eb0146f
commit a2f9ea2642
3 changed files with 34 additions and 90 deletions

View file

@ -1987,81 +1987,6 @@ class dfrn {
return true; return true;
} }
/**
* @brief Check and possibly rewrite a post if it was a dedicated forum post
*
* @param array $item the new item record
*
* @return boolean Was the post be rewritten?
*/
private static function rewriteDedicatedForumPost($item) {
$fields = array('author-link', 'allow_cid', 'contact-id', 'private', 'wall', 'id', 'parent');
$condition = array('uri' => $item['uri'], 'uid' => $item['uid']);
$existing = dba::select('item', $fields, $condition, array('limit' => 1));
if (!dbm::is_result($existing)) {
return false;
}
// Only rewrite if the former post was a private starting post
if (!$existing['wall'] || !$existing['private'] || ($existing['id'] != $existing['parent'])) {
return false;
}
// Is the post only directed to a single forum?
if ($existing['allow_cid'] != '<'.$item['contact-id'].'>') {
return false;
}
$fields = array('id');
$condition = array('uid' => $item['uid'], 'self' => true);
$self = dba::select('contact', $fields, $condition, array('limit' => 1));
if (!dbm::is_result($self)) {
return false;
}
// is the original item created by the "self" user.
if ($self['id'] != $existing['contact-id']) {
return false;
}
$fields = array('forum', 'prv');
$condition = array('id' => $item['contact-id']);
$contact = dba::select('contact', $fields, $condition, array('limit' => 1));
if (!dbm::is_result($contact)) {
return false;
}
// Is the post from a forum?
if (!$contact['forum'] && !$contact['prv']) {
return false;
}
/// @todo There is an ugly downside of this whole rewrite process: These items loose the ability to be edited by the user.
logger('Item '.$item['uri'].' will be rewritten.', LOGGER_DEBUG);
$item = store_conversation($item);
unset($fields['dsprsig']);
// Rewrite to a public post if it comes from a public forum
if ($contact['forum']) {
$item['allow_cid'] = '';
$item['allow_gid'] = '';
$item['deny_cid'] = '';
$item['deny_gid'] = '';
$item['private'] = false;
}
$item['wall'] = false;
$item["owner-id"] = get_contact($item["owner-link"], 0);
$condition = array('uri' => $item["uri"], 'uid' => $item["uid"]);
dba::update('item', $item, $condition);
add_shadow_thread($existing['id']);
return true;
}
/** /**
* @brief Updates an item * @brief Updates an item
* *
@ -2081,14 +2006,12 @@ class dfrn {
return false; return false;
} }
if (!self::rewriteDedicatedForumPost($item)) {
$fields = array('title' => $item["title"], 'body' => $item["body"], $fields = array('title' => $item["title"], 'body' => $item["body"],
'tag' => $item["tag"], 'changed' => datetime_convert(), 'tag' => $item["tag"], 'changed' => datetime_convert(),
'edited' => datetime_convert("UTC", "UTC", $item["edited"])); 'edited' => datetime_convert("UTC", "UTC", $item["edited"]));
$condition = array("`uri` = ? AND `uid` IN (0, ?)", $item["uri"], $importer["importer_uid"]); $condition = array("`uri` = ? AND `uid` IN (0, ?)", $item["uri"], $importer["importer_uid"]);
dba::update('item', $fields, $condition); dba::update('item', $fields, $condition);
}
create_tags_from_itemuri($item["uri"], $importer["importer_uid"]); create_tags_from_itemuri($item["uri"], $importer["importer_uid"]);
update_thread_uri($item["uri"], $importer["importer_uid"]); update_thread_uri($item["uri"], $importer["importer_uid"]);

View file

@ -215,6 +215,9 @@ function notifier_run(&$argv, &$argc){
// Do a PuSH // Do a PuSH
$push_notify = false; $push_notify = false;
// Deliver directly to a forum, don't PuSH
$direct_forum_delivery = false;
// fill this in with a single salmon slap if applicable // fill this in with a single salmon slap if applicable
$slap = ''; $slap = '';
@ -302,6 +305,7 @@ function notifier_run(&$argv, &$argc){
// Is the post from a forum? // Is the post from a forum?
if ($contact['forum'] || $contact['prv']) { if ($contact['forum'] || $contact['prv']) {
$relay_to_owner = true; $relay_to_owner = true;
$direct_forum_delivery = true;
} }
} }
if ($relay_to_owner) { if ($relay_to_owner) {
@ -337,6 +341,11 @@ function notifier_run(&$argv, &$argc){
} }
} }
} }
if ($direct_forum_delivery) {
$push_notify = false;
}
logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG); logger("Notify ".$target_item["guid"]." via PuSH: ".($push_notify?"Yes":"No"), LOGGER_DEBUG);
} else { } else {
$followup = false; $followup = false;

View file

@ -576,6 +576,7 @@ function item_post(App $a) {
$private_forum = false; $private_forum = false;
$only_to_forum = false; $only_to_forum = false;
$forum_contact = array();
if (count($tags)) { if (count($tags)) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
@ -608,18 +609,29 @@ function item_post(App $a) {
} }
// When the forum is private or the forum is addressed with a "!" make the post private // When the forum is private or the forum is addressed with a "!" make the post private
if (is_array($success['contact']) && ($success['contact']['prv'] || ($tag_type == '!'))) { if (is_array($success['contact']) && ($success['contact']['prv'] || ($tag_type == '!'))) {
$private_forum = true; $private_forum = $success['contact']['prv'];
$only_to_forum = ($tag_type == '!'); $only_to_forum = ($tag_type == '!');
$private_id = $success['contact']['id']; $private_id = $success['contact']['id'];
$forum_contact = $success['contact'];
} }
} }
} }
if ($private_forum && !$parent && (!$private || $only_to_forum)) { if (!$parent && count($forum_contact) && ($private_forum || $only_to_forum)) {
// we tagged a private forum in a top level post and the message was public. // we tagged a forum in a top level post. Now we change the post
// Restrict it. $private = $private_forum;
$private = 1;
$str_group_allow = '';
$str_contact_deny = '';
$str_group_deny = '';
if ($private_forum) {
$str_contact_allow = '<' . $private_id . '>'; $str_contact_allow = '<' . $private_id . '>';
} else {
$str_contact_allow = '';
}
$contact_id = $private_id;
$contact_record = $forum_contact;
$_REQUEST['origin'] = false;
} }
$attachments = ''; $attachments = '';
@ -643,7 +655,7 @@ function item_post(App $a) {
$wall = 0; $wall = 0;
if ($post_type === 'wall' || $post_type === 'wall-comment') { if (($post_type === 'wall' || $post_type === 'wall-comment') && !count($forum_contact)) {
$wall = 1; $wall = 1;
} }
@ -971,7 +983,7 @@ function item_post(App $a) {
intval($parent), intval($parent),
intval($post_id)); intval($post_id));
if ($contact_record != $author) { if (($contact_record != $author) && !count($forum_contact)) {
notification(array( notification(array(
'type' => NOTIFY_WALL, 'type' => NOTIFY_WALL,
'notify_flags' => $user['notify-flags'], 'notify_flags' => $user['notify-flags'],