* Record the given set of hash tags in the db for this notice.
* Given tag strings will be normalized and checked for dupes.
*/
- function saveKnownTags($hashtags)
+ function saveKnownTags(array $hashtags)
{
//turn each into their canonical tag
//this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
// reasonably handle notifications themselves.
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
- $stored->saveAttentions($act->context->attention);
-
if (!empty($tags)) {
$stored->saveKnownTags($tags);
} else {
// Note: groups may save tags, so must be run after tags are saved
// to avoid errors on duplicates.
- // Note: groups should always be set.
+ $stored->saveAttentions($act->context->attention);
if (!empty($urls)) {
$stored->saveKnownUrls($urls);
*
* @return void
*/
- function saveKnownUrls($urls)
+ function saveKnownUrls(array $urls)
{
if (common_config('attachments', 'process_links')) {
// @fixme validation?
continue;
}
- $this->saveAttention($target);
+ try {
+ $this->saveAttention($target);
+ } catch (AlreadyFulfilledException $e) {
+ common_debug('Attention already exists: '.var_export($e->getMessage(),true));
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Could not save notice id=={$this->getID()} attention for profile id=={$target->getID()}: {$e->getMessage()}");
+ }
}
}
+ /**
+ * Saves an attention for a profile (user or group) which means
+ * it shows up in their home feed and such.
+ */
function saveAttention(Profile $target, $reason=null)
{
if ($target->isGroup()) {
- // FIXME: Make sure we check that users are in the groups they send to!
+ // FIXME: Make sure we check (for both local and remote) users are in the groups they send to!
+
+ // legacy notification method, will still be in use for quite a while I think
+ $this->addToGroupInbox($target->getGroup());
} else {
if ($target->hasBlocked($this->getProfile())) {
common_log(LOG_INFO, "Not saving reply to profile {$target->id} ($uri) from sender {$sender->id} because of a block.");
}
if ($target->isLocal()) {
- // is local user
- $this->saveReply($target->getID()); // since we still have the Reply table which some apparently use!
+ // legacy notification method, will still be in use for quite a while I think
+ $this->saveReply($target->getID());
}
- try {
- $att = Attention::saveNew($this, $target, $reason);
- } catch (AlreadyFulfilledException $e) {
- common_debug('Could not save Attention: '.$e->getMessage());
- } catch (Exception $e) {
- common_log(LOG_ERR, 'Could not save Attention: '.$e->getMessage());
- }
+ $att = Attention::saveNew($this, $target, $reason);
self::blow('reply:stream:%d', $target->getID());
return true;
return $this->_replies[$this->getID()];
}
- function _setReplies($replies)
+ function _setReplies(array $replies)
{
$this->_replies[$this->getID()] = $replies;
}
}
$groups = User_group::multiGet('id', $ids);
- $this->_groups[$this->id] = $groups->fetchAll();
+ $this->_setGroups($groups->fetchAll());
return $this->_groups[$this->id];
}
}
}
- $reply_ids = $this->getReplies();
-
- foreach ($reply_ids as $id) {
- $rprofile = Profile::getKV('id', $id);
- if ($rprofile instanceof Profile) {
- $ctx->attention[$rprofile->getUri()] = ActivityObject::PERSON;
- }
- }
-
- $groups = $this->getGroups();
-
- foreach ($groups as $group) {
- $ctx->attention[$group->getUri()] = ActivityObject::GROUP;
+ // This covers the legacy getReplies and getGroups too which get their data
+ // from entries stored via Notice::saveNew (which we want to move away from)...
+ foreach ($this->getAttentionProfiles() as $target) {
+ // User and group profiles which get the attention of this notice
+ $ctx->attention[$target->getUri()] = $target->getObjectType();
}
switch ($this->scope) {
*
* @return boolean whether the profile is in the notice's scope
*/
- function inScope($profile)
+ function inScope(Profile $profile=null)
{
if (is_null($profile)) {
$keypart = sprintf('notice:in-scope-for:%d:null', $this->id);
return ($result == 1) ? true : false;
}
- protected function _inScope($profile)
+ protected function _inScope(Profile $profile=null)
{
$scope = is_null($this->scope) ? self::defaultScope() : $this->getScope();
return !$this->isHiddenSpam($profile);
}
- function isHiddenSpam($profile) {
+ function isHiddenSpam(Profile $profile=null) {
// Hide posts by silenced users from everyone but moderators.
return $scope;
}
- static function fillProfiles($notices)
+ static function fillProfiles(array $notices)
{
$map = self::getProfiles($notices);
foreach ($notices as $entry=>$notice) {
return array_values($map);
}
- static function getProfiles(&$notices)
+ static function getProfiles(array &$notices)
{
$ids = array();
foreach ($notices as $notice) {
return Profile::pivotGet('id', $ids);
}
- static function fillGroups(&$notices)
+ static function fillGroups(array &$notices)
{
$ids = self::_idsOf($notices);
$gis = Group_inbox::listGet('notice_id', $ids);
return array_keys($ids);
}
- static function fillAttachments(&$notices)
+ static function fillAttachments(array &$notices)
{
$ids = self::_idsOf($notices);
$f2pMap = File_to_post::listGet('post_id', $ids);
}
}
- static function fillReplies(&$notices)
+ static function fillReplies(array &$notices)
{
$ids = self::_idsOf($notices);
$replyMap = Reply::listGet('notice_id', $ids);