Get group attentions too for outbound notices

This commit is contained in:
Mikael Nordfeldth 2016-01-09 15:06:44 +01:00
parent c3c5a9974d
commit 5ef10a14ef
2 changed files with 24 additions and 24 deletions

View File

@ -1579,14 +1579,28 @@ class Notice extends Managed_DataObject
continue; 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) function saveAttention(Profile $target, $reason=null)
{ {
if ($target->isGroup()) { if ($target->isGroup()) {
// FIXME: Make sure we check that users are in the groups they send to! // FIXME: Make sure we check that users are in the groups they send to!
if ($target->getGroup()->isLocal()) {
// legacy notification method, will still be in use for quite a while I think
$this->addToGroupInbox($target->getGroup());
}
} else { } else {
if ($target->hasBlocked($this->getProfile())) { 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."); common_log(LOG_INFO, "Not saving reply to profile {$target->id} ($uri) from sender {$sender->id} because of a block.");
@ -1595,17 +1609,11 @@ class Notice extends Managed_DataObject
} }
if ($target->isLocal()) { if ($target->isLocal()) {
// is local user // legacy notification method, will still be in use for quite a while I think
$this->saveReply($target->getID()); // since we still have the Reply table which some apparently use! $this->saveReply($target->getID());
} }
try { $att = Attention::saveNew($this, $target, $reason);
$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());
}
self::blow('reply:stream:%d', $target->getID()); self::blow('reply:stream:%d', $target->getID());
return true; return true;
@ -1952,19 +1960,11 @@ class Notice extends Managed_DataObject
} }
} }
$reply_ids = $this->getReplies(); // 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 ($reply_ids as $id) { foreach ($this->getAttentionProfiles() as $target) {
$rprofile = Profile::getKV('id', $id); // User and group profiles which get the attention of this notice
if ($rprofile instanceof Profile) { $ctx->attention[$target->getUri()] = $target->getObjectType();
$ctx->attention[$rprofile->getUri()] = ActivityObject::PERSON;
}
}
$groups = $this->getGroups();
foreach ($groups as $group) {
$ctx->attention[$group->getUri()] = ActivityObject::GROUP;
} }
switch ($this->scope) { switch ($this->scope) {

View File

@ -687,7 +687,7 @@ function common_get_attentions($text, Profile $sender, Notice $parent=null)
$atts = array(); $atts = array();
foreach ($mentions as $mention) { foreach ($mentions as $mention) {
foreach ($mention['mentioned'] as $mentioned) { foreach ($mention['mentioned'] as $mentioned) {
$atts[$mentioned->getUri()] = $mentioned->isGroup() ? ActivityObject::GROUP : ActivityObject::PERSON; $atts[$mentioned->getUri()] = $mentioned->getObjectType();
} }
} }
if ($parent instanceof Notice) { if ($parent instanceof Notice) {