X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FInbox.php;h=26b27d2b58f71f47c2e6aa816a6cf668ab46cc3e;hb=663e4e02a1b3b1c104c2c3db19e524a486c3d981;hp=e14d4f4e7eddbb3c2821877d02d61896274e49ce;hpb=1554510c8437f9dcf26d1bc28252549149473e5c;p=quix0rs-gnu-social.git diff --git a/classes/Inbox.php b/classes/Inbox.php index e14d4f4e7e..26b27d2b58 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -56,6 +56,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(); @@ -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); @@ -110,11 +120,7 @@ class Inbox extends Memcached_DataObject $notice_id, $user_id)); if ($result) { - $c = self::memcache(); - - if (!empty($c)) { - $c->delete(self::cacheKey('inbox', 'user_id', $user_id)); - } + self::blow('inbox:user_id:%d', $user_id); } return $result; @@ -133,16 +139,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);