summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-04-23 10:38:51 +0000
committerEvan Prodromou <evan@controlyourself.ca>2009-04-23 10:38:51 +0000
commita9df5eab100bce97da3e028851d224ea2e9fff80 (patch)
treeb36b93d839ef02137327e3cd0c984eee62f017cb /classes/Notice.php
parent1c0d82de3bb7f75649a017a7d5632a6e070876c2 (diff)
insert into user's inbox at Web time
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php76
1 files changed, 51 insertions, 25 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index ebed0b8af..27b98de1c 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -197,7 +197,9 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->saveGroups();
- if (!common_config('queue', 'enabled')) {
+ if (common_config('queue', 'enabled')) {
+ $notice->addToAuthorInbox();
+ } else {
$notice->addToInboxes();
}
@@ -282,16 +284,8 @@ class Notice extends Memcached_DataObject
{
// Clear the user's cache
$cache = common_memcache();
- if ($cache) {
- $user = User::staticGet($this->profile_id);
- if (!empty($user)) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- if ($blowLast) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
- }
- }
- $user->free();
- unset($user);
+ if (!empty($cache)) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id));
}
$this->blowNoticeCache($blowLast);
$this->blowPublicCache($blowLast);
@@ -665,6 +659,33 @@ class Notice extends Memcached_DataObject
return;
}
+ function addToAuthorInbox()
+ {
+ $enabled = common_config('inboxes', 'enabled');
+
+ if ($enabled === true || $enabled === 'transitional') {
+ $user = User::staticGet('id', $this->profile_id);
+ if (empty($user)) {
+ return;
+ }
+ $inbox = new Notice_inbox();
+ $UT = common_config('db','type')=='pgsql'?'"user"':'user';
+ $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
+ "SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
+ "FROM $UT " .
+ "WHERE $UT.id = " . $this->profile_id . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ "WHERE user_id = " . $this->profile_id . ' '.
+ 'AND notice_id = ' . $this->id . ' )';
+ if ($enabled === 'transitional') {
+ $qry .= " AND $UT.inboxed = 1";
+ }
+ $inbox->query($qry);
+ }
+ return;
+ }
+
function saveGroups()
{
$enabled = common_config('inboxes', 'enabled');
@@ -717,24 +738,29 @@ class Notice extends Memcached_DataObject
// FIXME: do this in an offline daemon
- $inbox = new Notice_inbox();
- $UT = common_config('db','type')=='pgsql'?'"user"':'user';
- $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
- "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
- "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
- 'WHERE group_member.group_id = ' . $group->id . ' ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- "WHERE user_id = $UT.id " .
- 'AND notice_id = ' . $this->id . ' )';
- if ($enabled === 'transitional') {
- $qry .= " AND $UT.inboxed = 1";
- }
- $result = $inbox->query($qry);
+ $this->addToGroupInboxes($group);
}
}
}
+ function addToGroupInboxes($group)
+ {
+ $inbox = new Notice_inbox();
+ $UT = common_config('db','type')=='pgsql'?'"user"':'user';
+ $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
+ "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
+ "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
+ 'WHERE group_member.group_id = ' . $group->id . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ "WHERE user_id = $UT.id " .
+ 'AND notice_id = ' . $this->id . ' )';
+ if ($enabled === 'transitional') {
+ $qry .= " AND $UT.inboxed = 1";
+ }
+ $result = $inbox->query($qry);
+ }
+
function saveReplies()
{
// Alternative reply format