XMPP::UserAvatar
UserAvatar is a high-level client for XEP-0084 - User Avatar and XEP-0398 - User Avatar to vCard-Based Avatars.
Avatars are published to two PEP nodes: a "urn:xmpp:avatar:data" node holding the base64 image bytes and a "urn:xmpp:avatar:metadata" node describing the formats (size, MIME type, and an id hashing the image). Subscribers that receive the metadata fetch the data only if it differs from what they already hold. XEP-0398 bridges this to the legacy vCard-based avatar (XEP-0153) by converting between AvatarData and a vCard PHOTO.
avatar = XMPP::UserAvatar.new(client) avatar.publish(base64_bytes, "image/png", 2048, width: 64, height: 64) avatar.subscribe("juliet@capulet.lit")
client.on("message") do |s, p| if metadata = XMPP::UserAvatar.metadata_from_message(p.as(XMPP::Stanza::Message)) metadata.infos.first.try(&.id) # fetch the matching data node end end
See: https://xmpp.org/extensions/xep-0084.html and https://xmpp.org/extensions/xep-0398.html
Constants
The PEP node that holds the avatar image bytes.
The PEP node that describes the avatar formats.
Constructors
Class methods
avatar_from_photo converts a vCard PHOTO into an AvatarData payload, per XEP-0398 §3.
metadata_from_message extracts avatar metadata from a PEP notification message, or nil when the message does not carry one.
Instance methods
publish stores an avatar image on the client's data and metadata PEP nodes. data is the base64-encoded image, type its MIME type, and bytes the decoded size in bytes. id hashes the image (defaults to the hex SHA-1 of the base64 text).