Skip to content

Commit

Permalink
widgets: Add question for poll widget in the message itself.
Browse files Browse the repository at this point in the history
Use the command '/poll question?', to start a question.
  • Loading branch information
rheaparekh committed Jun 28, 2018
1 parent 7cdc22b commit b7562e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions static/js/voting_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var voting_widget = (function () {

var exports = {};

var poll_data_holder = function (is_my_poll) {
var poll_data_holder = function (is_my_poll, question) {
// This object just holds data for a poll, although it
// works closely with the widget's concept of how data
// should be represented for rendering, plus how the
// server sends us data.
var self = {};

var me = people.my_current_user_id();
var poll_question = '';
var poll_question = question;
var key_to_comment = {};
var my_idx = 1;

Expand Down Expand Up @@ -141,9 +141,10 @@ var poll_data_holder = function (is_my_poll) {
exports.activate = function (opts) {
var elem = opts.elem;
var callback = opts.callback;
var question = opts.extra_data.question;

var is_my_poll = people.is_my_user_id(opts.message.sender_id);
var poll_data = poll_data_holder(is_my_poll);
var poll_data = poll_data_holder(is_my_poll, question);

function render() {
var html = templates.render('poll-widget');
Expand Down
13 changes: 11 additions & 2 deletions zerver/lib/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ def do_widget_post_save_actions(message: MutableMapping[str, Any]) -> None:

widget_type = None
extra_data = None
if content in ['/poll', '/tictactoe']:
widget_type = content[1:]

tokens = content.split(' ')

if content in ['/tictactoe'] or tokens[0] in ['/poll']:
widget_type = tokens[0][1:]

widget_content = message.get('widget_content')
if widget_content is not None:
Expand All @@ -40,6 +43,12 @@ def do_widget_post_save_actions(message: MutableMapping[str, Any]) -> None:
widget_type = widget_content['widget_type']
extra_data = widget_content['extra_data']

if tokens[0] == '/poll' and extra_data is None:
question = ' '.join(tokens[1:])
if not question:
question = ''
extra_data = {'question': question}

if widget_type:
content = dict(
widget_type=widget_type,
Expand Down

0 comments on commit b7562e0

Please sign in to comment.