Added user_dashboard and message_user to modpol_minetest
This commit is contained in:
		| @@ -211,11 +211,8 @@ function modpol.interactions.user_dashboard(viewer, user, completion) | |||||||
|    local sel = io.read() |    local sel = io.read() | ||||||
|  |  | ||||||
|    if sel == "M" or sel == "m" then |    if sel == "M" or sel == "m" then | ||||||
|       print("Enter your message for "..user..":") |  | ||||||
|       sel = io.read() |  | ||||||
|       print("Sending message") |  | ||||||
|       modpol.interactions.message_user( |       modpol.interactions.message_user( | ||||||
|          viewer, user, sel) |          viewer, user) | ||||||
|       completion() |       completion() | ||||||
|    else |    else | ||||||
|       completion() |       completion() | ||||||
| @@ -237,14 +234,15 @@ function modpol.interactions.message(user, message) | |||||||
| end | end | ||||||
|  |  | ||||||
| --- Function: modpol.interactions.message_user | --- Function: modpol.interactions.message_user | ||||||
| -- Sends a message from one user to another | -- Gets and sends a message from one user to another | ||||||
| -- @param sender Name of user sending (string) | -- @param sender Name of user sending (string) | ||||||
| -- @param recipient Name of user receiving (string) | -- @param recipient Name of user receiving (string) | ||||||
| -- @param message Message to be sent (string) | function modpol.interactions.message_user(sender, recipient) | ||||||
| function modpol.interactions.message_user(sender, recipient, message) |    print("Enter your message for "..recipient..":") | ||||||
|  |    local sel = io.read() | ||||||
|    modpol.interactions.message( |    modpol.interactions.message( | ||||||
|       recipient, |       recipient, | ||||||
|       message.." [from "..sender.."]") |       sel.." [from "..sender.."]") | ||||||
| end | end | ||||||
|  |  | ||||||
| --- Function: modpol.interactions.display | --- Function: modpol.interactions.display | ||||||
|   | |||||||
| @@ -90,6 +90,14 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | |||||||
|          elseif fields.refresh then |          elseif fields.refresh then | ||||||
|             modpol.interactions.dashboard(pname) |             modpol.interactions.dashboard(pname) | ||||||
|           -- Put all dropdowns at the end |           -- Put all dropdowns at the end | ||||||
|  |          elseif fields.all_users then | ||||||
|  |             modpol.interactions.user_dashboard( | ||||||
|  |                pname, | ||||||
|  |                fields.all_users, | ||||||
|  |                function() | ||||||
|  |                   modpol.interactions.dashboard(pname) | ||||||
|  |                end | ||||||
|  |             ) | ||||||
|          elseif fields.all_orgs or fields.user_orgs or fields.pending then |          elseif fields.all_orgs or fields.user_orgs or fields.pending then | ||||||
|             local org_name = fields.all_orgs or fields.user_orgs or fields.pending |             local org_name = fields.all_orgs or fields.user_orgs or fields.pending | ||||||
|             modpol.interactions.org_dashboard(pname, org_name) |             modpol.interactions.org_dashboard(pname, org_name) | ||||||
| @@ -169,7 +177,7 @@ function modpol.interactions.org_dashboard(user, org_string) | |||||||
|           minetest.formspec_escape(org.name)..membership_toggle(org.name).."]", |           minetest.formspec_escape(org.name)..membership_toggle(org.name).."]", | ||||||
|        "label[0.5,1;Parent: "..parent..membership_toggle(parent).."]", |        "label[0.5,1;Parent: "..parent..membership_toggle(parent).."]", | ||||||
|        "label[0.5,2;Members:]", |        "label[0.5,2;Members:]", | ||||||
|        "dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(org.members)..";;]", |        "dropdown[2,1.5;7,0.8;members;"..formspec_list(org.members)..";;]", | ||||||
|        "label[0.5,3;Child orgs:]", |        "label[0.5,3;Child orgs:]", | ||||||
|        "dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]", |        "dropdown[2,2.5;7,0.8;children;"..formspec_list(children)..";;]", | ||||||
|        "label[0.5,4;Modules:]", |        "label[0.5,4;Modules:]", | ||||||
| @@ -202,6 +210,15 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | |||||||
|              |              | ||||||
|          -- Put all dropdowns at the end |          -- Put all dropdowns at the end | ||||||
|             -- Receiving modules |             -- Receiving modules | ||||||
|  |          elseif fields.members then | ||||||
|  |             modpol.interactions.user_dashboard( | ||||||
|  |                pname, | ||||||
|  |                fields.members, | ||||||
|  |                function() | ||||||
|  |                   modpol.interactions.org_dashboard( | ||||||
|  |                      pname, org.name) | ||||||
|  |                end | ||||||
|  |             ) | ||||||
|          elseif fields.modules |          elseif fields.modules | ||||||
|             and fields.modules ~= "View..." then |             and fields.modules ~= "View..." then | ||||||
|             local module = nil |             local module = nil | ||||||
| @@ -244,17 +261,60 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) | |||||||
|       end |       end | ||||||
| end) | end) | ||||||
|  |  | ||||||
|  | --- Function: modpol.interactions.user_dashboard | ||||||
|  | -- Displays a dashboard about a particular user | ||||||
|  | -- @param viewer Name of user viewing the dashboard (string) | ||||||
|  | -- @param user Name of user being viewed (string) | ||||||
|  | -- @param completion Optional function to call on Done button | ||||||
|  | function modpol.interactions.user_dashboard(viewer, user, completion) | ||||||
|  |    local user_orgs = modpol.orgs.user_orgs(user) | ||||||
|  |    table.insert(user_orgs,1,"View...") | ||||||
|  |  | ||||||
| -- Function: modpol.interactions.policy_dashboard |    -- set player context | ||||||
| -- input: user (string), org_id (int), policy (string) |    local user_context = {} | ||||||
| -- output: opens a dashboard for viewing/editing policy details |    user_context["viewer"] = viewer | ||||||
| -- TODO |    user_context["user"] = user | ||||||
| function modpol.interactions.policy_dashboard( |    user_context["completion"] = completion | ||||||
|       user, org_id, policy) |    _contexts[viewer] = user_context | ||||||
|    modpol.interactions.message( |    -- set up formspec | ||||||
|       user, |     local formspec = { | ||||||
|       "Not yet implemented: " .. policy) |        "formspec_version[4]", | ||||||
|  |        "size[10,8]", | ||||||
|  |        "label[0.5,0.5;User: "..user.."]", | ||||||
|  |        "label[0.5,2;User's orgs:]", | ||||||
|  |        "dropdown[2,1.5;7,0.8;user_orgs;"..formspec_list(user_orgs)..";;]", | ||||||
|  |        "button[0.5,7;1.5,0.8;message;Message]", | ||||||
|  |        "button_exit[8.5,7;1,0.8;close;Close]", | ||||||
|  |     } | ||||||
|  |     local formspec_string = table.concat(formspec, "") | ||||||
|  |     -- present to player | ||||||
|  |     minetest.show_formspec(viewer, "modpol:user_dashboard", formspec_string) | ||||||
| end | end | ||||||
|  | -- receive input | ||||||
|  | minetest.register_on_player_receive_fields(function (player, formname, fields) | ||||||
|  |       if formname == "modpol:user_dashboard" then | ||||||
|  |          local contexts = _contexts[player:get_player_name()] | ||||||
|  |          -- check fields | ||||||
|  |          if nil then | ||||||
|  |          elseif fields.message then | ||||||
|  |             modpol.interactions.message_user( | ||||||
|  |                contexts.viewer, contexts.user | ||||||
|  |             ) | ||||||
|  |          elseif fields.back then | ||||||
|  |             if contexts.completion then | ||||||
|  |                completion() | ||||||
|  |             else | ||||||
|  |                modpol.interactions.dashboard( | ||||||
|  |                   contexts.viewer) | ||||||
|  |             end | ||||||
|  |          -- dropdown fields | ||||||
|  |          elseif fields.user_orgs | ||||||
|  |             and fields.user_orgs ~= "View..." then | ||||||
|  |             modpol.interactions.org_dashboard( | ||||||
|  |                contexts.viewer, fields.user_orgs) | ||||||
|  |          end | ||||||
|  |       end | ||||||
|  | end) | ||||||
|  |  | ||||||
|  |  | ||||||
| -- INTERACTION PRIMITIVES | -- INTERACTION PRIMITIVES | ||||||
| @@ -271,6 +331,22 @@ function modpol.interactions.message(user, message) | |||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  | --- Function: modpol.interactions.message_user | ||||||
|  | -- Gets and sends a message from one user to another | ||||||
|  | -- @param sender Name of user sending (string) | ||||||
|  | -- @param recipient Name of user receiving (string) | ||||||
|  | function modpol.interactions.message_user(sender, recipient) | ||||||
|  |    modpol.interactions.text_query( | ||||||
|  |       sender, | ||||||
|  |       "Message for "..recipient..":", | ||||||
|  |       function(input) | ||||||
|  |          modpol.interactions.message( | ||||||
|  |             recipient, | ||||||
|  |             input.." [from "..sender.."]") | ||||||
|  |       end | ||||||
|  |    ) | ||||||
|  | end | ||||||
|  |  | ||||||
| --- Function: modpol.interactions.display | --- Function: modpol.interactions.display | ||||||
| -- Displays complex data to a user | -- Displays complex data to a user | ||||||
| -- @param user Name of target user (string) | -- @param user Name of target user (string) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user