From 22f8b205ee4a7f5312effef28a201424988e6dfa Mon Sep 17 00:00:00 2001
From: echicken <echicken@bbs.electronicchicken.com>
Date: Wed, 23 Nov 2016 01:06:31 -0500
Subject: [PATCH] Poll-posting things.

---
 web/lib/forum.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/web/lib/forum.js b/web/lib/forum.js
index da2aeb7e77..89d7e49510 100644
--- a/web/lib/forum.js
+++ b/web/lib/forum.js
@@ -475,6 +475,61 @@ function postReply(sub, body, pid) {
     return ret;
 }
 
+function postPoll(sub, subject, votes, results, answers, comments) {
+
+    if (user.alias == settings.guest || user.security.restrictions&UFLAG_V) {
+        return false;
+    }
+
+    if (typeof msg_area.sub[sub] === 'undefined' || !msg_area.sub[sub].can_post) {
+        return false;
+    }
+
+    if (typeof subject !== 'string' || subject.length < 1) return false;
+
+    if (!Array.isArray(answers) || answers.length < 2) return false;
+
+    votes = parseInt(votes);
+    if (isNaN(votes) || votes < 1 || votes > 15) return false;
+    if (votes > answers) votes = answers;
+
+    results = parseInt(results);
+    if (isNaN(results) || results < 0 || results > 3) {
+        return false;
+    }
+
+    var header = {
+        subject : subject,
+        from : msg_area.sub[sub].settings&SUB_NAME ? user.name : user.alias,
+        from_ext : user.number,
+        field_list : [],
+        auxattr : (results<<POLL_RESULTS_SHIFT),
+        votes : votes
+    };
+
+    if (Array.isArray(comments)) {
+        comments.forEach(
+            function (e) {
+                header.field_list.push({ type : SMB_COMMENT, data : e });
+            }
+        );
+    }
+
+    answers.forEach(
+        function (e) {
+            header.field_list.push({ type : SMB_POLL_ANSWER, data : e });
+        }
+    );
+
+    var msgBase = new MsgBase(sub);
+    if (!msgBase.open()) return false;
+    var ret = msgBase.add_poll(header);
+    msgBase.close();
+
+    return ret;
+
+}
+
 // Delete a message if
 // - This is the mail sub, and the message was sent by or to this user
 // - This is another sub on which the user is an operator
-- 
GitLab