]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Notice_inbox.php
Merge branch 'master' of git@gitorious.org:laconica/mainline
[quix0rs-gnu-social.git] / classes / Notice_inbox.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, Control Yourself, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
23
24 // We keep 5 pages of inbox notices in memcache, +1 for pagination check
25
26 define('INBOX_CACHE_WINDOW', 101);
27
28 define('NOTICE_INBOX_SOURCE_SUB', 1);
29 define('NOTICE_INBOX_SOURCE_GROUP', 2);
30 define('NOTICE_INBOX_SOURCE_REPLY', 3);
31 define('NOTICE_INBOX_SOURCE_GATEWAY', -1);
32
33 class Notice_inbox extends Memcached_DataObject
34 {
35     ###START_AUTOCODE
36     /* the code below is auto generated do not remove the above tag */
37
38     public $__table = 'notice_inbox';                    // table name
39     public $user_id;                         // int(4)  primary_key not_null
40     public $notice_id;                       // int(4)  primary_key not_null
41     public $created;                         // datetime()   not_null
42     public $source;                          // tinyint(1)   default_1
43
44     /* Static get */
45     function staticGet($k,$v=null)
46     { return Memcached_DataObject::staticGet('Notice_inbox',$k,$v); }
47
48     /* the code above is auto generated do not remove the tag below */
49     ###END_AUTOCODE
50
51     function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
52     {
53         return Notice::stream(array('Notice_inbox', '_streamDirect'),
54                               array($user_id, $own),
55                               ($own) ? 'notice_inbox:by_user:'.$user_id :
56                               'notice_inbox:by_user_own:'.$user_id,
57                               $offset, $limit, $since_id, $max_id, $since);
58     }
59
60     function _streamDirect($user_id, $own, $offset, $limit, $since_id, $max_id, $since)
61     {
62         $inbox = new Notice_inbox();
63
64         $inbox->user_id = $user_id;
65
66         if (!$own) {
67             $inbox->whereAdd('source != ' . NOTICE_INBOX_SOURCE_GATEWAY);
68         }
69
70         if ($since_id != 0) {
71             $inbox->whereAdd('notice_id > ' . $since_id);
72         }
73
74         if ($max_id != 0) {
75             $inbox->whereAdd('notice_id <= ' . $max_id);
76         }
77
78         if (!is_null($since)) {
79             $inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
80         }
81
82         $inbox->orderBy('notice_id DESC');
83
84         if (!is_null($offset)) {
85             $inbox->limit($offset, $limit);
86         }
87
88         $ids = array();
89
90         if ($inbox->find()) {
91             while ($inbox->fetch()) {
92                 $ids[] = $inbox->notice_id;
93             }
94         }
95
96         return $ids;
97     }
98
99     function &pkeyGet($kv)
100     {
101         return Memcached_DataObject::pkeyGet('Notice_inbox', $kv);
102     }
103 }