123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- class MessageCommand extends Command
- {
- var $other = null;
- var $text = null;
- function __construct($user, $other, $text)
- {
- parent::__construct($user);
- $this->other = $other;
- $this->text = $text;
- }
- function handle($channel)
- {
- try {
- $other = $this->getUser($this->other)->getProfile();
- } catch (CommandException $e) {
- try {
- $profile = $this->getProfile($this->other);
- } catch (CommandException $f) {
- throw $e;
- }
-
-
- throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
- }
- $len = mb_strlen($this->text);
- if ($len == 0) {
-
- $channel->error($this->user, _('No content!'));
- return;
- }
- $this->text = $this->user->shortenLinks($this->text);
- if (Message::contentTooLong($this->text)) {
-
-
-
- $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.',
- 'Message too long - maximum is %1$d characters, you sent %2$d.',
- Message::maxContent()),
- Message::maxContent(), mb_strlen($this->text)));
- return;
- }
- if (!$other instanceof Profile) {
-
- $channel->error($this->user, _('No such user.'));
- return;
- } else if (!$this->user->mutuallySubscribed($other)) {
-
- $channel->error($this->user, _('You can\'t send a message to this user.'));
- return;
- } else if ($this->user->id == $other->id) {
-
- $channel->error($this->user, _('Do not send a message to yourself; just say it to yourself quietly instead.'));
- return;
- }
- try {
- $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
- $message->notify();
-
-
- $channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
- } catch (Exception $e) {
-
- $channel->error($this->user, $e->getMessage());
- }
- }
- }
|