Browse Source

adding class version of join org module

Luke Miller 2 years ago
parent
commit
db43df6ce2
4 changed files with 42 additions and 10 deletions
  1. 1 0
      modpol/api.lua
  2. 15 0
      modpol/modules/join_org.lua
  3. 18 9
      modpol/modules/join_org_class.lua
  4. 8 1
      modpol/tests/new_module_test.lua

+ 1 - 0
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")

+ 15 - 0
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
 

+ 18 - 9
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")
+modpol.modules.join_org_class = JoinOrg

+ 8 - 1
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)
+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)