Reworked the ActivityContext->attention structure

Removing Evan's obscure attentionType solution and directly using the attention array
This commit is contained in:
Mikael Nordfeldth
2013-10-28 22:21:14 +01:00
parent f99c4b7f07
commit 23a6b4595f
12 changed files with 63 additions and 76 deletions

View File

@@ -450,19 +450,19 @@ class BookmarkPlugin extends MicroAppPlugin
}
}
$replies = $activity->context->attention;
$options['groups'] = array();
$options['replies'] = array();
$options['replies'] = array(); // TODO: context->attention
foreach ($replies as $replyURI) {
$other = Profile::fromURI($replyURI);
if (!empty($other)) {
$options['replies'][] = $replyURI;
foreach ($activity->context->attention as $attnUrl=>$type) {
$other = Profile::fromURI($attnUrl);
if ($other instanceof Profile) {
$options['replies'][] = $attnUrl;
} else {
$group = User_group::getKV('uri', $replyURI);
if (!empty($group)) {
$options['groups'][] = $replyURI;
// Maybe we can get rid of this since every User_group got a Profile?
// TODO: Make sure the above replies get sorted properly for groups (or handled afterwards)
$group = User_group::getKV('uri', $attnUrl);
if ($group instanceof User_group) {
$options['groups'][] = $attnUrl;
}
}
}

View File

@@ -78,14 +78,13 @@ class GroupsalmonAction extends SalmonAction
}
// Notice must be to the attention of this group
$context = $this->activity->context;
if (empty($context->attention)) {
if (empty($this->activity->context->attention)) {
// TRANS: Client exception.
throw new ClientException("Not to the attention of anyone.");
} else {
$uri = common_local_url('groupbyid', array('id' => $this->group->id));
if (!in_array($uri, $context->attention)) {
if (!array_key_exists($uri, $this->activity->context->attention)) {
// TRANS: Client exception.
throw new ClientException("Not to the attention of this group.");
}

View File

@@ -91,9 +91,9 @@ class UsersalmonAction extends SalmonAction
throw new ClientException(_m('In reply to a notice not by this user and not mentioning this user.'));
}
} else if (!empty($context->attention)) {
if (!in_array($this->user->uri, $context->attention) &&
!in_array(common_profile_url($this->user->nickname), $context->attention)) {
common_log(LOG_ERR, "{$this->user->uri} not in attention list (".implode(',', $context->attention).")");
if (!array_key_exists($this->user->uri, $context->attention) &&
!array_key_exists(common_profile_url($this->user->nickname), $context->attention)) {
common_log(LOG_ERR, "{$this->user->uri} not in attention list (".implode(',', array_keys($context->attention)).')');
// TRANS: Client exception.
throw new ClientException(_m('To the attention of user(s), not including this one.'));
}

View File

@@ -656,10 +656,9 @@ class Ostatus_profile extends Managed_DataObject
}
if ($activity->context) {
// Any individual or group attn: targets?
$replies = $activity->context->attention;
$options['groups'] = $this->filterReplies($oprofile, $replies);
$options['replies'] = $replies;
// TODO: context->attention
list($options['groups'], $options['replies'])
= $this->filterReplies($oprofile, $activity->context->attention);
// Maintain direct reply associations
// @todo FIXME: What about conversation ID?
@@ -826,10 +825,9 @@ class Ostatus_profile extends Managed_DataObject
}
if ($activity->context) {
// Any individual or group attn: targets?
$replies = $activity->context->attention;
$options['groups'] = $this->filterReplies($oprofile, $replies);
$options['replies'] = $replies;
// TODO: context->attention
list($options['groups'], $options['replies'])
= $this->filterReplies($oprofile, $activity->context->attention);
// Maintain direct reply associations
// @todo FIXME: What about conversation ID?
@@ -908,26 +906,26 @@ class Ostatus_profile extends Managed_DataObject
* @param array in/out &$attention_uris set of URIs, will be pruned on output
* @return array of group IDs
*/
protected function filterReplies($sender, &$attention_uris)
protected function filterReplies($sender, array $attention)
{
common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', $attention_uris));
common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', $attention));
$groups = array();
$replies = array();
foreach (array_unique($attention_uris) as $recipient) {
foreach ($attention as $recipient=>$type) {
// Is the recipient a local user?
$user = User::getKV('uri', $recipient);
if ($user) {
if ($user instanceof User) {
// @todo FIXME: Sender verification, spam etc?
$replies[] = $recipient;
continue;
}
// Is the recipient a local group?
// $group = User_group::getKV('uri', $recipient);
// TODO: $group = User_group::getKV('uri', $recipient);
$id = OStatusPlugin::localGroupFromUrl($recipient);
if ($id) {
$group = User_group::getKV('id', $id);
if ($group) {
if ($group instanceof User_group) {
// Deliver to all members of this local group if allowed.
$profile = $sender->localProfile();
if ($profile->isMember($group)) {
@@ -959,10 +957,9 @@ class Ostatus_profile extends Managed_DataObject
}
}
$attention_uris = $replies;
common_log(LOG_DEBUG, "Local reply recipients: " . implode(', ', $replies));
common_log(LOG_DEBUG, "Local group recipients: " . implode(', ', $groups));
return $groups;
return array($groups, $replies);
}
/**