X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FNotice.php;h=c6ad7d6c4568e912e314da8b4bfd9839d9aa579b;hb=a7ad37f83fcdf611f9a65d38b35ac1874979198c;hp=fdcef1bc2ed6de3e17a82e505abe90b2aeb5eebf;hpb=612a107e09619b92d4614e2f3076ddca5c65824c;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index fdcef1bc2e..c6ad7d6c45 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -34,6 +34,8 @@ define('NOTICE_REMOTE_OMB', 0); define('NOTICE_LOCAL_NONPUBLIC', -1); define('NOTICE_GATEWAY', -2); +define('MAX_BOXCARS', 128); + class Notice extends Memcached_DataObject { ###START_AUTOCODE @@ -72,7 +74,21 @@ class Notice extends Memcached_DataObject $this->blowFavesCache(true); $this->blowSubsCache(true); + // For auditing purposes, save a record that the notice + // was deleted. + + $deleted = new Deleted_notice(); + + $deleted->id = $this->id; + $deleted->profile_id = $this->profile_id; + $deleted->uri = $this->uri; + $deleted->created = $this->created; + $deleted->deleted = common_sql_now(); + $this->query('BEGIN'); + + $deleted->insert(); + //Null any notices that are replies to this notice $this->query(sprintf("UPDATE notice set reply_to = null WHERE reply_to = %d", $this->id)); $related = array('Reply', @@ -221,7 +237,7 @@ class Notice extends Memcached_DataObject $notice->saveTags(); $notice->addToInboxes(); - $notice->saveGroups(); + $notice->saveUrls(); $orig2 = clone($notice); $notice->rendered = common_render_content($final, $notice); @@ -354,6 +370,8 @@ class Notice extends Memcached_DataObject $this->blowTagCache($blowLast); $this->blowGroupCache($blowLast); $this->blowConversationCache($blowLast); + $profile = Profile::staticGet($this->profile_id); + $profile->blowNoticeCount(); } function blowConversationCache($blowLast=false) @@ -793,7 +811,7 @@ class Notice extends Memcached_DataObject $notice->selectAdd(); // clears it $notice->selectAdd('id'); - $notice->whereAdd('conversation = '.$id); + $notice->conversation = $id; $notice->orderBy('id DESC'); @@ -833,14 +851,58 @@ class Notice extends Memcached_DataObject if ($enabled === true || $enabled === 'transitional') { + // XXX: loads constants + + $inbox = new Notice_inbox(); + $users = $this->getSubscribedUsers(); // FIXME: kind of ignoring 'transitional'... // we'll probably stop supporting inboxless mode // in 0.9.x + $ni = array(); + foreach ($users as $id) { - $this->addToUserInbox($id, NOTICE_INBOX_SOURCE_SUB); + $ni[$id] = NOTICE_INBOX_SOURCE_SUB; + } + + $groups = $this->saveGroups(); + + foreach ($groups as $group) { + $users = $group->getUserMembers(); + foreach ($users as $id) { + if (!array_key_exists($id, $ni)) { + $ni[$id] = NOTICE_INBOX_SOURCE_GROUP; + } + } + } + + $cnt = 0; + + $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES '; + $qry = $qryhdr; + + foreach ($ni as $id => $source) { + if ($cnt > 0) { + $qry .= ', '; + } + $qry .= '('.$id.', '.$this->id.', '.$source.', "'.$this->created.'") '; + $cnt++; + if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) { + Notice_inbox::gc($id); + } + if ($cnt >= MAX_BOXCARS) { + $inbox = new Notice_inbox(); + $inbox->query($qry); + $qry = $qryhdr; + $cnt = 0; + } + } + + if ($cnt > 0) { + $inbox = new Notice_inbox(); + $inbox->query($qry); } } @@ -870,27 +932,13 @@ class Notice extends Memcached_DataObject return $ids; } - function addToUserInbox($user_id, $source) - { - $inbox = Notice_inbox::pkeyGet(array('user_id' => $user_id, - 'notice_id' => $this->id)); - if (empty($inbox)) { - $inbox = new Notice_inbox(); - $inbox->user_id = $user_id; - $inbox->notice_id = $this->id; - $inbox->source = $source; - $inbox->created = $this->created; - return $inbox->insert(); - } - - return true; - } - function saveGroups() { + $groups = array(); + $enabled = common_config('inboxes', 'enabled'); if ($enabled !== true && $enabled !== 'transitional') { - return; + return $groups; } /* extract all !group */ @@ -898,7 +946,7 @@ class Notice extends Memcached_DataObject strtolower($this->content), $match); if (!$count) { - return true; + return $groups; } $profile = $this->getProfile(); @@ -930,11 +978,11 @@ class Notice extends Memcached_DataObject common_log_db_error($gi, 'INSERT', __FILE__); } - // FIXME: do this in an offline daemon - - $this->addToGroupMemberInboxes($group); + $groups[] = clone($group); } } + + return $groups; } function addToGroupInbox($group) @@ -956,15 +1004,6 @@ class Notice extends Memcached_DataObject return true; } - function addToGroupMemberInboxes($group) - { - $users = $group->getUserMembers(); - - foreach ($users as $id) { - $this->addToUserInbox($id, NOTICE_INBOX_SOURCE_GROUP); - } - } - function saveReplies() { // Alternative reply format @@ -1144,6 +1183,20 @@ class Notice extends Memcached_DataObject } $tag->free(); + # Enclosures + $attachments = $this->attachments(); + if($attachments){ + foreach($attachments as $attachment){ + if ($attachment->isEnclosure()) { + $attributes = array('rel'=>'enclosure','href'=>$attachment->url,'type'=>$attachment->mimetype,'length'=>$attachment->size); + if($attachment->title){ + $attributes['title']=$attachment->title; + } + $xs->element('link', $attributes, null); + } + } + } + $xs->elementEnd('entry'); return $xs->getString(); @@ -1167,6 +1220,7 @@ class Notice extends Memcached_DataObject if (empty($cache) || $since_id != 0 || $max_id != 0 || (!is_null($since) && $since > 0) || + is_null($limit) || ($offset + $limit) > NOTICE_CACHE_WINDOW) { return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id, $max_id, $since))); @@ -1189,7 +1243,7 @@ class Notice extends Memcached_DataObject $window = explode(',', $laststr); $last_id = $window[0]; $new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, - $last_id, 0, null, $tag))); + $last_id, 0, null))); $new_window = array_merge($new_ids, $window); @@ -1204,7 +1258,7 @@ class Notice extends Memcached_DataObject } $window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW, - 0, 0, null, $tag))); + 0, 0, null))); $windowstr = implode(',', $window);