From eb2f93ad2b0d03c5cf09e1ef77b66c124581bb6f Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 28 Jul 2014 09:25:05 +0200 Subject: [PATCH] More use of Profile, less User --- classes/Message.php | 2 +- classes/Notice.php | 22 ++++++++++------------ classes/Profile.php | 10 +++++----- lib/activitystreamjsondocument.php | 2 +- lib/atomusernoticefeed.php | 2 +- plugins/Activity/ActivityPlugin.php | 2 +- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/classes/Message.php b/classes/Message.php index bc25b1b0b3..cc605ab54f 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -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; diff --git a/classes/Notice.php b/classes/Notice.php index 89f41ad79b..e9875d3424 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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 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"; } diff --git a/classes/Profile.php b/classes/Profile.php index e0eb06956f..94f83ab788 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -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 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); diff --git a/lib/activitystreamjsondocument.php b/lib/activitystreamjsondocument.php index ed3197bc7f..767fb5dff7 100644 --- a/lib/activitystreamjsondocument.php +++ b/lib/activitystreamjsondocument.php @@ -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++; } diff --git a/lib/atomusernoticefeed.php b/lib/atomusernoticefeed.php index 567045ee86..56e97880b0 100644 --- a/lib/atomusernoticefeed.php +++ b/lib/atomusernoticefeed.php @@ -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')); } diff --git a/plugins/Activity/ActivityPlugin.php b/plugins/Activity/ActivityPlugin.php index 99c0a246c6..6dc9730544 100644 --- a/plugins/Activity/ActivityPlugin.php +++ b/plugins/Activity/ActivityPlugin.php @@ -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;