summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-12 16:00:27 -0500
committerEvan Prodromou <evan@status.net>2009-12-12 16:00:27 -0500
commitcfe67a9c0192129448ea3f0b98aadf49e962fd4d (patch)
tree7079083b93c83af8d4649ca613a88731f5ca8f86 /classes
parent138ce0cd05e2e59c79b29f5eeea5c11d1e56e931 (diff)
add statuses/retweets_of_me to API
Diffstat (limited to 'classes')
-rw-r--r--classes/Notice.php14
-rw-r--r--classes/User.php53
2 files changed, 67 insertions, 0 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 6a701ae0c..eb611f314 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -463,6 +463,20 @@ class Notice extends Memcached_DataObject
$user->free();
unset($user);
}
+
+ $original = Notice::staticGet('id', $this->repeat_of);
+
+ if (!empty($original)) {
+ $originalUser = User::staticGet('id', $original->profile_id);
+ if (!empty($originalUser)) {
+ $ouk = common_cache_key('user:repeats_of_me:'.$originalUser->id);
+ $cache->delete($ouk);
+ $originalUser->free();
+ unset($originalUser);
+ }
+ $original->free();
+ unset($original);
+ }
}
}
}
diff --git a/classes/User.php b/classes/User.php
index 4b7365fc7..b3da448a6 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -793,4 +793,57 @@ class User extends Memcached_DataObject
return $ids;
}
+
+ function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
+ {
+ $ids = Notice::stream(array($this, '_repeatsOfMeDirect'),
+ array(),
+ 'user:repeats_of_me:'.$this->id,
+ $offset, $limit, $since_id, $max_id, null);
+
+ return Notice::getStreamByIds($ids);
+ }
+
+ function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id, $since)
+ {
+ $qry =
+ 'SELECT DISTINCT original.id AS id ' .
+ 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' .
+ 'WHERE original.profile_id = ' . $this->id . ' ';
+
+ if ($since_id != 0) {
+ $qry .= 'AND original.id > ' . $since_id . ' ';
+ }
+
+ if ($max_id != 0) {
+ $qry .= 'AND original.id <= ' . $max_id . ' ';
+ }
+
+ if (!is_null($since)) {
+ $qry .= 'AND original.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
+ }
+
+ // NOTE: we sort by fave time, not by notice time!
+
+ $qry .= 'ORDER BY original.id DESC ';
+
+ if (!is_null($offset)) {
+ $qry .= "LIMIT $limit OFFSET $offset";
+ }
+
+ $ids = array();
+
+ $notice = new Notice();
+
+ $notice->query($qry);
+
+ while ($notice->fetch()) {
+ $ids[] = $notice->id;
+ }
+
+ $notice->free();
+ $notice = NULL;
+
+ return $ids;
+ }
}