More use of Profile, less User

This commit is contained in:
Mikael Nordfeldth 2014-07-28 09:25:05 +02:00
parent d11ce2ef3b
commit eb2f93ad2b
6 changed files with 19 additions and 21 deletions

View File

@ -184,7 +184,7 @@ class Message extends Managed_DataObject
}
$act->actor = $profile->asActivityObject();
$act->actor->extra[] = $profile->profileInfo(null);
$act->actor->extra[] = $profile->profileInfo();
$act->verb = ActivityVerb::POST;

View File

@ -1737,12 +1737,12 @@ class Notice extends Managed_DataObject
/**
* Convert a notice into an activity for export.
*
* @param User $cur Current user
* @param Profile $scoped The currently logged in/scoped profile
*
* @return Activity activity object representing this Notice.
*/
function asActivity($cur=null)
function asActivity(Profile $scoped=null)
{
$act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
@ -1766,14 +1766,14 @@ class Notice extends Managed_DataObject
$profile = $this->getProfile();
$act->actor = $profile->asActivityObject();
$act->actor->extra[] = $profile->profileInfo($cur);
$act->actor->extra[] = $profile->profileInfo($scoped);
$act->verb = $this->verb;
if ($this->repeat_of) {
$repeated = Notice::getKV('id', $this->repeat_of);
if ($repeated instanceof Notice) {
$act->objects[] = $repeated->asActivity($cur);
$act->objects[] = $repeated->asActivity($scoped);
}
} else {
$act->objects[] = $this->asActivityObject();
@ -1912,10 +1912,10 @@ class Notice extends Managed_DataObject
function asAtomEntry($namespace=false,
$source=false,
$author=true,
$cur=null)
Profile $scoped=null)
{
$act = $this->asActivity($cur);
$act->extra[] = $this->noticeInfo($cur);
$act = $this->asActivity($scoped);
$act->extra[] = $this->noticeInfo($scoped);
return $act->asString($namespace, $author, $source);
}
@ -1925,12 +1925,12 @@ class Notice extends Managed_DataObject
* Clients use some extra notice info in the atom stream.
* This gives it to them.
*
* @param User $cur Current user
* @param Profile $scoped The currently logged in/scoped profile
*
* @return array representation of <statusnet:notice_info> element
*/
function noticeInfo($cur)
function noticeInfo(Profile $scoped=null)
{
// local notice ID (useful to clients for ordering)
@ -1956,9 +1956,7 @@ class Notice extends Managed_DataObject
// favorite and repeated
$scoped = null;
if (!empty($cur)) {
$scoped = $cur->getProfile();
if ($scoped instanceof Profile) {
$noticeInfoAttr['repeated'] = ($scoped->hasRepeated($this)) ? "true" : "false";
}

View File

@ -1266,20 +1266,20 @@ class Profile extends Managed_DataObject
* Clients use some extra profile info in the atom stream.
* This gives it to them.
*
* @param User $cur Current user
* @param Profile $scoped The currently logged in/scoped profile
*
* @return array representation of <statusnet:profile_info> element or null
*/
function profileInfo($cur)
function profileInfo(Profile $scoped=null)
{
$profileInfoAttr = array('local_id' => $this->id);
if ($cur != null) {
if ($scoped instanceof Profile) {
// Whether the current user is a subscribed to this profile
$profileInfoAttr['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
$profileInfoAttr['following'] = $scoped->isSubscribed($this) ? 'true' : 'false';
// Whether the current user is has blocked this profile
$profileInfoAttr['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
$profileInfoAttr['blocking'] = $scoped->hasBlocked($this) ? 'true' : 'false';
}
return array('statusnet:profile_info', $profileInfoAttr, null);

View File

@ -141,7 +141,7 @@ class ActivityStreamJSONDocument extends JSONActivityCollection
$cur = empty($this->cur) ? common_current_user() : $this->cur;
$act = $notice->asActivity($cur);
$act->extra[] = $notice->noticeInfo($cur);
$act->extra[] = $notice->noticeInfo($cur->getProfile());
array_push($this->items, $act->asArray());
$this->count++;
}

View File

@ -64,7 +64,7 @@ class AtomUserNoticeFeed extends AtomNoticeFeed
$ao = $profile->asActivityObject();
array_push($ao->extra, $profile->profileInfo($cur));
array_push($ao->extra, $profile->profileInfo($cur->getProfile()));
$this->addAuthorRaw($ao->asString('author'));
}

View File

@ -317,7 +317,7 @@ class ActivityPlugin extends Plugin
$notice = Notice::getKV('id', $fave->notice_id);
if (!empty($notice)) {
$cur = common_current_user();
$target = $notice->asActivity($cur);
$target = $notice->asActivity($cur->getProfile());
if ($target->verb == ActivityVerb::POST) {
// "I like the thing you posted"
$activity->objects = $target->objects;