aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Lib/Activity.php178
-rw-r--r--Zotlabs/Module/Vote.php3
-rw-r--r--include/items.php3
3 files changed, 102 insertions, 82 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 5f5a4c003..66d5edcd9 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -2021,129 +2021,149 @@ class Activity {
}
- static function update_poll($item_id, $post) {
+ static function update_poll($pollItem, $response) {
- $multi = false;
- $mid = $post['mid'];
- $content = $post['title'];
+ logger('updating poll');
- if (!$item_id) {
+ $multi = false;
+
+
+ if (!$pollItem) {
+ logger('no item');
return false;
}
- if (intval($post['item_blocked']) === ITEM_MODERATED) {
+ if (intval($pollItem['item_blocked']) === ITEM_MODERATED) {
+ logger('item blocked');
return false;
}
- dbq("START TRANSACTION");
-
- $item = q("SELECT * FROM item WHERE id = %d FOR UPDATE",
- intval($item_id)
- );
-
- if (!$item) {
- dbq("COMMIT");
+ $channel = channelx_by_n($pollItem['uid']);
+ if (!$channel) {
+ logger('no channel');
return false;
}
- $item = $item[0];
-
- $o = json_decode($item['obj'], true);
+ $o = json_decode($pollItem['obj'], true);
if ($o && array_key_exists('anyOf', $o)) {
$multi = true;
}
- $r = q("select mid, title from item where parent_mid = '%s' and author_xchan = '%s'",
- dbesc($item['mid']),
- dbesc($post['author_xchan'])
- );
+ if ($response) {
+ $mid = $response['mid'];
+ $content = trim($response['title']);
- // prevent any duplicate votes by same author for oneOf and duplicate votes with same author and same answer for anyOf
- if ($r) {
- if ($multi) {
- foreach ($r as $rv) {
- if ($rv['title'] === $content && $rv['mid'] !== $mid) {
- return false;
+ $r = q("select mid, title from item where parent_mid = '%s' and author_xchan = '%s' and mid != parent_mid ",
+ dbesc($pollItem['mid']),
+ dbesc($response['author_xchan'])
+ );
+
+ // prevent any duplicate votes by same author for oneOf and duplicate votes with same author and same answer for anyOf
+
+ if ($r) {
+ if ($multi) {
+ foreach ($r as $rv) {
+ if (trim($rv['title']) === $content && $rv['mid'] !== $mid) {
+ logger('already voted multi');
+ return false;
+ }
}
- }
- }
- else {
- foreach ($r as $rv) {
- if ($rv['mid'] !== $mid) {
- return false;
+ } else {
+ foreach ($r as $rv) {
+ if ($rv['mid'] !== $mid && $content) {
+ logger('already voted');
+ return false;
+ }
}
}
}
- }
- $answer_found = false;
- $found = false;
- if ($multi) {
- for ($c = 0; $c < count($o['anyOf']); $c++) {
- if ($o['anyOf'][$c]['name'] === $content) {
- $answer_found = true;
- if (is_array($o['anyOf'][$c]['replies'])) {
- foreach ($o['anyOf'][$c]['replies'] as $reply) {
- if (is_array($reply) && array_key_exists('id', $reply) && $reply['id'] === $mid) {
- $found = true;
+ $answer_found = false;
+ $foundPrevious = false;
+ if ($multi) {
+ for ($c = 0; $c < count($o['anyOf']); $c++) {
+ if (trim($o['anyOf'][$c]['name']) === $content) {
+ $answer_found = true;
+ if (is_array($o['anyOf'][$c]['replies'])) {
+ foreach ($o['anyOf'][$c]['replies'] as $reply) {
+ if (is_array($reply) && array_key_exists('id', $reply) && $reply['id'] === $mid) {
+ $foundPrevious = true;
+ }
}
}
- }
- if (!$found) {
- $o['anyOf'][$c]['replies']['totalItems']++;
- $o['anyOf'][$c]['replies']['items'][] = ['id' => $mid, 'type' => 'Note'];
+ if (!$foundPrevious) {
+ $o['anyOf'][$c]['replies']['totalItems']++;
+ $o['anyOf'][$c]['replies']['items'][] = ['id' => $mid, 'type' => 'Note'];
+ }
}
}
- }
- }
- else {
- for ($c = 0; $c < count($o['oneOf']); $c++) {
- if ($o['oneOf'][$c]['name'] === $content) {
- $answer_found = true;
- if (is_array($o['oneOf'][$c]['replies'])) {
- foreach ($o['oneOf'][$c]['replies'] as $reply) {
- if (is_array($reply) && array_key_exists('id', $reply) && $reply['id'] === $mid) {
- $found = true;
+ } else {
+ for ($c = 0; $c < count($o['oneOf']); $c++) {
+ if (trim($o['oneOf'][$c]['name']) === $content) {
+ $answer_found = true;
+ if (is_array($o['oneOf'][$c]['replies'])) {
+ foreach ($o['oneOf'][$c]['replies'] as $reply) {
+ if (is_array($reply) && array_key_exists('id', $reply) && $reply['id'] === $mid) {
+ $foundPrevious = true;
+ }
}
}
- }
- if (!$found) {
- $o['oneOf'][$c]['replies']['totalItems']++;
- $o['oneOf'][$c]['replies']['items'][] = ['id' => $mid, 'type' => 'Note'];
+ if (!$foundPrevious) {
+ $o['oneOf'][$c]['replies']['totalItems']++;
+ $o['oneOf'][$c]['replies']['items'][] = ['id' => $mid, 'type' => 'Note'];
+ }
}
}
}
}
+ if ($pollItem['comments_closed'] > NULL_DATE) {
+ if ($pollItem['comments_closed'] > datetime_convert()) {
+ $o['closed'] = datetime_convert('UTC', 'UTC', $pollItem['comments_closed'], ATOM_TIME);
+ // set this to force an update
+ $answer_found = true;
+ }
+ }
+
logger('updated_poll: ' . print_r($o, true), LOGGER_DATA);
- if ($answer_found && !$found) {
- $u = q("update item set obj = '%s', edited = '%s' where id = %d",
+
+ // A change was made locally
+ if ($response && $answer_found && !$foundPrevious) {
+ q("update item set obj = '%s', edited = '%s' where id = %d",
dbesc(json_encode($o)),
dbesc(datetime_convert()),
- intval($item['id'])
+ intval($pollItem['id'])
);
+ }
- if ($u) {
- dbq("COMMIT");
+ $i = q("select * from item where id = %d",
+ intval($pollItem['id'])
+ );
- if ($multi) {
- // wait some seconds for possible multiple answers to be processed
- // before calling the notifier
- sleep(3);
- }
+ xchan_query($i, true);
+ $items = fetch_post_tags($i);
- Master::Summon(['Notifier', 'wall-new', $item['id']]);
- return true;
- }
+ $pollItem = array_shift($items);
+ $pollItem['obj'] = json_decode($pollItem['obj'],true);
+ $pollItem['target'] = json_decode($pollItem['target'], true);
+ $pollItem['attach'] = json_decode($pollItem['attach'], true);
- dbq("ROLLBACK");
+ Master::Summon(['Notifier', 'edit_post', $pollItem['id']]);
+ $related = find_related($pollItem);
+ if ($related) {
+ // Update the object in the collection activity and the timestamp
+ $newObj = self::build_packet(self::encode_activity($pollItem), $channel);
+ $r = q("update item set obj = '%s', edited = '%s' where id = %d",
+ dbesc($newObj),
+ dbesc(datetime_convert()),
+ intval($related['id'])
+ );
+ Master::Summon(['Notifier', 'edit_post', $related['id']]);
}
-
- dbq("COMMIT");
- return false;
+ return true;
}
static function decode_note($act) {
diff --git a/Zotlabs/Module/Vote.php b/Zotlabs/Module/Vote.php
index d288426e9..5192e3043 100644
--- a/Zotlabs/Module/Vote.php
+++ b/Zotlabs/Module/Vote.php
@@ -107,8 +107,7 @@ class Vote extends Controller {
retain_item($fetch[0]['id']);
if($x['success']) {
- $itemid = $x['item_id'];
- Master::Summon( ['Notifier', 'like', $itemid ] );
+ Master::Summon(['Notifier', 'like', $x['item_id']]);
if (!empty($x['approval_id'])) {
Master::Summon(['Notifier', 'like', $x['approval_id']]);
}
diff --git a/include/items.php b/include/items.php
index 41c60103c..41bb3cff7 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1897,7 +1897,7 @@ function item_store($arr, $allow_exec = false, $deliver = true, $addAndSync = tr
$arr['item_private'] = 0;
if(in_array($arr['obj_type'], ['Note','Answer']) && $r[0]['obj_type'] === 'Question' && intval($r[0]['item_wall'])) {
- Activity::update_poll($r[0]['id'], $arr);
+ Activity::update_poll($r[0], $arr);
}
}
@@ -4034,6 +4034,7 @@ function find_related($item) {
if (! $allRelated) {
return false;
}
+
if ($item['verb'] === 'Add' && $item['tgt_type'] === 'Collection') {
$thisItem = json_decode($item['obj'],true);
if (is_array($thisItem)) {