diff options
-rw-r--r-- | Zotlabs/Lib/Activity.php | 30 | ||||
-rwxr-xr-x | include/items.php | 2 |
2 files changed, 30 insertions, 2 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 2f219af1f..02ec7614e 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1673,8 +1673,11 @@ class Activity { - static function update_poll($item,$mid,$content) { + static function update_poll($item,$post) { $multi = false; + $mid = $post['mid']; + $content = $post['title']; + if (! $item) { return false; } @@ -1683,6 +1686,31 @@ class Activity { 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']) + ); + + // 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; + } + } + } + else { + foreach ($r as $rv) { + if ($rv['mid'] !== $mid) { + return false; + } + } + } + } + $answer_found = false; $found = false; if ($multi) { diff --git a/include/items.php b/include/items.php index bf1ddee82..9768fdf23 100755 --- a/include/items.php +++ b/include/items.php @@ -1950,7 +1950,7 @@ function item_store($arr, $allow_exec = false, $deliver = true) { $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],$arr['mid'],$arr['title']); + Activity::update_poll($r[0],$arr); } } |