forked from GNUsocial/gnu-social
saveAttentions, trying to move away from saveReply
This commit is contained in:
parent
801ca3531b
commit
6255e1dca3
@ -969,23 +969,12 @@ class Notice extends Managed_DataObject
|
|||||||
throw new ServerException('StartNoticeSave did not give back a Notice');
|
throw new ServerException('StartNoticeSave did not give back a Notice');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save per-notice metadata...
|
|
||||||
$mentions = array();
|
|
||||||
$group_ids = array();
|
|
||||||
|
|
||||||
// This event lets plugins filter out non-local recipients (attentions we don't care about)
|
|
||||||
// Used primarily for OStatus (and if we don't federate, all attentions would be local anyway)
|
|
||||||
Event::handle('GetLocalAttentions', array($actor, $act->context->attention, &$mentions, &$group_ids));
|
|
||||||
|
|
||||||
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
|
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
|
||||||
// the activityverb is a POST (since stuff like repeat, favorite etc.
|
// the activityverb is a POST (since stuff like repeat, favorite etc.
|
||||||
// reasonably handle notifications themselves.
|
// reasonably handle notifications themselves.
|
||||||
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
|
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
|
||||||
if (!empty($mentions)) {
|
|
||||||
$stored->saveKnownReplies($mentions);
|
$stored->saveAttentions($act->context->attention);
|
||||||
} else {
|
|
||||||
$stored->saveReplies();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($tags)) {
|
if (!empty($tags)) {
|
||||||
$stored->saveKnownTags($tags);
|
$stored->saveKnownTags($tags);
|
||||||
@ -997,8 +986,6 @@ class Notice extends Managed_DataObject
|
|||||||
// to avoid errors on duplicates.
|
// to avoid errors on duplicates.
|
||||||
// Note: groups should always be set.
|
// Note: groups should always be set.
|
||||||
|
|
||||||
$stored->saveKnownGroups($group_ids);
|
|
||||||
|
|
||||||
if (!empty($urls)) {
|
if (!empty($urls)) {
|
||||||
$stored->saveKnownUrls($urls);
|
$stored->saveKnownUrls($urls);
|
||||||
} else {
|
} else {
|
||||||
@ -1584,6 +1571,43 @@ class Notice extends Managed_DataObject
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveAttentions(array $uris)
|
||||||
|
{
|
||||||
|
foreach ($uris as $uri=>$type) {
|
||||||
|
try {
|
||||||
|
$target = Profile::fromUri($uri);
|
||||||
|
} catch (UnknownUriException $e) {
|
||||||
|
common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->saveAttention($target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveAttention(Profile $target, $reason=null)
|
||||||
|
{
|
||||||
|
if ($target->isGroup()) {
|
||||||
|
// FIXME: Make sure we check that users are in the groups they send to!
|
||||||
|
} 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.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
self::blow('reply:stream:%d', $target->getID());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save reply records indicating that this notice needs to be
|
* Save reply records indicating that this notice needs to be
|
||||||
* delivered to the local users with the given URIs.
|
* delivered to the local users with the given URIs.
|
||||||
@ -1658,9 +1682,6 @@ class Notice extends Managed_DataObject
|
|||||||
|
|
||||||
$mentions = common_find_mentions($this->content, $sender, $parent);
|
$mentions = common_find_mentions($this->content, $sender, $parent);
|
||||||
|
|
||||||
// store replied only for first @ (what user/notice what the reply directed,
|
|
||||||
// we assume first @ is it)
|
|
||||||
|
|
||||||
foreach ($mentions as $mention) {
|
foreach ($mentions as $mention) {
|
||||||
|
|
||||||
foreach ($mention['mentioned'] as $mentioned) {
|
foreach ($mention['mentioned'] as $mentioned) {
|
||||||
@ -1671,9 +1692,7 @@ class Notice extends Managed_DataObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't save replies from blocked profile to local user
|
// Don't save replies from blocked profile to local user
|
||||||
|
if ($mentioned->hasBlocked($sender)) {
|
||||||
$mentioned_user = User::getKV('id', $mentioned->id);
|
|
||||||
if ($mentioned_user instanceof User && $mentioned_user->hasBlocked($sender)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1701,6 +1720,23 @@ class Notice extends Managed_DataObject
|
|||||||
return $reply;
|
return $reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected $_attentionids = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pull the complete list of known activity context attentions for this notice.
|
||||||
|
*
|
||||||
|
* @return array of integer profile ids (also group profiles)
|
||||||
|
*/
|
||||||
|
function getAttentionProfileIDs()
|
||||||
|
{
|
||||||
|
if (!isset($this->_attentionids[$this->getID()])) {
|
||||||
|
$atts = Attention::multiGet('notice_id', array($this->getID()));
|
||||||
|
// (array)null means empty array
|
||||||
|
$this->_attentionids[$this->getID()] = (array)$atts->fetchAll('profile_id');
|
||||||
|
}
|
||||||
|
return $this->_attentionids[$this->getID()];
|
||||||
|
}
|
||||||
|
|
||||||
protected $_replies = array();
|
protected $_replies = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1729,9 +1765,9 @@ class Notice extends Managed_DataObject
|
|||||||
*/
|
*/
|
||||||
function getAttentionProfiles()
|
function getAttentionProfiles()
|
||||||
{
|
{
|
||||||
$ids = array_unique(array_merge($this->getReplies(), $this->getGroupProfileIDs()));
|
$ids = array_unique(array_merge($this->getReplies(), $this->getGroupProfileIDs(), $this->getAttentionProfileIDs()));
|
||||||
|
|
||||||
$profiles = Profile::multiGet('id', $ids);
|
$profiles = Profile::multiGet('id', (array)$ids);
|
||||||
|
|
||||||
return $profiles->fetchAll();
|
return $profiles->fetchAll();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user