summaryrefslogtreecommitdiff
path: root/classes/Inbox.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Inbox.php')
-rw-r--r--classes/Inbox.php51
1 files changed, 40 insertions, 11 deletions
diff --git a/classes/Inbox.php b/classes/Inbox.php
index e14d4f4e7..086dba1c9 100644
--- a/classes/Inbox.php
+++ b/classes/Inbox.php
@@ -57,6 +57,22 @@ class Inbox extends Memcached_DataObject
static function initialize($user_id)
{
+ $inbox = Inbox::fromNoticeInbox($user_id);
+
+ unset($inbox->fake);
+
+ $result = $inbox->insert();
+
+ if (!$result) {
+ common_log_db_error($inbox, 'INSERT', __FILE__);
+ return null;
+ }
+
+ return $inbox;
+ }
+
+ static function fromNoticeInbox($user_id)
+ {
$ids = array();
$ni = new Notice_inbox();
@@ -80,20 +96,14 @@ class Inbox extends Memcached_DataObject
$inbox->user_id = $user_id;
$inbox->notice_ids = call_user_func_array('pack', array_merge(array('N*'), $ids));
-
- $result = $inbox->insert();
-
- if (!$result) {
- common_log_db_error($inbox, 'INSERT', __FILE__);
- return null;
- }
+ $inbox->fake = true;
return $inbox;
}
static function insertNotice($user_id, $notice_id)
{
- $inbox = Inbox::staticGet('user_id', $user_id);
+ $inbox = DB_DataObject::staticGet('inbox', 'user_id', $user_id);
if (empty($inbox)) {
$inbox = Inbox::initialize($user_id);
@@ -133,16 +143,35 @@ class Inbox extends Memcached_DataObject
$inbox = Inbox::staticGet('user_id', $user_id);
if (empty($inbox)) {
- $inbox = Inbox::initialize($user_id);
+ $inbox = Inbox::fromNoticeInbox($user_id);
if (empty($inbox)) {
return array();
+ } else {
+ $inbox->encache();
}
}
$ids = unpack('N*', $inbox->notice_ids);
- // XXX: handle since_id
- // XXX: handle max_id
+ if (!empty($since_id)) {
+ $newids = array();
+ foreach ($ids as $id) {
+ if ($id > $since_id) {
+ $newids[] = $id;
+ }
+ }
+ $ids = $newids;
+ }
+
+ if (!empty($max_id)) {
+ $newids = array();
+ foreach ($ids as $id) {
+ if ($id <= $max_id) {
+ $newids[] = $id;
+ }
+ }
+ $ids = $newids;
+ }
$ids = array_slice($ids, $offset, $limit);