class Twitapidirect_messagesAction extends TwitterapiAction {
- function is_readonly() {
-
- static $write_methods = array( 'direct_messages',
- 'sent');
-
- $cmdtext = explode('.', $this->arg('method'));
-
- if (in_array($cmdtext[0], $write_methods)) {
- return false;
- }
-
- return true;
- }
-
function direct_messages($args, $apidata) {
parent::handle($args);
return $this->show_messages($args, $apidata, 'received');
$count = $this->arg('count');
$since = $this->arg('since');
$since_id = $this->arg('since_id');
+ $before_id = $this->arg('before_id');
+
$page = $this->arg('page');
if (!$page) {
$link = $server . $user->nickname . '/outbox';
}
+ if ($before_id) {
+ $message->whereAdd("id < $before_id");
+ }
+
+ if ($since_id) {
+ $message->whereAdd("id > $since_id");
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ if ($since) {
+ $d = date('Y-m-d H:i:s', $since);
+ $message->whereAdd("created > '$d'");
+ }
+
$message->orderBy('created DESC, id DESC');
$message->limit((($page-1)*20), $count);
$message->find();
common_user_error(_('API method not found!'), $code = 404);
}
- exit();
}
// had to change this from "new" to "create" to avoid PHP reserved word
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
- exit();
+ return;
}
$user = $apidata['user'];
- $source = $this->trimmed('source'); // Not supported by Twitter.
+ $source = $this->trimmed('source'); // Not supported by Twitter.
- if (!$source) {
+ $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
+ if (!$source || in_array($source, $reserved_sources)) {
$source = 'api';
}
if (!$content) {
$this->client_error(_('No message text!'), $code = 406, $apidata['content-type']);
- } else if (mb_strlen($status) > 140) {
- $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
- $code = 406, $apidata['content-type']);
- exit();
+ } else {
+ $content_shortened = common_shorten_links($content);
+ if (mb_strlen($content_shortened) > 140) {
+ $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
+ $code = 406, $apidata['content-type']);
+ return;
+ }
}
- common_debug($this->trimmed('user'));
-
$other = $this->get_user($this->trimmed('user'));
if (!$other) {
$this->client_error(_('Recipient user not found.'), $code = 403, $apidata['content-type']);
- exit();
+ return;
} else if (!$user->mutuallySubscribed($other)) {
$this->client_error(_('Can\'t send direct messages to users who aren\'t your friend.'),
$code = 403, $apidata['content-type']);
- exit();
+ return;
} else if ($user->id == $other->id) {
// Sending msgs to yourself is allowed by Twitter
$this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'),
$code = 403, $apidata['content-type']);
- exit();
+ return;
}
- $message = Message::saveNew($user->id, $other->id, $content, $source);
+ $message = Message::saveNew($user->id, $other->id,
+ html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
if (is_string($message)) {
$this->server_error($message);
- exit();
+ return;
}
$this->notify($user, $other, $message);
$this->show_single_json_dmsg($message);
}
- exit();
}
function destroy($args, $apidata) {
parent::handle($args);
common_server_error(_('API method under construction.'), $code=501);
- exit();
}
function show_xml_dmsgs($message) {
}
}
- $this->show_twitter_json_dmsgs($dmsgs);
+ $this->show_json_objects($dmsgs);
$this->end_document('json');
}
# XXX: Jabber, SMS notifications... probably queued
}
-}
\ No newline at end of file
+}