join_org_class.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. -- JOIN ORG
  2. -- Module that enables a user to join an org
  3. JoinOrg = {}
  4. JoinOrg_mt = { __index = JoinOrg }
  5. function JoinOrg.create(initiator, org)
  6. local inst = {
  7. name = "Join an org",
  8. desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
  9. initiator = initiator,
  10. org = org
  11. }
  12. setmetatable(inst, JoinOrg_mt)
  13. return inst
  14. end
  15. function JoinOrg:initiate(result)
  16. modpol.interactions.binary_poll_user(
  17. self.initiator,
  18. "Would you like to join",
  19. function (resp)
  20. if resp == "Yes" then
  21. modpol.call_module(
  22. "consent",
  23. "",
  24. org,
  25. result
  26. )
  27. modpol.modules.consent(
  28. "Let " .. initiator .. " join " .. org.name .. "?",
  29. org,
  30. params,
  31. self:on_failure,
  32. self:on_success
  33. )
  34. -- for i, member in ipairs(org.members) do
  35. -- org:add_pending_action(
  36. -- member,
  37. -- function ()
  38. -- modpol.interactions.binary_poll_user(
  39. -- member,
  40. -- "Let " .. initiator .. " join " .. org.name .. "?",
  41. -- function (resp)
  42. -- self:vote()
  43. -- end
  44. -- )
  45. -- end
  46. -- )
  47. -- end
  48. end
  49. end
  50. )
  51. if result then result() end
  52. end
  53. function JoinOrg:request()
  54. end
  55. function JoinOrg:on_success()
  56. self.org:add_member(self.initiator)
  57. end
  58. -- ===================================
  59. -- When calling a module internally
  60. modpol.modules.join_org_class = JoinOrg