// @fixme we have some cases where things get re-run and so the
// insert fails.
$deleted = Deleted_notice::staticGet('id', $this->id);
+
+ if (!$deleted) {
+ $deleted = Deleted_notice::staticGet('uri', $this->uri);
+ }
+
if (!$deleted) {
$deleted = new Deleted_notice();
$this->clearFaves();
$this->clearTags();
$this->clearGroupInboxes();
+ $this->clearFiles();
// NOTE: we don't clear inboxes
// NOTE: we don't clear queue items
function saveTags()
{
/* extract all #hastags */
- $count = preg_match_all('/(?:^|\s)#([\pL\pN_\-\.]{1,64})/', strtolower($this->content), $match);
+ $count = preg_match_all('/(?:^|\s)#([\pL\pN_\-\.]{1,64})/u', strtolower($this->content), $match);
if (!$count) {
return true;
}
* in place of extracting # tags from content
* array 'urls' list of attached/referred URLs to save with the
* notice in place of extracting links from content
+ * boolean 'distribute' whether to distribute the notice, default true
+ *
* @fixme tag override
*
* @return Notice
$defaults = array('uri' => null,
'url' => null,
'reply_to' => null,
- 'repeat_of' => null);
+ 'repeat_of' => null,
+ 'distribute' => true);
if (!empty($options)) {
$options = $options + $defaults;
$notice->saveUrls();
}
- // Prepare inbox delivery, may be queued to background.
- $notice->distribute();
+ if ($distribute) {
+ // Prepare inbox delivery, may be queued to background.
+ $notice->distribute();
+ }
return $notice;
}
function blowOnInsert($conversation = false)
{
self::blow('profile:notice_ids:%d', $this->profile_id);
- self::blow('public');
+
+ if ($this->isPublic()) {
+ self::blow('public');
+ }
// XXX: Before we were blowing the casche only if the notice id
// was not the root of the conversation. What to do now?
$this->blowOnInsert();
self::blow('profile:notice_ids:%d;last', $this->profile_id);
- self::blow('public;last');
+
+ if ($this->isPublic()) {
+ self::blow('public;last');
+ }
}
/** save all urls in the notice to the db
function getStreamByIds($ids)
{
- $cache = common_memcache();
+ $cache = Cache::instance();
if (!empty($cache)) {
$notices = array();
$c = self::memcache();
if (!empty($c)) {
- $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id));
+ $ni = $c->get(Cache::key('notice:who_gets:'.$this->id));
if ($ni !== false) {
return $ni;
}
// Exclude any deleted, non-local, or blocking recipients.
$profile = $this->getProfile();
+ $originalProfile = null;
+ if ($this->repeat_of) {
+ // Check blocks against the original notice's poster as well.
+ $original = Notice::staticGet('id', $this->repeat_of);
+ if ($original) {
+ $originalProfile = $original->getProfile();
+ }
+ }
foreach ($ni as $id => $source) {
$user = User::staticGet('id', $id);
- if (empty($user) || $user->hasBlocked($profile)) {
+ if (empty($user) || $user->hasBlocked($profile) ||
+ ($originalProfile && $user->hasBlocked($originalProfile))) {
unset($ni[$id]);
}
}
if (!empty($c)) {
// XXX: pack this data better
- $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni);
+ $c->set(Cache::key('notice:who_gets:'.$this->id), $ni);
}
return $ni;
$groups = array();
/* extract all !group */
- $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/',
+ $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/',
strtolower($this->content),
$match);
if (!$count) {
$reply->notice_id = $this->id;
$reply->profile_id = $profile->id;
+ $reply->modified = $this->created;
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id");
$reply->notice_id = $this->id;
$reply->profile_id = $mentioned->id;
+ $reply->modified = $this->created;
$id = $reply->insert();
* Convert a notice into an activity for export.
*
* @param User $cur Current user
- *
+ *
* @return Activity activity object representing this Notice.
*/
- function asActivity()
+ function asActivity($cur)
{
$act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
if (!empty($act)) {
return $act;
}
-
$act = new Activity();
-
+
if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
$profile = $this->getProfile();
-
- $act->actor = ActivityObject::fromProfile($profile);
- $act->verb = ActivityVerb::POST;
- $act->objects[] = ActivityObject::fromNotice($this);
+
+ $act->actor = ActivityObject::fromProfile($profile);
+ $act->actor->extra[] = $profile->profileInfo($cur);
+ $act->verb = ActivityVerb::POST;
+ $act->objects[] = ActivityObject::fromNotice($this);
// XXX: should this be handled by default processing for object entry?
$act->time = strtotime($this->created);
$act->link = $this->bestUrl();
-
+
$act->content = common_xml_safe_str($this->rendered);
$act->id = $this->uri;
$act->title = common_xml_safe_str($this->content);
$act->enclosures[] = $enclosure;
}
}
-
+
$ctx = new ActivityContext();
-
+
if (!empty($this->reply_to)) {
$reply = Notice::staticGet('id', $this->reply_to);
if (!empty($reply)) {
$ctx->replyToUrl = $reply->bestUrl();
}
}
-
+
$ctx->location = $this->getLocation();
-
+
$conv = null;
-
+
if (!empty($this->conversation)) {
$conv = Conversation::staticGet('id', $this->conversation);
if (!empty($conv)) {
$ctx->conversation = $conv->uri;
}
}
-
+
$reply_ids = $this->getReplies();
-
+
foreach ($reply_ids as $id) {
$profile = Profile::staticGet('id', $id);
if (!empty($profile)) {
$ctx->attention[] = $profile->getUri();
}
}
-
+
$groups = $this->getGroups();
-
+
foreach ($groups as $group) {
- $ctx->attention[] = $group->uri;
+ $ctx->attention[] = $group->getUri();
}
// XXX: deprecated; use ActivityVerb::SHARE instead
$ctx->forwardID = $repeat->uri;
$ctx->forwardUrl = $repeat->bestUrl();
}
-
+
$act->context = $ctx;
// Source
if (!empty($atom_feed)) {
$act->source = new ActivitySource();
-
+
// XXX: we should store the actual feed ID
$act->source->id = $atom_feed;
$act->source->links['self'] = $atom_feed;
$act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
-
+
$notice = $profile->getCurrentNotice();
if (!empty($notice)) {
Event::handle('EndNoticeAsActivity', array($this, &$act));
}
-
+
self::cacheSet(Cache::codeKey('notice:as-activity:'.$this->id), $act);
return $act;
function asAtomEntry($namespace=false,
$source=false,
- $author=true,
+ $author=true,
$cur=null)
{
- $act = $this->asActivity();
+ $act = $this->asActivity($cur);
$act->extra[] = $this->noticeInfo($cur);
return $act->asString($namespace, $author, $source);
}
/**
* Extra notice info for atom entries
- *
+ *
* Clients use some extra notice info in the atom stream.
* This gives it to them.
*
function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0)
{
- $cache = common_memcache();
+ $cache = Cache::instance();
if (empty($cache) ||
$since_id != 0 || $max_id != 0 ||
$max_id)));
}
- $idkey = common_cache_key($cachekey);
+ $idkey = Cache::key($cachekey);
$idstr = $cache->get($idkey);
function repeatStream($limit=100)
{
- $cache = common_memcache();
+ $cache = Cache::instance();
if (empty($cache)) {
$ids = $this->_repeatStreamDirect($limit);
} else {
- $idstr = $cache->get(common_cache_key('notice:repeats:'.$this->id));
+ $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
if ($idstr !== false) {
$ids = explode(',', $idstr);
} else {
$ids = $this->_repeatStreamDirect(100);
- $cache->set(common_cache_key('notice:repeats:'.$this->id), implode(',', $ids));
+ $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
}
if ($limit < 100) {
// We do a max of 100, so slice down to limit
$reply->free();
}
+ function clearFiles()
+ {
+ $f2p = new File_to_post();
+
+ $f2p->post_id = $this->id;
+
+ if ($f2p->find()) {
+ while ($f2p->fetch()) {
+ $f2p->delete();
+ }
+ }
+ // FIXME: decide whether to delete File objects
+ // ...and related (actual) files
+ }
+
function clearRepeats()
{
$repeatNotice = new Notice();
if ($tag->find()) {
while ($tag->fetch()) {
- self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, common_keyize($tag->tag));
- self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, common_keyize($tag->tag));
- self::blow('notice_tag:notice_ids:%s', common_keyize($tag->tag));
- self::blow('notice_tag:notice_ids:%s;last', common_keyize($tag->tag));
+ self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, Cache::keyize($tag->tag));
+ self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, Cache::keyize($tag->tag));
+ self::blow('notice_tag:notice_ids:%s', Cache::keyize($tag->tag));
+ self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($tag->tag));
$tag->delete();
}
}
*/
public static function addWhereSinceId(DB_DataObject $obj, $id, $idField='id', $createdField='created')
{
- $since = self::whereSinceId($id);
+ $since = self::whereSinceId($id, $idField, $createdField);
if ($since) {
$obj->whereAdd($since);
}
*/
public static function addWhereMaxId(DB_DataObject $obj, $id, $idField='id', $createdField='created')
{
- $max = self::whereMaxId($id);
+ $max = self::whereMaxId($id, $idField, $createdField);
if ($max) {
$obj->whereAdd($max);
}
}
+
+ function isPublic()
+ {
+ if (common_config('public', 'localonly')) {
+ return ($this->is_local == Notice::LOCAL_PUBLIC);
+ } else {
+ return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
+ ($this->is_local != Notice::GATEWAY));
+ }
+ }
}