subscribe before sending confirmation message
darcs-hash:20080626064646-34904-d9b9bba1994626cc242e1ed7222762e8e3a90543.gz
This commit is contained in:
parent
9fe45d4158
commit
b560759df1
|
@ -79,27 +79,32 @@ function jabber_send_presence($status=Null, $show='available', $to=Null) {
|
||||||
|
|
||||||
function jabber_confirm_address($code, $nickname, $address) {
|
function jabber_confirm_address($code, $nickname, $address) {
|
||||||
|
|
||||||
# FIXME: do we have to request presence first?
|
# FIXME: above arguments are unused, we start the process with a
|
||||||
|
# subscription
|
||||||
|
# XXX: no idea what we do if the update daemon is already subscribed.
|
||||||
|
|
||||||
$body = "Hey, $nickname.";
|
jabber_special_presence('subscribe', $address);
|
||||||
$body .= "\n\n";
|
|
||||||
$body .= 'Someone just entered this IM address on ';
|
|
||||||
$body .= common_config('site', 'name') . '.';
|
|
||||||
$body .= "\n\n";
|
|
||||||
$body .= 'If it was you, and you want to confirm your entry, ';
|
|
||||||
$body .= 'use the URL below:';
|
|
||||||
$body .= "\n\n";
|
|
||||||
$body .= "\t".common_local_url('confirmaddress',
|
|
||||||
array('code' => $code));
|
|
||||||
$body .= "\n\n";
|
|
||||||
$body .= 'If not, just ignore this message.';
|
|
||||||
$body .= "\n\n";
|
|
||||||
$body .= 'Thanks for your time, ';
|
|
||||||
$body .= "\n";
|
|
||||||
$body .= common_config('site', 'name');
|
|
||||||
$body .= "\n";
|
|
||||||
|
|
||||||
jabber_send_message($address, $body);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function jabber_special_presence($type, $to=NULL, $show=NULL, $status=NULL) {
|
||||||
|
$conn = jabber_connect();
|
||||||
|
|
||||||
|
$to = htmlspecialchars($to);
|
||||||
|
$status = htmlspecialchars($status);
|
||||||
|
$out = "<presence";
|
||||||
|
if($to) $out .= " to='$to'";
|
||||||
|
if($type) $out .= " type='$type'";
|
||||||
|
if($show == 'available' and !$status) {
|
||||||
|
$out .= "/>";
|
||||||
|
} else {
|
||||||
|
$out .= ">";
|
||||||
|
if($show && ($show != 'available')) $out .= "<show>$show</show>";
|
||||||
|
if($status) $out .= "<status>$status</status>";
|
||||||
|
$out .= "</presence>";
|
||||||
|
}
|
||||||
|
$conn->send($out);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jabber_broadcast_notice($notice) {
|
function jabber_broadcast_notice($notice) {
|
||||||
|
|
|
@ -155,6 +155,25 @@ class XMPPDaemon {
|
||||||
|
|
||||||
function handle_presence(&$pl) {
|
function handle_presence(&$pl) {
|
||||||
$from = jabber_normalize_jid($pl['from']);
|
$from = jabber_normalize_jid($pl['from']);
|
||||||
|
switch ($pl['type']) {
|
||||||
|
case 'subscribe':
|
||||||
|
# We let anyone subscribe
|
||||||
|
$this->subscribed($from);
|
||||||
|
break;
|
||||||
|
case 'subscribed':
|
||||||
|
# Are we trying to confirm this address?
|
||||||
|
$confirm = Confirm_address::staticGet('address', $from);
|
||||||
|
if ($confirm) {
|
||||||
|
$this->send_confirmation_code($from, $confirm);
|
||||||
|
}
|
||||||
|
# Otherwise, silently ignore
|
||||||
|
break;
|
||||||
|
case 'unsubscribe':
|
||||||
|
case 'unsubscribed':
|
||||||
|
# XXX: do we care?
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!$pl['type']) {
|
||||||
$user = User::staticGet('jabber', $from);
|
$user = User::staticGet('jabber', $from);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$this->log(LOG_WARNING, 'Message from unknown user ' . $from);
|
$this->log(LOG_WARNING, 'Message from unknown user ' . $from);
|
||||||
|
@ -164,6 +183,9 @@ class XMPPDaemon {
|
||||||
$this->add_notice($user, $pl);
|
$this->add_notice($user, $pl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handle_session(&$pl) {
|
function handle_session(&$pl) {
|
||||||
$this->conn->presence($status="Send me a message to post a notice");
|
$this->conn->presence($status="Send me a message to post a notice");
|
||||||
|
@ -172,6 +194,39 @@ class XMPPDaemon {
|
||||||
function log($level, $msg) {
|
function log($level, $msg) {
|
||||||
common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
|
common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function subscribed($to) {
|
||||||
|
$this->special_presence('subscribed', $to);
|
||||||
|
}
|
||||||
|
|
||||||
|
function special_presence($type, $to=NULL, $show=NULL, $status=NULL) {
|
||||||
|
$to = htmlspecialchars($to);
|
||||||
|
$status = htmlspecialchars($status);
|
||||||
|
$out = "<presence";
|
||||||
|
if($to) $out .= " to='$to'";
|
||||||
|
if($type) $out .= " type='$type'";
|
||||||
|
if($show == 'available' and !$status) {
|
||||||
|
$out .= "/>";
|
||||||
|
} else {
|
||||||
|
$out .= ">";
|
||||||
|
if($show && ($show != 'available')) $out .= "<show>$show</show>";
|
||||||
|
if($status) $out .= "<status>$status</status>";
|
||||||
|
$out .= "</presence>";
|
||||||
|
}
|
||||||
|
$this->conn->send($out);
|
||||||
|
}
|
||||||
|
|
||||||
|
function send_confirmation_code($to, &$confirm) {
|
||||||
|
$body = 'Someone has asked to add this Jabber ID to their ' .
|
||||||
|
'account on ' . common_config('site', 'name') . '. ' .
|
||||||
|
'If it was you, you can confirm by clicking on this URL: ' .
|
||||||
|
common_local_url('confirmaddress', array('code' => $confirm->code)) .
|
||||||
|
' . (If you cannot click it, copy-and-paste it into the ' .
|
||||||
|
'address bar of your browser). If it wasn\'t you, ' .
|
||||||
|
'just ignore this message.';
|
||||||
|
|
||||||
|
$this->conn->message($to, $body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$daemon = new XMPPDaemon();
|
$daemon = new XMPPDaemon();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user