From 2dd81d9a5c448ff438545df3405ff319b34169b2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 Apr 2011 18:20:54 -0400 Subject: [PATCH] add a threading notice stream class --- lib/threadingnoticestream.php | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/threadingnoticestream.php diff --git a/lib/threadingnoticestream.php b/lib/threadingnoticestream.php new file mode 100644 index 0000000000..c4b35f4092 --- /dev/null +++ b/lib/threadingnoticestream.php @@ -0,0 +1,70 @@ +. + * + * @category Notice stream + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + // This check helps protect against security problems; + // your code file can't be executed directly from the web. + exit(1); +} + +/** + * This notice stream filters notices by whether their conversation + * has been seen before. It's a good (well, OK) way to get streams + * for a ThreadedNoticeList display. + * + * @category Notice stream + * @package StatusNet + * @author Evan Prodromou + * @copyright 2011 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 + * @link http://status.net/ + */ + +class ThreadingNoticeStream extends FilteringNoticeStream +{ + protected $seen = array(); + + function getNotices($offset, $limit, $sinceId=null, $maxId=null) + { + // Clear this each time we're called + $this->seen = array(); + return parent::getNotices($offset, $limit, $sinceId, $maxId); + } + + function filter($notice) + { + if (!array_key_exists($notice->id, $this->seen)) { + $this->seen[$notice->id] = true; + return true; + } else { + return false; + } + } +}