join_org_class.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, id)
  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. id = id
  12. }
  13. setmetatable(inst, JoinOrg_mt)
  14. return inst
  15. end
  16. function JoinOrg:initiate(result)
  17. modpol.interactions.binary_poll_user(
  18. self.initiator,
  19. "Would you like to join",
  20. function (resp)
  21. if resp == "Yes" then
  22. modpol.call_module(
  23. "consent",
  24. "",
  25. org,
  26. result
  27. )
  28. modpol.modules.consent(
  29. "Let " .. initiator .. " join " .. org.name .. "?",
  30. org,
  31. params,
  32. self:on_failure,
  33. self:on_success
  34. )
  35. -- for i, member in ipairs(org.members) do
  36. -- org:add_pending_action(
  37. -- member,
  38. -- function ()
  39. -- modpol.interactions.binary_poll_user(
  40. -- member,
  41. -- "Let " .. initiator .. " join " .. org.name .. "?",
  42. -- function (resp)
  43. -- self:vote()
  44. -- end
  45. -- )
  46. -- end
  47. -- )
  48. -- end
  49. end
  50. end
  51. )
  52. if result then result() end
  53. end
  54. function JoinOrg:request()
  55. end
  56. function JoinOrg:on_success()
  57. self.org:add_member(self.initiator)
  58. self.org:delete_process(self.id)
  59. end
  60. -- ===================================
  61. -- When calling a module internally
  62. modpol.modules.join_org_class = JoinOrg