mod_nodeinfo2: Only expose message stats if nodeinfo2_expose_posts isn’t set to false
--- a/mod_nodeinfo2/README.markdown Mon Dec 30 12:04:35 2019 +0000
+++ b/mod_nodeinfo2/README.markdown Mon Dec 30 22:20:11 2019 +0100
@@ -22,7 +22,13 @@
}
```
-This module depends on [mod\_http](https://prosody.im/doc/http), all of its
+Set the `nodeinfo2_expose_posts` option to false if you don’t want to expose
+statistics about the amount of messages being exchanged by your users:
+```
+nodeinfo2_expose_posts = false
+```
+
+This module depends on [mod\_http](https://prosody.im/doc/http), most of its
configuration actually happens in this module.
Compatibility
--- a/mod_nodeinfo2/mod_nodeinfo2.lua Mon Dec 30 12:04:35 2019 +0000
+++ b/mod_nodeinfo2/mod_nodeinfo2.lua Mon Dec 30 22:20:11 2019 +0100
@@ -5,7 +5,11 @@
module:depends("http");
module:depends("lastlog");
-module:depends("measure_message_e2ee");
+
+local expose_posts = module:get_option_boolean("nodeinfo2_expose_posts", true);
+if expose_posts then
+ module:depends("measure_message_e2ee");
+end
local main_store = module:open_store();
local lastlog_store = module:open_store("lastlog");
@@ -38,21 +42,38 @@
week_users = nil;
end
-local data = main_store:get("nodeinfo2") or { message_count = 0 };
+local data;
+if expose_posts then
+ data = main_store:get("nodeinfo2") or { message_count = 0 };
+end
module:provides("http", {
default_path = "/.well-known/x-nodeinfo2";
route = {
GET = function (event)
- local stats, changed_only, extras = get_stats();
- for stat, _ in pairs(stats) do
- if stat == "/"..module.host.."/mod_measure_message_e2ee/message:rate" then
- local new_message_count = extras[stat].total;
- if new_message_count ~= data.message_count then
- data = { message_count = new_message_count };
- main_store:set("nodeinfo2", data);
+ local usage = {
+ users = {
+ total = total_users;
+ activeHalfyear = half_year_users;
+ activeMonth = month_users;
+ activeWeek = week_users;
+ };
+ };
+
+ if expose_posts then
+ local stats, changed_only, extras = get_stats();
+ for stat, _ in pairs(stats) do
+ if stat == "/"..module.host.."/mod_measure_message_e2ee/message:rate" then
+ local new_message_count = extras[stat].total;
+ if new_message_count ~= data.message_count then
+ data = { message_count = new_message_count };
+ main_store:set("nodeinfo2", data);
+ end
end
end
+ usage.localPosts = data.message_count;
+ -- TODO: also count PubSub replies here.
+ usage.localComments = 0;
end
event.response.headers.content_type = "application/json";
@@ -84,17 +105,7 @@
};
--]]
openRegistrations = module:get_option_boolean("allow_registration", false);
- usage = {
- users = {
- total = total_users;
- activeHalfyear = half_year_users;
- activeMonth = month_users;
- activeWeek = week_users;
- };
- localPosts = data.message_count;
- -- TODO: also count PubSub replies here.
- localComments = 0;
- };
+ usage = usage;
});
end;
}