functional test of call_module and new pending action/interact version

This commit is contained in:
Luke Miller
2021-12-06 16:45:52 -05:00
parent 08151ad9d9
commit fa7a0f82f6
5 changed files with 75 additions and 61 deletions

View File

@@ -11,7 +11,8 @@ function JoinOrg.create(initiator, org, id)
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
initiator = initiator,
org = org,
id = id
id = id,
votes_yes = 0
}
setmetatable(inst, JoinOrg_mt)
return inst
@@ -24,63 +25,27 @@ function JoinOrg:initiate(result)
"Would you like to join",
function (resp)
if resp == "Yes" then
modpol.call_module(
"consent",
"",
org,
result
)
modpol.modules.consent(
"Let " .. initiator .. " join " .. org.name .. "?",
org,
params,
self:on_failure,
self:on_success
)
-- for i, member in ipairs(org.members) do
-- org:add_pending_action(
-- member,
-- function ()
-- modpol.interactions.binary_poll_user(
-- member,
-- "Let " .. initiator .. " join " .. org.name .. "?",
-- function (resp)
-- self:vote()
-- end
-- )
-- end
-- )
-- end
for id, member in pairs(self.org.members) do
self.org:add_pending_action(self.id, member, "callback")
end
end
end
)
for user in pairs(self.org.users) {
self.org:add_pending_action(self.id, user, "callback")
org.pending.user[2348] = "callback"
self:callback(user)
}
if result then result() end
end
function JoinOrg:callback(user)
function JoinOrg:callback(member)
modpol.interactions.binary_poll_user(
self.initiator,
"Do you want this" .. self.user_to_add .. "to join?",
member,
"Do you want " .. self.initiator .. " to join?",
function (resp)
if resp == "yes" then
self.votes_yes += 1
if resp == "Yes" then
self.votes_yes = self.votes_yes + 1
end
self:evaluate_vote()
@@ -91,9 +56,12 @@ end
function JoinOrg:on_success()
self.org:add_member(self.initiator)
self.org:delete_process(self.id)
function JoinOrg:evaluate_vote()
if self.votes_yes >= 1 then
print('added user')
self.org:add_member(self.initiator)
self.org:wipe_pending_actions(self.id)
end
end
-- ===================================