thrasherbird.pl: Item disco target config was missing.
[thrasher.git] / perl / lib / Thrasher / Plugin / PEPAvatar.pm
blob6033a3b2f6846e66653169750aa9a671a6381df0
1 package Thrasher::Plugin::PEPAvatar;
2 use strict;
3 use warnings;
5 =pod
7 =head1 NAME
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.
13 =head1 DESCRIPTION
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?
23 =cut
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}}});
39 sub avatar_update {
40 my $component = shift;
41 my $user_jid = shift;
42 my $legacy_jid = shift;
43 my $raw_binary_data = shift;
44 my $base64_data = shift;
45 my $image = 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'],
52 {},
54 [[$NS_PEP_AVATAR_METADATA, 'item'],
55 {id => $avatar_atts->{id}},
57 [[$NS_PEP_AVATAR_METADATA, 'metadata'], {},
58 [[[$NS_PEP_AVATAR_METADATA, 'info'],
59 $avatar_atts, []]]
62 ]]]);
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'], {},
69 [$base64_data]]]]]
70 ]]);
73 sub image_atts_except_id {
74 my $image = shift;
76 my $atts =
78 bytes => $image->Get('filesize'),
79 height => $image->Get('base-rows'),
80 width => $image->Get('base-columns'),
81 type => 'image/png',
84 return $atts;