diff --git a/modpol/api.lua b/modpol/api.lua index d20c88f..5e278ec 100644 --- a/modpol/api.lua +++ b/modpol/api.lua @@ -16,5 +16,6 @@ dofile (localdir .. "/interactions/interactions.lua") --modules dofile (localdir .. "/modules/join_org.lua") +dofile (localdir .. "/modules/join_org_class.lua") dofile (localdir .. "/modules/remove_org.lua") dofile (localdir .. "/modules/child_org.lua") diff --git a/modpol/modules/join_org.lua b/modpol/modules/join_org.lua index a608481..9b20287 100644 --- a/modpol/modules/join_org.lua +++ b/modpol/modules/join_org.lua @@ -12,6 +12,21 @@ function join_org.initiate(initiator, org, result) end ) + -- 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) + + -- end + -- ) + -- end + -- ) + -- end + if result then result() end end diff --git a/modpol/modules/join_org_class.lua b/modpol/modules/join_org_class.lua index ccb29c2..5d8305c 100644 --- a/modpol/modules/join_org_class.lua +++ b/modpol/modules/join_org_class.lua @@ -1,25 +1,35 @@ -- JOIN ORG -- Module that enables a user to join an org -modpol.modules.join_org = {} -module = modpol.modules.join_org - JoinOrg = {} JoinOrg_mt = { __index = JoinOrg } -function JoinOrg:create(initiator, org) +function JoinOrg.create(initiator, org) 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." + desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.", + initiator = initiator, + org = org } setmetatable(inst, JoinOrg_mt) return inst end -function JoinOrg:initiate(initiator, org, result) - modpol.interactions.binary_poll_user(initiator, "Would you like to join", ) +function JoinOrg:initiate(result) + modpol.interactions.binary_poll_user( + self.initiator, + "Would you like to join", + function (resp) + if resp == "Yes" then + self:implement() + end + end + ) + + if result then result() end + end function JoinOrg:request() @@ -33,5 +43,4 @@ end -- =================================== -- When calling a module internally -test = JoinOrg.create() -test:initiate("luke") \ No newline at end of file +modpol.modules.join_org_class = JoinOrg \ No newline at end of file diff --git a/modpol/tests/new_module_test.lua b/modpol/tests/new_module_test.lua index 3a0201f..2f83e9a 100644 --- a/modpol/tests/new_module_test.lua +++ b/modpol/tests/new_module_test.lua @@ -7,4 +7,11 @@ test_org:add_member('nathan') print(table.concat(test_org:list_members(), ", ")) -modpol.modules.join_org.initiate("paul", test_org, function () print("callback") end) \ No newline at end of file +function completion() + print("completed") +end + +-- modpol.modules.join_org.initiate("paul", test_org, completion) + +process = modpol.modules.join_org_class.create("paul", test_org) +process:initiate(completion) \ No newline at end of file