changeset 5781:cb25d341745f

mod_http_admin_api: Return avatar metadata from get_user_info()
author Matthew Wild <mwild1@gmail.com>
date Thu, 07 Dec 2023 15:30:01 +0000
parents f199bff16f1f
children 5621dece3ee4
files mod_http_admin_api/mod_http_admin_api.lua
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_admin_api/mod_http_admin_api.lua	Thu Dec 07 13:02:36 2023 +0000
+++ b/mod_http_admin_api/mod_http_admin_api.lua	Thu Dec 07 15:30:01 2023 +0000
@@ -175,6 +175,27 @@
 	return 200;
 end
 
+local function get_user_avatar_info(username)
+	local pep_service = mod_pep.get_pep_service(username);
+	local ok, _, avatar_item = pep_service:get_last_item("urn:xmpp:avatar:metadata", true);
+	avatar_item = avatar_item and avatar_item:get_child("metadata", "urn:xmpp:avatar:metadata");
+	if not ok or not avatar_item then return; end
+
+	local avatar_info = {};
+
+	for avatar in avatar_item:childtags("info") do
+		table.insert(avatar_info, {
+			bytes = tonumber(avatar.attr.bytes);
+			hash = avatar.attr.id;
+			type = avatar.attr.type;
+			width = tonumber(avatar.attr.width);
+			height = tonumber(avatar.attr.height);
+		});
+	end
+
+	return avatar_info;
+end
+
 local function get_user_info(username)
 	if not usermanager.user_exists(username, module.host) then
 		return nil;
@@ -214,6 +235,7 @@
 		enabled = enabled;
 		last_active = mod_lastlog2.get_last_active(username);
 		deletion_request = deleted_users:get(username);
+		avatar_info = get_user_avatar_info(username);
 	};
 end