1 package Thrasher
::Plugin
::PEPAvatar
;
9 Thrasher::Plugin::PEPAvatar - implement PEP-based avatars, based on
10 whether or not the server supports PEP, with an easy interface for the
11 protocols to set avatars.
15 This module uses ::PEP to advertise avatars in accordance with
16 XEP-0084. The intent is to expose a single function for a protocol
17 to support avatar setting, and to allow this module to do the rest.
19 So far, I've not actually figured out if I'm missing something, or
20 if none of the clients I use actually supports this. Might be
21 missing some features?
25 use Thrasher
::Log
qw(log);
26 use Thrasher
::Constants
qw(:all);
27 use Thrasher
::Callbacks
qw(:all);
28 use Thrasher
::Plugin
qw(:all);
29 use Thrasher
::Plugin
::PEP
qw(pep_publish);
30 use Carp
qw(longmess);
32 use Digest
::SHA1
qw(sha1_hex);
34 # Regardless of the server's support for PEP, we support PEP avatars
35 register_plugin
({features
=> [$NS_PEP_AVATAR,
36 $NS_PEP_AVATAR_METADATA],
37 callbacks
=> {avatar_changed
=> {PEPAvatar
=> \
&avatar_update
}}});
40 my $component = shift;
42 my $legacy_jid = shift;
43 my $raw_binary_data = shift;
44 my $base64_data = shift;
47 my $avatar_atts = image_atts_except_id
($image);
48 $avatar_atts->{id
} = sha1_hex
($raw_binary_data);
50 pep_publish
($component, $legacy_jid, $NS_PEP_AVATAR_METADATA,
51 [[[$NS_PEP_AVATAR_METADATA, 'info'],
54 [[$NS_PEP_AVATAR_METADATA, 'item'],
55 {id
=> $avatar_atts->{id
}},
57 [[$NS_PEP_AVATAR_METADATA, 'metadata'], {},
58 [[[$NS_PEP_AVATAR_METADATA, 'info'],
64 pep_publish
($component, $legacy_jid, $NS_PEP_AVATAR,
65 [[[$NS_PEP_AVATAR, 'items'], {},
66 [[[$NS_PEP_AVATAR, 'item'],
67 {id
=> $avatar_atts->{id
}},
68 [[[$NS_PEP_AVATAR, 'data'], {},
73 sub image_atts_except_id
{
78 bytes
=> $image->Get('filesize'),
79 height
=> $image->Get('base-rows'),
80 width
=> $image->Get('base-columns'),