summaryrefslogtreecommitdiff
path: root/classes/Notice.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-01-21 21:53:02 -0500
committerEvan Prodromou <evan@controlyourself.ca>2009-01-21 21:53:02 -0500
commitfca1ccc351138abfaf060d01808e9e102d5a9b6d (patch)
tree5afb8043aeec0987dd841f071dbe95deb29ab83f /classes/Notice.php
parentfc90dd44b73d3bae7cf5f986fb70dd90752cd1b0 (diff)
First pass at delivery of group messages
A first pass at the delivery of group messages.
Diffstat (limited to 'classes/Notice.php')
-rw-r--r--classes/Notice.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 3eb653066..16fbf0c17 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -158,6 +158,7 @@ class Notice extends Memcached_DataObject
common_save_replies($notice);
$notice->saveTags();
+ $notice->saveGroups();
# Clear the cache for subscribed users, so they'll update at next request
# XXX: someone clever could prepend instead of clearing the cache
@@ -195,6 +196,26 @@ class Notice extends Memcached_DataObject
$this->blowRepliesCache($blowLast);
$this->blowPublicCache($blowLast);
$this->blowTagCache($blowLast);
+ $this->blowGroupCache($blowLast);
+ }
+
+ function blowGroupCache($blowLast=false)
+ {
+ $cache = common_memcache();
+ if ($cache) {
+ $group_inbox = new Group_inbox();
+ $group_inbox->notice_id = $this->id;
+ if ($group_inbox->find()) {
+ while ($group_inbox->fetch()) {
+ $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id.';last'));
+ }
+ }
+ }
+ $group_inbox->free();
+ unset($group_inbox);
+ }
}
function blowTagCache($blowLast=false)
@@ -549,5 +570,59 @@ class Notice extends Memcached_DataObject
return;
}
+ function saveGroups()
+ {
+ $enabled = common_config('inboxes', 'enabled');
+ if ($enabled !== true && $enabled !== 'transitional') {
+ return;
+ }
+
+ /* extract all !group */
+ $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/',
+ strtolower($this->content),
+ $match);
+ if (!$count) {
+ return true;
+ }
+
+ $profile = $this->getProfile();
+
+ /* Add them to the database */
+
+ foreach (array_unique($match[1]) as $nickname) {
+ /* XXX: remote groups. */
+ $group = User_group::staticGet('nickname', $nickname);
+
+ if ($profile->isMember($group)) {
+ $gi = new Group_inbox();
+
+ $gi->group_id = $group->id;
+ $gi->notice_id = $this->id;
+ $gi->created = common_sql_now();
+
+ $result = $gi->insert();
+
+ if (!$result) {
+ common_log_db_error($gi, 'INSERT', __FILE__);
+ }
+
+ // FIXME: do this in an offline daemon
+
+ $inbox = new Notice_inbox();
+ $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
+ 'SELECT user.id, ' . $this->id . ', "' . $this->created . '" ' .
+ 'FROM user JOIN user_group ON user.id = user_group.profile_id ' .
+ 'WHERE user_group.group_id = ' . $group->id . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = user.id ' .
+ 'AND notice_id = ' . $this->id . ' )';
+ if ($enabled === 'transitional') {
+ $qry .= ' AND user.inboxed = 1';
+ }
+ $inbox->query($qry);
+ }
+ }
+ }
}