parent
1c6434630e
commit
4168b2ce41
@ -69,9 +69,14 @@ converse.plugins.add('livechat-converse-poll', {
|
||||
if (!attrs.current_poll) {
|
||||
return this.__super__.onMessage(attrs)
|
||||
}
|
||||
// We intercept poll messages, so they won't show up in the chat as classic messages.
|
||||
if (attrs.is_delayed) {
|
||||
console.info('Got a delayed poll message, just dropping')
|
||||
// We intercept poll messages, to show the banner.
|
||||
// Note: we also show the message in the chat.
|
||||
if (attrs.is_delayed || attrs.is_archived) {
|
||||
if (attrs.current_poll.over) {
|
||||
console.info('Got a delayed/archived poll message for an poll that is over, just displaying in the chat')
|
||||
return this.__super__.onMessage(attrs)
|
||||
}
|
||||
console.info('Got a delayed/archived poll message, just dropping')
|
||||
return
|
||||
}
|
||||
|
||||
@ -79,6 +84,11 @@ converse.plugins.add('livechat-converse-poll', {
|
||||
this.set('current_poll', attrs.current_poll)
|
||||
// this will be displayed by the livechat-converse-muc-poll custom element,
|
||||
// which is inserted in the DOM by the muc.js template overload.
|
||||
if (attrs.current_poll.over) {
|
||||
console.info('The poll is over, displaying the message in the chat')
|
||||
return this.__super__.onMessage(attrs)
|
||||
}
|
||||
// Dropping the message.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,3 +13,19 @@ There will probably be a XEP proposal for this module behaviour. When done, this
|
||||
## Configuration
|
||||
|
||||
Just enable the module on your MUC component.
|
||||
All above configurations are optional.
|
||||
|
||||
## poll_groupchat_votes_priority
|
||||
|
||||
The priority for the hook that will take into account votes.
|
||||
You can change this, if you have some specific hook that should be done after/before counting votes (slow mode, firewall, ...).
|
||||
|
||||
Default: 500
|
||||
|
||||
## Strings
|
||||
|
||||
You can change some defaults strings, if you want for example to localize the poll messages.
|
||||
Here are the existing strings and default values:
|
||||
|
||||
* poll_string_over: This poll is now over.
|
||||
* poll_string_vote_instructions: Send a message with an exclamation mark followed by your choice number to vote. Example: !1
|
||||
|
@ -17,18 +17,21 @@ local get_room_from_jid = mod_muc.get_room_from_jid;
|
||||
local debounce_delay = 5; -- number of seconds during which we must group votes to avoid flood.
|
||||
local scheduled_updates = {};
|
||||
|
||||
local string_poll_over = module:get_option_string("poll_string_over") or "This poll is now over.";
|
||||
local string_poll_vote_instructions = module:get_option_string("poll_string_vote_instructions") or "Send a message with an exclamation mark followed by your choice number to vote. Example: !1";
|
||||
|
||||
-- construct the poll message stanza
|
||||
local function build_poll_message(room, message_id, is_end_message)
|
||||
local current_poll = room._data.current_poll;
|
||||
if not current_poll then
|
||||
return nil;
|
||||
end
|
||||
local from = room.jid .. '/' .. current_poll.occupant_nick;
|
||||
local from = current_poll.occupant_nick; -- this is in fact room.jid/nickname
|
||||
|
||||
local content = current_poll["muc#roompoll_question"] .. "\n";
|
||||
|
||||
if is_end_message then
|
||||
content = content .. "This poll is now over.\n";
|
||||
content = content .. string_poll_over .. "\n";
|
||||
end
|
||||
|
||||
local total = 0;
|
||||
@ -47,7 +50,7 @@ local function build_poll_message(room, message_id, is_end_message)
|
||||
end
|
||||
|
||||
if not is_end_message then
|
||||
content = content .. "Send a message with an exclamation mark followed by your choice number to vote. Example: !1\n";
|
||||
content = content .. string_poll_vote_instructions .. "\n";
|
||||
end
|
||||
|
||||
local msg = st.message({
|
||||
|
@ -23,6 +23,9 @@ local remove_specific_tags_from_groupchat = module:require("message").remove_spe
|
||||
local handle_new_occupant_session = module:require("message").handle_new_occupant_session;
|
||||
local room_restored = module:require("poll").room_restored;
|
||||
|
||||
local poll_groupchat_votes_priority = module:get_option_number("poll_groupchat_votes_priority") or 500;
|
||||
|
||||
|
||||
-- new poll creation, get form
|
||||
module:hook("iq-get/bare/" .. xmlns_poll .. ":query", function (event)
|
||||
local origin, stanza = event.origin, event.stanza;
|
||||
@ -81,7 +84,7 @@ end);
|
||||
|
||||
-- On groupchat messages, we check if this is a vote for the current poll.
|
||||
-- Note: we use a high priority, so it will be handled before the slow mode.
|
||||
module:hook("muc-occupant-groupchat", handle_groupchat, 1000);
|
||||
module:hook("muc-occupant-groupchat", handle_groupchat, poll_groupchat_votes_priority);
|
||||
|
||||
-- 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);
|
||||
|
@ -366,6 +366,8 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
|
||||
}
|
||||
}
|
||||
|
||||
config.usePoll()
|
||||
|
||||
config.useTestModule(apikey, testApiUrl)
|
||||
|
||||
const debugMucAdminJids = debugMucAdmins(options)
|
||||
|
@ -248,8 +248,6 @@ class ProsodyConfigContent {
|
||||
if (chatTerms) {
|
||||
this.muc.set('muc_terms_global', new ConfigEntryValueMultiLineString(chatTerms))
|
||||
}
|
||||
|
||||
this.muc.add('modules_enabled', 'muc_poll')
|
||||
}
|
||||
|
||||
useAnonymous (autoBanIP: boolean): void {
|
||||
@ -532,6 +530,14 @@ class ProsodyConfigContent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the poll feature.
|
||||
*/
|
||||
usePoll (): void {
|
||||
this.muc.add('modules_enabled', 'muc_poll')
|
||||
this.muc.set('poll_groupchat_votes_priority', 1000)
|
||||
}
|
||||
|
||||
addMucAdmins (jids: string[]): void {
|
||||
for (const jid of jids) {
|
||||
this.muc.add('admins', jid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user