try {
$conn->connect(true); // true = persistent connection
} catch (XMPPHP_Exception $e) {
- common_log(LOG_ERROR, $e->getMessage());
+ common_log(LOG_ERR, $e->getMessage());
return false;
}
function jabber_format_entry($profile, $notice)
{
- // FIXME: notice url might be remote
-
- $noticeurl = common_local_url('shownotice',
- array('notice' => $notice->id));
-
- $msg = jabber_format_notice($profile, $notice);
-
- $self_url = common_local_url('userrss', array('nickname' => $profile->nickname));
-
- $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n";
- $entry .= "<source>\n";
- $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
- $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n";
- $entry .= "<link rel='self' type='application/rss+xml' href='" . $self_url . "'/>\n";
- $entry .= "<author><name>" . $profile->nickname . "</name></author>\n";
- $entry .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
- $entry .= "</source>\n";
- $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n";
- $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
- $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
- $entry .= "<id>". $notice->uri . "</id>\n";
- $entry .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
- $entry .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
- $entry .= "</entry>\n";
-
- $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n";
- $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n";
- $html .= "<a href='".htmlspecialchars($profile->profileurl)."'>".$profile->nickname."</a>: ";
- $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice);
- $html .= "\n</body>\n";
- $html .= "\n</html>\n";
-
- $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
- $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n";
- $address .= "</addresses>\n";
-
- // FIXME: include a pubsub event, too.
-
- return $html . $entry . $address;
+ $entry = $notice->asAtomEntry(true, true);
+
+ $xs = new XMLStringer();
+ $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
+ $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
+ $xs->element('a', array('href' => $profile->profileurl),
+ $profile->nickname);
+ $xs->text(": ");
+ if (!empty($notice->rendered)) {
+ $xs->raw($notice->rendered);
+ } else {
+ $xs->raw(common_render_content($notice->content, $notice));
+ }
+ $xs->elementEnd('body');
+ $xs->elementEnd('html');
+
+ $html = $xs->getString();
+
+ return $html . ' ' . $entry;
}
/**
// First, get users to whom this is a direct reply
$user = new User();
- $user->query('SELECT user.id, user.jabber ' .
- 'FROM user JOIN reply ON user.id = reply.profile_id ' .
+ $UT = common_config('db','type')=='pgsql'?'"user"':'user';
+ $user->query("SELECT $UT.id, $UT.jabber " .
+ "FROM $UT JOIN reply ON $UT.id = reply.profile_id " .
'WHERE reply.notice_id = ' . $notice->id . ' ' .
- 'AND user.jabber is not null ' .
- 'AND user.jabbernotify = 1 ' .
- 'AND user.jabberreplies = 1 ');
+ "AND $UT.jabber is not null " .
+ "AND $UT.jabbernotify = 1 " .
+ "AND $UT.jabberreplies = 1 ");
while ($user->fetch()) {
common_log(LOG_INFO,
// Now, get users subscribed to this profile
$user = new User();
- $user->query('SELECT user.id, user.jabber ' .
- 'FROM user JOIN subscription ' .
- 'ON user.id = subscription.subscriber ' .
+ $user->query("SELECT $UT.id, $UT.jabber " .
+ "FROM $UT JOIN subscription " .
+ "ON $UT.id = subscription.subscriber " .
'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' .
- 'AND user.jabber is not null ' .
- 'AND user.jabbernotify = 1 ' .
+ "AND $UT.jabber is not null " .
+ "AND $UT.jabbernotify = 1 " .
'AND subscription.jabber = 1 ');
while ($user->fetch()) {
// To keep the incoming queue from filling up,
// we service it after each send.
$conn->processTime(0);
+ $sent_to[$user->id] = 1;
+ }
+ }
+
+ // Now, get users who have it in their inbox because of groups
+
+ $user = new User();
+ $user->query("SELECT $UT.id, $UT.jabber " .
+ "FROM $UT JOIN notice_inbox " .
+ "ON $UT.id = notice_inbox.user_id " .
+ 'WHERE notice_inbox.notice_id = ' . $notice->id . ' ' .
+ 'AND notice_inbox.source = 2 ' .
+ "AND $UT.jabber is not null " .
+ "AND $UT.jabbernotify = 1 ");
+
+ while ($user->fetch()) {
+ if (!array_key_exists($user->id, $sent_to)) {
+ common_log(LOG_INFO,
+ 'Sending notice ' . $notice->id . ' to ' . $user->jabber,
+ __FILE__);
+ $conn->message($user->jabber, $msg, 'chat', null, $entry);
+ // To keep the incoming queue from filling up,
+ // we service it after each send.
+ $conn->processTime(0);
+ $sent_to[$user->id] = 1;
}
}