-- JOIN ORG -- Module that enables a user to join an org JoinOrg = {} JoinOrg_mt = { __index = JoinOrg } function JoinOrg.create(initiator, org, id) local inst = { name = "Join an org", 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 } setmetatable(inst, JoinOrg_mt) return inst end function JoinOrg:initiate(result) modpol.interactions.binary_poll_user( self.initiator, "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 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) modpol.interactions.binary_poll_user( self.initiator, "Do you want this" .. self.user_to_add .. "to join?", function (resp) if resp == "yes" then self.votes_yes += 1 end self:evaluate_vote() end ) end function JoinOrg:on_success() self.org:add_member(self.initiator) self.org:delete_process(self.id) end -- =================================== -- When calling a module internally modpol.modules.join_org_class = JoinOrg