3 class MessageCommand extends Command
7 function __construct($user, $other, $text)
9 parent::__construct($user);
10 $this->other = $other;
14 function handle($channel)
17 $other = $this->getUser($this->other)->getProfile();
18 } catch (CommandException $e) {
20 $profile = $this->getProfile($this->other);
21 } catch (CommandException $f) {
24 // TRANS: Command exception text shown when trying to send a direct message to a remote user (a user not registered at the current server).
25 // TRANS: %s is a remote profile.
26 throw new CommandException(sprintf(_('%s is a remote profile; you can only send direct messages to users on the same server.'), $this->other));
29 $len = mb_strlen($this->text);
32 // TRANS: Command exception text shown when trying to send a direct message to another user without content.
33 $channel->error($this->user, _('No content!'));
37 $this->text = $this->user->shortenLinks($this->text);
39 if (Message::contentTooLong($this->text)) {
40 // XXX: i18n. Needs plural support.
41 // TRANS: Message given if content is too long. %1$sd is used for plural.
42 // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters.
43 $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.',
44 'Message too long - maximum is %1$d characters, you sent %2$d.',
45 Message::maxContent()),
46 Message::maxContent(), mb_strlen($this->text)));
50 if (!$other instanceof Profile) {
51 // TRANS: Error text shown when trying to send a direct message to a user that does not exist.
52 $channel->error($this->user, _('No such user.'));
54 } else if (!$this->user->mutuallySubscribed($other)) {
55 // TRANS: Error text shown when trying to send a direct message to a user without a mutual subscription (each user must be subscribed to the other).
56 $channel->error($this->user, _('You can\'t send a message to this user.'));
58 } else if ($this->user->id == $other->id) {
59 // TRANS: Error text shown when trying to send a direct message to self.
60 $channel->error($this->user, _('Do not send a message to yourself; just say it to yourself quietly instead.'));
64 $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
66 // TRANS: Message given have sent a direct message to another user.
67 // TRANS: %s is the name of the other user.
68 $channel->output($this->user, sprintf(_('Direct message to %s sent.'), $this->other));
69 } catch (Exception $e) {
70 // TRANS: Error text shown sending a direct message fails with an unknown reason.
71 $channel->error($this->user, $e->getMessage());