const GROUP_SCOPE = 4;
const FOLLOWER_SCOPE = 8;
+ protected $_profile = -1;
+
function getProfile()
{
- $profile = Profile::staticGet('id', $this->profile_id);
+ if (is_int($this->_profile) && $this->_profile == -1) {
+ $this->_profile = Profile::staticGet('id', $this->profile_id);
- if (empty($profile)) {
- // TRANS: Server exception thrown when a user profile for a notice cannot be found.
- // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number).
- throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id));
+ if (empty($this->_profile)) {
+ // TRANS: Server exception thrown when a user profile for a notice cannot be found.
+ // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number).
+ throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id));
+ }
}
- return $profile;
+ return $this->_profile;
}
function delete()
if (!$id) {
// TRANS: Server exception. %s are the error details.
- throw new ServerException(sprintf(_('Database error inserting hashtag: %s'),
+ throw new ServerException(sprintf(_('Database error inserting hashtag: %s.'),
$last_error->message));
return;
}
$notice->saveKnownGroups($groups);
+ if (isset($peopletags)) {
+ $notice->saveProfileTags($peopletags);
+ } else {
+ $notice->saveProfileTags();
+ }
+
if (isset($urls)) {
$notice->saveKnownUrls($urls);
} else {
}
$users = $this->getSubscribedUsers();
+ $ptags = $this->getProfileTags();
// FIXME: kind of ignoring 'transitional'...
// we'll probably stop supporting inboxless mode
}
}
+ foreach ($ptags as $ptag) {
+ $users = $ptag->getUserSubscribers();
+ foreach ($users as $id) {
+ if (!array_key_exists($id, $ni)) {
+ $user = User::staticGet('id', $id);
+ if (!$user->hasBlocked($profile)) {
+ $ni[$id] = NOTICE_INBOX_SOURCE_PROFILE_TAG;
+ }
+ }
+ }
+ }
+
foreach ($recipients as $recipient) {
if (!array_key_exists($recipient, $ni)) {
$ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY;
}
- }
- // 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();
+ // 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) ||
- ($originalProfile && $user->hasBlocked($originalProfile))) {
- unset($ni[$id]);
+ foreach ($ni as $id => $source) {
+ $user = User::staticGet('id', $id);
+ if (empty($user) || $user->hasBlocked($profile) ||
+ ($originalProfile && $user->hasBlocked($originalProfile))) {
+ unset($ni[$id]);
+ }
}
}
return $ids;
}
+ function getProfileTags()
+ {
+ // Don't save ptags for repeats, for now.
+
+ if (!empty($this->repeat_of)) {
+ return array();
+ }
+
+ // XXX: cache me
+
+ $ptags = array();
+
+ $ptagi = new Profile_tag_inbox();
+
+ $ptagi->selectAdd();
+ $ptagi->selectAdd('profile_tag_id');
+
+ $ptagi->notice_id = $this->id;
+
+ if ($ptagi->find()) {
+ while ($ptagi->fetch()) {
+ $profile_list = Profile_list::staticGet('id', $ptagi->profile_tag_id);
+ if ($profile_list) {
+ $ptags[] = $profile_list;
+ }
+ }
+ }
+
+ $ptagi->free();
+
+ return $ptags;
+ }
+
/**
* Record this notice to the given group inboxes for delivery.
* Overrides the regular parsing of !group markup.
return true;
}
+ /**
+ * record targets into profile_tag_inbox.
+ * @return array of Profile_list objects
+ */
+ function saveProfileTags($known=array())
+ {
+ // Don't save ptags for repeats, for now
+
+ if (!empty($this->repeat_of)) {
+ return array();
+ }
+
+ if (is_array($known)) {
+ $ptags = $known;
+ } else {
+ $ptags = array();
+ }
+
+ $ptag = new Profile_tag();
+ $ptag->tagged = $this->profile_id;
+
+ if($ptag->find()) {
+ while($ptag->fetch()) {
+ $plist = Profile_list::getByTaggerAndTag($ptag->tagger, $ptag->tag);
+ $ptags[] = clone($plist);
+ }
+ }
+
+ foreach ($ptags as $target) {
+ $this->addToProfileTagInbox($target);
+ }
+
+ return $ptags;
+ }
+
+ function addToProfileTagInbox($plist)
+ {
+ $ptagi = Profile_tag_inbox::pkeyGet(array('profile_tag_id' => $plist->id,
+ 'notice_id' => $this->id));
+
+ if (empty($ptagi)) {
+
+ $ptagi = new Profile_tag_inbox();
+
+ $ptagi->query('BEGIN');
+ $ptagi->profile_tag_id = $plist->id;
+ $ptagi->notice_id = $this->id;
+ $ptagi->created = $this->created;
+
+ $result = $ptagi->insert();
+ if (!$result) {
+ common_log_db_error($ptagi, 'INSERT', __FILE__);
+ // TRANS: Server exception thrown when saving profile_tag inbox fails.
+ throw new ServerException(_('Problem saving profile_tag inbox.'));
+ }
+
+ $ptagi->query('COMMIT');
+
+ self::blow('profile_tag:notice_ids:%d', $ptagi->profile_tag_id);
+ }
+
+ return true;
+ }
+
/**
* Save reply records indicating that this notice needs to be
* delivered to the local users with the given URIs.
$reply_ids = $this->getReplies();
foreach ($reply_ids as $id) {
- $profile = Profile::staticGet('id', $id);
- if (!empty($profile)) {
- $ctx->attention[] = $profile->getUri();
+ $rprofile = Profile::staticGet('id', $id);
+ if (!empty($rprofile)) {
+ $ctx->attention[] = $rprofile->getUri();
}
}
/**
* Check that the given profile is allowed to read, respond to, or otherwise
* act on this notice.
- *
+ *
* The $scope member is a bitmask of scopes, representing a logical AND of the
* scope requirement. So, 0x03 (Notice::ADDRESSEE_SCOPE | Notice::SITE_SCOPE) means
* "only visible to people who are mentioned in the notice AND are users on this site."
* @return boolean whether the profile is in the notice's scope
*/
function inScope($profile)
+ {
+ $keypart = sprintf('notice:in-scope-for:%d:%d', $this->id, $profile->id);
+
+ $result = self::cacheGet($keypart);
+
+ if ($result === false) {
+ $bResult = $this->_inScope($profile);
+ $result = ($bResult) ? 1 : 0;
+ self::cacheSet($keypart, $result, 0, 300);
+ }
+
+ return ($result == 1) ? true : false;
+ }
+
+ protected function _inScope($profile)
{
// If there's no scope, anyone (even anon) is in scope.