X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fxmppdaemon.php;h=b2efc07c38c644092b4a1549761efb01af99c330;hb=18f4a7eaea3c78cb55db843d77b43db86ac70308;hp=bd1918ca98aa90b8fbe56e2cb29c75c3577bf348;hpb=741eb1a28bbe505364baa440539bbc5ed6fbe5e0;p=quix0rs-gnu-social.git diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index bd1918ca98..b2efc07c38 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -1,8 +1,8 @@ #!/usr/bin/env php resource = common_config('xmpp', 'resource') . 'daemon'; } - $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}"); + $this->jid = $this->user.'@'.$this->server.'/'.$this->resource; + + $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->jid}"); } function connect() @@ -106,8 +108,23 @@ class XMPPDaemon extends Daemon $this->log(LOG_DEBUG, "Beginning processing loop."); - $this->conn->process(); + while ($this->conn->processTime(60)) { + $this->sendPing(); + } + } + } + + function sendPing() + { + if (!isset($this->pingid)) { + $this->pingid = 0; + } else { + $this->pingid++; } + + $this->log(LOG_DEBUG, "Sending ping #{$this->pingid}"); + + $this->conn->send(""); } function handle_reconnect(&$pl) @@ -158,6 +175,10 @@ class XMPPDaemon extends Daemon $user = $this->get_user($from); + // For common_current_user to work + global $_cur; + $_cur = $user; + if (!$user) { $this->from_site($from, 'Unknown user; go to ' . common_local_url('imsettings') . @@ -194,6 +215,7 @@ class XMPPDaemon extends Daemon $user->free(); unset($user); + unset($_cur); unset($pl['xml']); $pl['xml'] = null; @@ -294,17 +316,22 @@ class XMPPDaemon extends Daemon { $body = trim($pl['body']); $content_shortened = common_shorten_links($body); - if (mb_strlen($content_shortened) > 140) { + if (Notice::contentTooLong($content_shortened)) { $from = jabber_normalize_jid($pl['from']); - $this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened)); + $this->from_site($from, sprintf(_("Message too long - maximum is %d characters, you sent %d"), + Notice::maxContent(), + mb_strlen($content_shortened))); return; } - $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); - if (is_string($notice)) { - $this->log(LOG_ERR, $notice); - $this->from_site($user->jabber, $notice); + + try { + $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); + } catch (Exception $e) { + $this->log(LOG_ERR, $e->getMessage()); + $this->from_site($user->jabber, $e->getMessage()); return; } + common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname);