view mod_nodeinfo2/mod_nodeinfo2.lua @ 3706:36b645e94325

mod_nodeinfo2: Add some TODOs
author Kim Alvefur <zash@zash.se>
date Thu, 10 Oct 2019 16:55:54 +0200
parents 5d3d8b75dee9
children 3248295e1b16
line wrap: on
line source

local json = require "util.json";
local array = require "util.array";

module:depends("http");

local total_users = 0;
for _ in require "core.usermanager".users(module.host) do -- TODO refresh at some interval?
	total_users = total_users + 1;
end

module:provides("http", {
	default_path = "/.well-known/x-nodeinfo2";
	route = {
		GET = function (event)
			event.response.headers.content_type = "application/json";
			return json.encode({
				version = "1.0";
				server = {
					baseUrl = module:http_url("","/");
					name = module.host;
					software = "Prosody";
					version = prosody.version;
				};
				--[[ TODO re-use data from mod_server_contact_info ?
				organization = {
					name = "";
					contact = "";
					account = "";
				};
				--]]
				protocols = array {
					"xmpp",
				};
				--[[ TODO would be cool to identify local transports
				services = {
					inbound = array {
						"irc";
					};
					outbound = array {
					};
				};
				--]]
				openRegistrations = module:get_option_boolean("allow_registration", false);
				usage = {
					users = {
						total = total_users;
						-- TODO how would one calculate these?
						-- activeHalfyear = 1;
						-- activeMonth = 1;
						-- activeWeek = 1;
					};
					-- localPosts = 0;
					-- localComments = 0;
				};
			});
		end;
	}
});