Comparison

plugins/mod_mam/mod_mam.lua @ 8252:63e505578d4f

mod_mam: Also return the preferences on set Fixes #995.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Sep 2017 23:38:08 +0200
parent 8250:9ea5ea53744b
child 8538:3eb4cafb3b64
comparison
equal deleted inserted replaced
8251:cb2d86f4b511 8252:63e505578d4f
65 65
66 -- Handle prefs. 66 -- Handle prefs.
67 module:hook("iq/self/"..xmlns_mam..":prefs", function(event) 67 module:hook("iq/self/"..xmlns_mam..":prefs", function(event)
68 local origin, stanza = event.origin, event.stanza; 68 local origin, stanza = event.origin, event.stanza;
69 local user = origin.username; 69 local user = origin.username;
70 if stanza.attr.type == "get" then 70 if stanza.attr.type == "set" then
71 local prefs = prefs_to_stanza(get_prefs(user));
72 local reply = st.reply(stanza):add_child(prefs);
73 origin.send(reply);
74 else -- type == "set"
75 local new_prefs = stanza:get_child("prefs", xmlns_mam); 71 local new_prefs = stanza:get_child("prefs", xmlns_mam);
76 local prefs = prefs_from_stanza(new_prefs); 72 local prefs = prefs_from_stanza(new_prefs);
77 local ok, err = set_prefs(user, prefs); 73 local ok, err = set_prefs(user, prefs);
78 if not ok then 74 if not ok then
79 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err))); 75 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", "Error storing preferences: "..tostring(err)));
80 else 76 return true;
81 origin.send(st.reply(stanza)); 77 end
82 end 78 end
83 end 79 local prefs = prefs_to_stanza(get_prefs(user));
80 local reply = st.reply(stanza):add_child(prefs);
81 origin.send(reply);
84 return true; 82 return true;
85 end); 83 end);
86 84
87 local query_form = dataform { 85 local query_form = dataform {
88 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; }; 86 { name = "FORM_TYPE"; type = "hidden"; value = xmlns_mam; };