Tidying up getUser calls to profiles and some events

getUser calls are much more strict, and one place where this was found was
in the (un)subscribe start/end event handlers, which resulted in making the
Subscription class a bit stricter, regarding ::start and ::cancel at least.
Several minor fixes in many files were made due to this.

This does NOT touch the Foreign_link function, which should also have a more
strict getUser call. That is a future project.
This commit is contained in:
Mikael Nordfeldth
2013-09-09 21:35:16 +02:00
parent c5bf6cb05e
commit 747fe9d59b
20 changed files with 317 additions and 236 deletions

View File

@@ -601,18 +601,16 @@ class OStatusPlugin extends Plugin
* @fixme If something else aborts later, we could end up with a stray
* PuSH subscription. This is relatively harmless, though.
*
* @param Profile $subscriber
* @param Profile $other
* @param Profile $profile subscriber
* @param Profile $other subscribee
*
* @return hook return code
*
* @throws Exception
*/
function onStartSubscribe($subscriber, $other)
function onStartSubscribe(Profile $profile, Profile $other)
{
$user = User::getKV('id', $subscriber->id);
if (empty($user)) {
if (!$profile->isLocal()) {
return true;
}
@@ -632,18 +630,16 @@ class OStatusPlugin extends Plugin
* Having established a remote subscription, send a notification to the
* remote OStatus profile's endpoint.
*
* @param Profile $subscriber
* @param Profile $other
* @param Profile $profile subscriber
* @param Profile $other subscribee
*
* @return hook return code
*
* @throws Exception
*/
function onEndSubscribe($subscriber, $other)
function onEndSubscribe(Profile $profile, Profile $other)
{
$user = User::getKV('id', $subscriber->id);
if (empty($user)) {
if (!$profile->isLocal()) {
return true;
}
@@ -653,12 +649,12 @@ class OStatusPlugin extends Plugin
return true;
}
$sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
$sub = Subscription::pkeyGet(array('subscriber' => $profile->id,
'subscribed' => $other->id));
$act = $sub->asActivity();
$oprofile->notifyActivity($act, $subscriber);
$oprofile->notifyActivity($act, $profile);
return true;
}
@@ -671,11 +667,9 @@ class OStatusPlugin extends Plugin
* @param Profile $other
* @return hook return value
*/
function onEndUnsubscribe($profile, $other)
function onEndUnsubscribe(Profile $profile, Profile $other)
{
$user = User::getKV('id', $profile->id);
if (empty($user)) {
if (!$profile->isLocal()) {
return true;
}

View File

@@ -298,7 +298,7 @@ class OStatusSubAction extends Action
if ($user->isSubscribed($local)) {
// TRANS: OStatus remote subscription dialog error.
$this->showForm(_m('Already subscribed!'));
} elseif (Subscription::start($user, $local)) {
} elseif (Subscription::start($user->getProfile(), $local)) {
$this->success();
} else {
// TRANS: OStatus remote subscription dialog error.