forked from GNUsocial/gnu-social
Replace $this->user/auth_user with $this->scoped in lib/apiaction.php
We prefer handling a Profile class rather than the User class, as some functions might be useful for remote users as well, which cannot be handled via the User class.
This commit is contained in:
parent
61aa71ed34
commit
6cdedf6049
@ -264,22 +264,20 @@ class ApiAction extends Action
|
|||||||
$twitter_user['statuses_count'] = $profile->noticeCount();
|
$twitter_user['statuses_count'] = $profile->noticeCount();
|
||||||
|
|
||||||
// Is the requesting user following this user?
|
// Is the requesting user following this user?
|
||||||
|
// These values might actually also mean "unknown". Ambiguity issues?
|
||||||
$twitter_user['following'] = false;
|
$twitter_user['following'] = false;
|
||||||
$twitter_user['statusnet_blocking'] = false;
|
$twitter_user['statusnet_blocking'] = false;
|
||||||
$twitter_user['notifications'] = false;
|
$twitter_user['notifications'] = false;
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if ($this->scoped instanceof Profile) {
|
||||||
|
try {
|
||||||
$twitter_user['following'] = $this->auth_user->isSubscribed($profile);
|
$sub = Subscription::getSubscription($this->scoped, $profile);
|
||||||
$twitter_user['statusnet_blocking'] = $this->auth_user->hasBlocked($profile);
|
// Notifications on?
|
||||||
|
$twitter_user['following'] = true;
|
||||||
// Notifications on?
|
$twitter_user['statusnet_blocking'] = $this->scoped->hasBlocked($profile);
|
||||||
$sub = Subscription::pkeyGet(array('subscriber' =>
|
|
||||||
$this->auth_user->id,
|
|
||||||
'subscribed' => $profile->id));
|
|
||||||
|
|
||||||
if ($sub) {
|
|
||||||
$twitter_user['notifications'] = ($sub->jabber || $sub->sms);
|
$twitter_user['notifications'] = ($sub->jabber || $sub->sms);
|
||||||
|
} catch (NoResultException $e) {
|
||||||
|
// well, the values are already false...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,11 +428,11 @@ class ApiAction extends Action
|
|||||||
$twitter_group['nickname'] = $group->nickname;
|
$twitter_group['nickname'] = $group->nickname;
|
||||||
$twitter_group['fullname'] = $group->fullname;
|
$twitter_group['fullname'] = $group->fullname;
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if ($this->scoped instanceof Profile) {
|
||||||
$twitter_group['member'] = $this->auth_user->isMember($group);
|
$twitter_group['member'] = $this->scoped->isMember($group);
|
||||||
$twitter_group['blocked'] = Group_block::isBlocked(
|
$twitter_group['blocked'] = Group_block::isBlocked(
|
||||||
$group,
|
$group,
|
||||||
$this->auth_user->getProfile()
|
$this->scoped
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,8 +483,8 @@ class ApiAction extends Action
|
|||||||
$twitter_list['member_count'] = $list->taggedCount();
|
$twitter_list['member_count'] = $list->taggedCount();
|
||||||
$twitter_list['uri'] = $list->getUri();
|
$twitter_list['uri'] = $list->getUri();
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if ($this->scoped instanceof Profile) {
|
||||||
$twitter_list['following'] = $list->hasSubscriber($this->auth_user);
|
$twitter_list['following'] = $list->hasSubscriber($this->scoped);
|
||||||
} else {
|
} else {
|
||||||
$twitter_list['following'] = false;
|
$twitter_list['following'] = false;
|
||||||
}
|
}
|
||||||
@ -575,37 +573,30 @@ class ApiAction extends Action
|
|||||||
$relationship = array();
|
$relationship = array();
|
||||||
|
|
||||||
$relationship['source'] =
|
$relationship['source'] =
|
||||||
$this->relationshipDetailsArray($source, $target);
|
$this->relationshipDetailsArray($source->getProfile(), $target->getProfile());
|
||||||
$relationship['target'] =
|
$relationship['target'] =
|
||||||
$this->relationshipDetailsArray($target, $source);
|
$this->relationshipDetailsArray($target->getProfile(), $source->getProfile());
|
||||||
|
|
||||||
return array('relationship' => $relationship);
|
return array('relationship' => $relationship);
|
||||||
}
|
}
|
||||||
|
|
||||||
function relationshipDetailsArray($source, $target)
|
function relationshipDetailsArray(Profile $source, Profile $target)
|
||||||
{
|
{
|
||||||
$details = array();
|
$details = array();
|
||||||
|
|
||||||
$source_profile = $source->getProfile();
|
$details['screen_name'] = $source->getNickname();
|
||||||
$target_profile = $target->getProfile();
|
$details['followed_by'] = $target->isSubscribed($source);
|
||||||
|
|
||||||
$details['screen_name'] = $source->nickname;
|
try {
|
||||||
$details['followed_by'] = $target->isSubscribed($source_profile);
|
$sub = Subscription::getSubscription($source, $target);
|
||||||
$details['following'] = $source->isSubscribed($target_profile);
|
$details['following'] = true;
|
||||||
|
$details['notifications_enabled'] = ($sub->jabber || $sub->sms);
|
||||||
$notifications = false;
|
} catch (NoResultException $e) {
|
||||||
|
$details['following'] = false;
|
||||||
if ($source->isSubscribed($target_profile)) {
|
$details['notifications_enabled'] = false;
|
||||||
$sub = Subscription::pkeyGet(array('subscriber' =>
|
|
||||||
$source->id, 'subscribed' => $target->id));
|
|
||||||
|
|
||||||
if (!empty($sub)) {
|
|
||||||
$notifications = ($sub->jabber || $sub->sms);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$details['notifications_enabled'] = $notifications;
|
$details['blocking'] = $source->hasBlocked($target);
|
||||||
$details['blocking'] = $source->hasBlocked($target_profile);
|
|
||||||
$details['id'] = intval($source->id);
|
$details['id'] = intval($source->id);
|
||||||
|
|
||||||
return $details;
|
return $details;
|
||||||
@ -788,7 +779,7 @@ class ApiAction extends Action
|
|||||||
function showSingleAtomStatus($notice)
|
function showSingleAtomStatus($notice)
|
||||||
{
|
{
|
||||||
header('Content-Type: application/atom+xml; charset=utf-8');
|
header('Content-Type: application/atom+xml; charset=utf-8');
|
||||||
print $notice->asAtomEntry(true, true, true, $this->auth_user);
|
print $notice->asAtomEntry(true, true, true, $this->scoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_single_json_status($notice)
|
function show_single_json_status($notice)
|
||||||
@ -1352,7 +1343,7 @@ class ApiAction extends Action
|
|||||||
return User::getKV('nickname', $nickname);
|
return User::getKV('nickname', $nickname);
|
||||||
} else {
|
} else {
|
||||||
// Fall back to trying the currently authenticated user
|
// Fall back to trying the currently authenticated user
|
||||||
return $this->auth_user;
|
return $this->scoped->getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (self::is_decimal($id)) {
|
} else if (self::is_decimal($id)) {
|
||||||
@ -1448,7 +1439,7 @@ class ApiAction extends Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($list) && $list->private) {
|
if (!empty($list) && $list->private) {
|
||||||
if ($this->auth_user->id == $list->tagger) {
|
if ($this->scoped->id == $list->tagger) {
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user