| | 121 | elsif ($stanza->isa('DJabberd::Presence')) { |
|---|
| | 122 | # Most presence-related stuff is handled by the server itself, However, we still |
|---|
| | 123 | # need to handle presence subscription requests. |
|---|
| | 124 | my $type = $stanza->attr('{}type'); |
|---|
| | 125 | |
|---|
| | 126 | if ($type eq 'subscribe') { |
|---|
| | 127 | $logger->debug("Accepting presence subscripton request from ", $stanza->from_jid->as_string); |
|---|
| | 128 | my $response = DJabberd::Presence->new('jabber:client', 'presence', { |
|---|
| | 129 | '{}type' => 'chat', |
|---|
| | 130 | '{}to' => $stanza->from_jid->as_string, |
|---|
| | 131 | '{}type' => 'subscribed', |
|---|
| | 132 | }, []); |
|---|
| | 133 | $self->send_stanza_as_client($response); |
|---|
| | 134 | } |
|---|
| | 135 | |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | } |
|---|
| | 139 | |
|---|
| | 140 | # Since DJabberd::Bot is acting like a client, it must deliver messages using |
|---|
| | 141 | # this method which does the same thing as a DJabberd::Connection::ClientIn would |
|---|
| | 142 | # do if a stanza was recieved from a real client. |
|---|
| | 143 | sub send_stanza_as_client { |
|---|
| | 144 | my ($self, $stanza) = @_; |
|---|
| | 145 | $self->vhost->hook_chain_fast( |
|---|
| | 146 | "filter_incoming_client", |
|---|
| | 147 | [ $stanza, $self ], |
|---|
| | 148 | { |
|---|
| | 149 | reject => sub { }, # just stops the chain |
|---|
| | 150 | }, |
|---|
| | 151 | \&filter_incoming_client_builtin, |
|---|
| | 152 | ); |
|---|
| | 153 | } |
|---|
| | 154 | sub filter_incoming_client_builtin { |
|---|
| | 155 | my ($vhost, $cb, $stanza, $self) = @_; |
|---|
| | 156 | |
|---|
| | 157 | # if no from, we set our own |
|---|
| | 158 | if (! $stanza->from_jid) { |
|---|
| | 159 | my $bj = $self->jid; |
|---|
| | 160 | $stanza->set_from($bj->as_string) if $bj; |
|---|
| | 161 | } |
|---|
| | 162 | |
|---|
| | 163 | $vhost->hook_chain_fast( |
|---|
| | 164 | "switch_incoming_client", |
|---|
| | 165 | [ $stanza ], |
|---|
| | 166 | { |
|---|
| | 167 | process => sub { }, # Do nothing, because we don't actually have a $conn object to pass into $stanza->process |
|---|
| | 168 | deliver => sub { $stanza->deliver($vhost) }, |
|---|
| | 169 | }, |
|---|
| | 170 | sub { |
|---|
| | 171 | $stanza->on_recv_from_client($self); |
|---|
| | 172 | }, |
|---|
| | 173 | ); |
|---|