diff mod_nodeinfo2/mod_nodeinfo2.lua @ 3707:3248295e1b16

mod_nodeinfo2: Retrieve message count from mod_measure_message_e2ee for localPosts and localComments.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 10 Oct 2019 17:59:32 +0200
parents 36b645e94325
children 0a800463bc08
line wrap: on
line diff
--- a/mod_nodeinfo2/mod_nodeinfo2.lua	Thu Oct 10 16:55:54 2019 +0200
+++ b/mod_nodeinfo2/mod_nodeinfo2.lua	Thu Oct 10 17:59:32 2019 +0200
@@ -1,7 +1,9 @@
 local json = require "util.json";
 local array = require "util.array";
+local get_stats = require "core.statsmanager".get_stats;
 
 module:depends("http");
+module:depends("measure_message_e2ee");
 
 local total_users = 0;
 for _ in require "core.usermanager".users(module.host) do -- TODO refresh at some interval?
@@ -12,6 +14,14 @@
 	default_path = "/.well-known/x-nodeinfo2";
 	route = {
 		GET = function (event)
+			local stats, changed_only, extras = get_stats();
+			local message_count = nil;
+			for stat, value in pairs(stats) do
+				if stat == "/*/mod_measure_message_e2ee/message:rate" then
+					message_count = extras[stat].total;
+				end
+			end
+
 			event.response.headers.content_type = "application/json";
 			return json.encode({
 				version = "1.0";
@@ -49,8 +59,8 @@
 						-- activeMonth = 1;
 						-- activeWeek = 1;
 					};
-					-- localPosts = 0;
-					-- localComments = 0;
+					localPosts = message_count;
+					localComments = message_count;
 				};
 			});
 		end;