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; + } + } +}