join_org_class.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. for user in pairs(self.org.users) {
  53. self.org:add_pending_action(self.id, user, "callback")
  54. org.pending.user[2348] = "callback"
  55. self:callback(user)
  56. }
  57. if result then result() end
  58. end
  59. function JoinOrg:callback(user)
  60. modpol.interactions.binary_poll_user(
  61. self.initiator,
  62. "Do you want this" .. self.user_to_add .. "to join?",
  63. function (resp)
  64. if resp == "yes" then
  65. self.votes_yes += 1
  66. end
  67. self:evaluate_vote()
  68. end
  69. )
  70. end
  71. function JoinOrg:on_success()
  72. self.org:add_member(self.initiator)
  73. self.org:delete_process(self.id)
  74. end
  75. -- ===================================
  76. -- When calling a module internally
  77. modpol.modules.join_org_class = JoinOrg