From 729c6eef361d93e22f5eeeb0bd1c15e88f22438d Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sat, 9 Nov 2013 01:18:44 +0100 Subject: [PATCH] Inbox class a bit more consistent in argument order and type --- classes/Inbox.php | 10 +++++----- classes/Notice.php | 4 ++-- plugins/TwitterBridge/lib/tweetinqueuehandler.php | 6 +++--- plugins/TwitterBridge/scripts/streamtest.php | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/classes/Inbox.php b/classes/Inbox.php index e584e9e82b..429d2ae02b 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -66,7 +66,7 @@ class Inbox extends Managed_DataObject { * @param int $notice_id * @return boolean success */ - static function insertNotice($user_id, $notice_id) + static function insertNotice(Notice $notice, $user_id) { // Going straight to the DB rather than trusting our caching // during an update. Note: not using DB_DataObject::staticGet, @@ -80,7 +80,7 @@ class Inbox extends Managed_DataObject { } $ids = $inbox->unpack(); - if (in_array(intval($notice_id), $ids)) { + if (in_array(intval($notice->id), $ids)) { // Already in there, we probably re-ran some inbox adds // due to an error. Skip the dupe silently. return true; @@ -90,7 +90,7 @@ class Inbox extends Managed_DataObject { 'SET notice_ids = concat(cast(0x%08x as binary(4)), '. 'SUBSTR(notice_ids, 1, %d)) '. 'WHERE user_id = %d', - $notice_id, + $notice->id, 4 * (self::MAX_NOTICES - 1), $user_id)); @@ -101,11 +101,11 @@ class Inbox extends Managed_DataObject { return $result; } - static function bulkInsert($notice_id, $user_ids) + static function bulkInsert(Notice $notice, array $user_ids) { foreach ($user_ids as $user_id) { - self::insertNotice($user_id, $notice_id); + self::insertNotice($notice, $user_id); } } diff --git a/classes/Notice.php b/classes/Notice.php index 4b0db2988d..f40a4c2111 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1086,7 +1086,7 @@ class Notice extends Managed_DataObject // Bulk insert - Inbox::bulkInsert($this->id, $ids); + Inbox::bulkInsert($this, $ids); return; } @@ -2058,7 +2058,7 @@ class Notice extends Managed_DataObject $user = User::getKV('id', $this->profile_id); if ($user instanceof User) { - Inbox::insertNotice($user->id, $this->id); + Inbox::insertNotice($this, $user->id); } if (common_config('queue', 'inboxes')) { diff --git a/plugins/TwitterBridge/lib/tweetinqueuehandler.php b/plugins/TwitterBridge/lib/tweetinqueuehandler.php index 7f34ade23b..cc4d2f47d4 100644 --- a/plugins/TwitterBridge/lib/tweetinqueuehandler.php +++ b/plugins/TwitterBridge/lib/tweetinqueuehandler.php @@ -50,13 +50,13 @@ class TweetInQueueHandler extends QueueHandler $importer = new TwitterImport(); $notice = $importer->importStatus($status); - if ($notice) { + if ($notice instanceof Notice) { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); - if ($flink) { + if ($flink instanceof Foreign_link) { common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice ". $notice->id." to inbox ".$flink->user_id); // @fixme this should go through more regular channels? - Inbox::insertNotice($flink->user_id, $notice->id); + Inbox::insertNotice($notice, $flink->user_id); }else { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user ".$receiver); } diff --git a/plugins/TwitterBridge/scripts/streamtest.php b/plugins/TwitterBridge/scripts/streamtest.php index 800d8c1e1c..c42fa38f10 100644 --- a/plugins/TwitterBridge/scripts/streamtest.php +++ b/plugins/TwitterBridge/scripts/streamtest.php @@ -170,9 +170,9 @@ $stream->hookEvent('status', function($data, $context) { $importer = new TwitterImport(); printf("\timporting..."); $notice = $importer->importStatus($data); - if ($notice) { + if ($notice instanceof Notice) { global $myuser; - Inbox::insertNotice($myuser->id, $notice->id); + Inbox::insertNotice($notice, $myuser->id); printf(" %s\n", $notice->id); } else { printf(" FAIL\n");