<?php
/**
* StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011 StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ function multiGet($kc, $kvs, $skipNulls=true)
+ {
+ return Memcached_DataObject::multiGet('Notice', $kc, $kvs, $skipNulls);
+ }
+
/* Notice types */
const LOCAL_PUBLIC = 1;
- const REMOTE_OMB = 0;
+ const REMOTE = 0;
const LOCAL_NONPUBLIC = -1;
const GATEWAY = -2;
* string 'created' timestamp of notice; defaults to now
* int 'is_local' source/gateway ID, one of:
* Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline
- * Notice::REMOTE_OMB - Sent from a remote OMB service;
+ * Notice::REMOTE - Sent from a remote service;
* hide from public timeline but show in
* local "and friends" timelines
* Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
- * Notice::GATEWAY - From another non-OMB service;
+ * Notice::GATEWAY - From another non-OStatus service;
* will not appear in public views
* float 'lat' decimal latitude for geolocation
* float 'lon' decimal longitude for geolocation
if (!empty($reply)) {
$notice->scope = $reply->scope;
} else {
- $notice->scope = common_config('notice', 'defaultscope');
+ $notice->scope = self::defaultScope();
}
} else {
$notice->scope = $scope;
function blowOnInsert($conversation = false)
{
- self::blow('profile:notice_ids:%d', $this->profile_id);
+ $this->blowStream('profile:notice_ids:%d', $this->profile_id);
if ($this->isPublic()) {
- self::blow('public');
+ $this->blowStream('public');
}
// XXX: Before we were blowing the casche only if the notice id
self::blow('conversation::notice_count:%d', $this->conversation);
if (!empty($this->repeat_of)) {
- self::blow('notice:repeats:%d', $this->repeat_of);
+ $this->blowStream('notice:repeats:%d', $this->repeat_of);
}
$original = Notice::staticGet('id', $this->repeat_of);
if (!empty($original)) {
$originalUser = User::staticGet('id', $original->profile_id);
if (!empty($originalUser)) {
- self::blow('user:repeats_of_me:%d', $originalUser->id);
+ $this->blowStream('user:repeats_of_me:%d', $originalUser->id);
}
}
$profile = Profile::staticGet($this->profile_id);
+
if (!empty($profile)) {
$profile->blowNoticeCount();
}
}
}
+ function blowStream()
+ {
+ $c = self::memcache();
+
+ if (empty($c)) {
+ return false;
+ }
+
+ $args = func_get_args();
+
+ $format = array_shift($args);
+
+ $keyPart = vsprintf($format, $args);
+
+ $cacheKey = Cache::key($keyPart);
+
+ $c->delete($cacheKey);
+
+ // delete the "last" stream, too, if this notice is
+ // older than the top of that stream
+
+ $lastKey = $cacheKey.';last';
+
+ $lastStr = $c->get($lastKey);
+
+ if ($lastStr !== false) {
+ $window = explode(',', $lastStr);
+ $lastID = $window[0];
+ $lastNotice = Notice::staticGet('id', $lastID);
+ if (empty($lastNotice) // just weird
+ || strtotime($lastNotice->created) >= strtotime($this->created)) {
+ $c->delete($lastKey);
+ }
+ }
+ }
+
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
} else {
$idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
if ($idstr !== false) {
- $ids = explode(',', $idstr);
+ if (empty($idstr)) {
+ $ids = array();
+ } else {
+ $ids = explode(',', $idstr);
+ }
} else {
$ids = $this->_repeatStreamDirect(100);
$cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
$notice->limit(0, $limit);
}
- $ids = array();
-
- if ($notice->find()) {
- while ($notice->fetch()) {
- $ids[] = $notice->id;
- }
- }
-
- $notice->free();
- $notice = NULL;
-
- return $ids;
+ return $notice->fetchAll('id');
}
function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
$skip = array('_original', '_profile');
return array_diff($vars, $skip);
}
+
+ static function defaultScope()
+ {
+ $scope = common_config('notice', 'defaultscope');
+ if (is_null($scope)) {
+ if (common_config('site', 'private')) {
+ $scope = 1;
+ } else {
+ $scope = 0;
+ }
+ }
+ return $scope;
+ }
}