`
: ''}
`
diff --git a/conversejs/loc.keys.js b/conversejs/loc.keys.js
index 6d167438..ee0cadc1 100644
--- a/conversejs/loc.keys.js
+++ b/conversejs/loc.keys.js
@@ -42,7 +42,9 @@ const locKeys = [
'poll_anonymous_results',
'poll_choice_n',
'poll_title',
- 'poll_instructions'
+ 'poll_instructions',
+ 'poll_end',
+ 'poll'
]
module.exports = locKeys
diff --git a/languages/en.yml b/languages/en.yml
index 99f53d50..96e824ba 100644
--- a/languages/en.yml
+++ b/languages/en.yml
@@ -565,9 +565,11 @@ livechat_configuration_channel_terms_desc: |
You can configure a "terms & conditions" message that will be shown to users joining your chatrooms.
new_poll: Create a new poll
+poll: Poll
poll_title: New poll
poll_instructions: Complete and submit this form to create a new poll. This will end and replace any existing poll.
poll_question: Question
poll_duration: Poll duration (in minutes)
poll_anonymous_results: Anonymous results
poll_choice_n: Choice {{N}}
+poll_end: 'Poll ends at:'
diff --git a/prosody-modules/mod_muc_poll/message.lib.lua b/prosody-modules/mod_muc_poll/message.lib.lua
index fa1a8d45..601ce217 100644
--- a/prosody-modules/mod_muc_poll/message.lib.lua
+++ b/prosody-modules/mod_muc_poll/message.lib.lua
@@ -62,7 +62,7 @@ local function build_poll_message(room, message_id, is_end_message)
}):up();
-- now we must add some custom XML data, so that compatible clients can display the poll as they want:
- --
+ --
-- Poll question
-- Choice 1 label
-- Choice 2 label
@@ -74,6 +74,7 @@ local function build_poll_message(room, message_id, is_end_message)
id = current_poll.poll_id,
votes = "" .. total
};
+ message_attrs["end"] = string.format("%i", current_poll.end_timestamp);
if current_poll.already_ended then
message_attrs["over"] = "";
end
@@ -175,9 +176,23 @@ local function remove_specific_tags_from_groupchat(event)
end);
end
+-- when a new session is opened, we must send the current poll to the client
+local function handle_new_occupant_session(event)
+ local room = event.room;
+ if not room._data.current_poll then
+ return;
+ end
+ if room._data.current_poll.already_ended then
+ return;
+ end
+ schedule_poll_update_message(room.jid);
+ -- FIXME: for now we just schedule a new poll update. But we should only send a message to the new occupant.
+end
+
return {
poll_start_message = poll_start_message;
poll_end_message = poll_end_message;
schedule_poll_update_message = schedule_poll_update_message;
remove_specific_tags_from_groupchat = remove_specific_tags_from_groupchat;
+ handle_new_occupant_session = handle_new_occupant_session;
};
diff --git a/prosody-modules/mod_muc_poll/mod_muc_poll.lua b/prosody-modules/mod_muc_poll/mod_muc_poll.lua
index 90bbb320..a8c8600c 100644
--- a/prosody-modules/mod_muc_poll/mod_muc_poll.lua
+++ b/prosody-modules/mod_muc_poll/mod_muc_poll.lua
@@ -19,7 +19,8 @@ local xmlns_poll = module:require("constants").xmlns_poll;
local send_form = module:require("form").send_form;
local process_form = module:require("form").process_form;
local handle_groupchat = module:require("poll").handle_groupchat;
-local remove_specific_tags_from_groupchat = module:require("message").remove_specific_tags_from_groupchat
+local remove_specific_tags_from_groupchat = module:require("message").remove_specific_tags_from_groupchat;
+local handle_new_occupant_session = module:require("message").handle_new_occupant_session;
local room_restored = module:require("poll").room_restored;
-- new poll creation, get form
@@ -85,7 +86,11 @@ module:hook("muc-occupant-groupchat", handle_groupchat, 1000);
-- security check: we must remove all specific tags, to be sure nobody tries to spoof polls!
module:hook("muc-occupant-groupchat", remove_specific_tags_from_groupchat, 1000);
-
-- when a room is restored (after a server restart for example),
-- we must resume any current poll
module:hook("muc-room-restored", room_restored);
+
+-- when a new session is opened, we must send the current poll to the client
+-- Note: it should be in the MAM. But it is easier for clients to ignore delayed messages
+-- when displaying polls (to ignore old polls).
+module:hook("muc-occupant-session-new", handle_new_occupant_session);