Poll WIP (#231):
* mod_muc_poll * feature detection and create poll button in Converse
This commit is contained in:
15
prosody-modules/mod_muc_poll/README.md
Normal file
15
prosody-modules/mod_muc_poll/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
<!--
|
||||
SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
# mod_muc_slow_pool
|
||||
|
||||
This module provide a way to create polls in MUC rooms.
|
||||
|
||||
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
|
||||
|
||||
There will probably be a XEP proposal for this module behaviour. When done, this module will be published in the prosody-modules repository.
|
||||
|
||||
## Configuration
|
||||
|
||||
Just enable the module on your MUC component.
|
70
prosody-modules/mod_muc_poll/mod_muc_poll.lua
Normal file
70
prosody-modules/mod_muc_poll/mod_muc_poll.lua
Normal file
@ -0,0 +1,70 @@
|
||||
local st = require "util.stanza";
|
||||
local dataform = require "util.dataforms";
|
||||
local jid_bare = require "util.jid".bare;
|
||||
|
||||
local mod_muc = module:depends"muc";
|
||||
local get_room_from_jid = mod_muc.get_room_from_jid;
|
||||
|
||||
-- FIXME: create a XEP to standardize this, and remove the "x-".
|
||||
local xmlns_poll = "http://jabber.org/protocol/muc#x-poll";
|
||||
|
||||
local function get_form_layout(room, stanza)
|
||||
local form = dataform.new({
|
||||
title = "New poll",
|
||||
instructions = "Complete and submit this form to create a new poll. This will end and replace any existing poll.",
|
||||
{
|
||||
name = "FORM_TYPE";
|
||||
type = "hidden";
|
||||
value = xmlns_poll;
|
||||
}
|
||||
});
|
||||
|
||||
table.insert(form, {
|
||||
name = "muc#roompoll_question";
|
||||
label = "Question";
|
||||
value = "";
|
||||
});
|
||||
return form;
|
||||
end
|
||||
|
||||
local function send_form(room, origin, stanza)
|
||||
module:log("debug", "Sending the poll form");
|
||||
origin.send(st.reply(stanza):query(xmlns_poll)
|
||||
:add_child(get_form_layout(room, stanza.attr.from):form())
|
||||
) ;
|
||||
end
|
||||
|
||||
-- module:hook("iq/bare", function (event)
|
||||
-- local stanza = event.stanza;
|
||||
-- local type = stanza.attr.type;
|
||||
-- local child = stanza.tags[1];
|
||||
-- local xmlns = child.attr.xmlns or "jabber:client";
|
||||
-- module:log("info", "coucou %s %s %s", type, xmlns, child.name);
|
||||
-- end, 1000);
|
||||
|
||||
-- new poll creation, get form
|
||||
module:hook("iq-get/bare/" .. xmlns_poll .. ":query", function (event)
|
||||
local origin, stanza = event.origin, event.stanza;
|
||||
local room_jid = stanza.attr.to;
|
||||
module:log("debug", "Received a request for the poll form");
|
||||
local room = get_room_from_jid(room_jid);
|
||||
if not room then
|
||||
origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
|
||||
return true;
|
||||
end
|
||||
local from = jid_bare(stanza.attr.from);
|
||||
|
||||
local from_affiliation = room:get_affiliation(from);
|
||||
if (from_affiliation ~= "owner" and from_affiliation ~= "admin") then
|
||||
origin.send(st.error_reply(stanza, "auth", "forbidden"))
|
||||
return true;
|
||||
end
|
||||
|
||||
send_form(room, origin, stanza);
|
||||
return true;
|
||||
end);
|
||||
|
||||
-- Discovering support
|
||||
module:hook("muc-disco#info", function (event)
|
||||
event.reply:tag("feature", { var = xmlns_poll }):up();
|
||||
end);
|
Reference in New Issue
Block a user