Type testing instead of just empty() in OStatusPlugin

This commit is contained in:
Mikael Nordfeldth 2014-05-06 14:36:52 +02:00
parent 261778f6de
commit 0fa00d5106

View File

@ -350,7 +350,7 @@ class OStatusPlugin extends Plugin
$this->log(LOG_INFO, "Checking webfinger '$target'"); $this->log(LOG_INFO, "Checking webfinger '$target'");
try { try {
$oprofile = Ostatus_profile::ensureWebfinger($target); $oprofile = Ostatus_profile::ensureWebfinger($target);
if ($oprofile && !$oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
$profile = $oprofile->localProfile(); $profile = $oprofile->localProfile();
$matches[$pos] = array('mentioned' => array($profile), $matches[$pos] = array('mentioned' => array($profile),
'type' => 'mention', 'type' => 'mention',
@ -377,7 +377,7 @@ class OStatusPlugin extends Plugin
$this->log(LOG_INFO, "Checking profile address '$url'"); $this->log(LOG_INFO, "Checking profile address '$url'");
try { try {
$oprofile = Ostatus_profile::ensureProfileURL($url); $oprofile = Ostatus_profile::ensureProfileURL($url);
if ($oprofile && !$oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
$profile = $oprofile->localProfile(); $profile = $oprofile->localProfile();
$matches[$pos] = array('mentioned' => array($profile), $matches[$pos] = array('mentioned' => array($profile),
'type' => 'mention', 'type' => 'mention',
@ -422,7 +422,7 @@ class OStatusPlugin extends Plugin
function onStartCommandGetProfile($command, $arg, &$profile) function onStartCommandGetProfile($command, $arg, &$profile)
{ {
$oprofile = $this->pullRemoteProfile($arg); $oprofile = $this->pullRemoteProfile($arg);
if ($oprofile && !$oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
$profile = $oprofile->localProfile(); $profile = $oprofile->localProfile();
return false; return false;
} else { } else {
@ -444,7 +444,7 @@ class OStatusPlugin extends Plugin
function onStartCommandGetGroup($command, $arg, &$group) function onStartCommandGetGroup($command, $arg, &$group)
{ {
$oprofile = $this->pullRemoteProfile($arg); $oprofile = $this->pullRemoteProfile($arg);
if ($oprofile && $oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && $oprofile->isGroup()) {
$group = $oprofile->localGroup(); $group = $oprofile->localGroup();
return false; return false;
} else { } else {
@ -580,7 +580,7 @@ class OStatusPlugin extends Plugin
function onFeedSubSubscriberCount($feedsub, &$count) function onFeedSubSubscriberCount($feedsub, &$count)
{ {
$oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri); $oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri);
if ($oprofile) { if ($oprofile instanceof Ostatus_profile) {
$count += $oprofile->subscriberCount(); $count += $oprofile->subscriberCount();
} }
return true; return true;
@ -607,8 +607,7 @@ class OStatusPlugin extends Plugin
} }
$oprofile = Ostatus_profile::getKV('profile_id', $other->id); $oprofile = Ostatus_profile::getKV('profile_id', $other->id);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -636,8 +635,7 @@ class OStatusPlugin extends Plugin
} }
$oprofile = Ostatus_profile::getKV('profile_id', $other->id); $oprofile = Ostatus_profile::getKV('profile_id', $other->id);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -666,8 +664,7 @@ class OStatusPlugin extends Plugin
} }
$oprofile = Ostatus_profile::getKV('profile_id', $other->id); $oprofile = Ostatus_profile::getKV('profile_id', $other->id);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -713,7 +710,10 @@ class OStatusPlugin extends Plugin
function onStartJoinGroup($group, $profile) function onStartJoinGroup($group, $profile)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if ($oprofile) { if (!$oprofile instanceof Ostatus_profile) {
return true;
}
if (!$oprofile->subscribe()) { if (!$oprofile->subscribe()) {
// TRANS: Exception thrown when setup of remote group membership fails. // TRANS: Exception thrown when setup of remote group membership fails.
throw new Exception(_m('Could not set up remote group membership.')); throw new Exception(_m('Could not set up remote group membership.'));
@ -749,7 +749,6 @@ class OStatusPlugin extends Plugin
throw new Exception(_m('Failed joining remote group.')); throw new Exception(_m('Failed joining remote group.'));
} }
} }
}
/** /**
* When one of our local users leaves a remote group, notify the remote * When one of our local users leaves a remote group, notify the remote
@ -768,7 +767,10 @@ class OStatusPlugin extends Plugin
function onEndLeaveGroup($group, $profile) function onEndLeaveGroup($group, $profile)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if ($oprofile) { if (!$oprofile instanceof Ostatus_profile) {
return true;
}
// Drop the PuSH subscription if there are no other subscribers. // Drop the PuSH subscription if there are no other subscribers.
$oprofile->garbageCollect(); $oprofile->garbageCollect();
@ -795,7 +797,6 @@ class OStatusPlugin extends Plugin
$oprofile->notifyActivity($act, $member); $oprofile->notifyActivity($act, $member);
} }
}
/** /**
* When one of our local users tries to subscribe to a remote peopletag, * When one of our local users tries to subscribe to a remote peopletag,
@ -811,7 +812,10 @@ class OStatusPlugin extends Plugin
function onStartSubscribePeopletag($peopletag, $user) function onStartSubscribePeopletag($peopletag, $user)
{ {
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id); $oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
if ($oprofile) { if (!$oprofile instanceof Ostatus_profile) {
return true;
}
if (!$oprofile->subscribe()) { if (!$oprofile->subscribe()) {
// TRANS: Exception thrown when setup of remote list subscription fails. // TRANS: Exception thrown when setup of remote list subscription fails.
throw new Exception(_m('Could not set up remote list subscription.')); throw new Exception(_m('Could not set up remote list subscription.'));
@ -848,7 +852,6 @@ class OStatusPlugin extends Plugin
throw new Exception(_m('Failed subscribing to remote list.')); throw new Exception(_m('Failed subscribing to remote list.'));
} }
} }
}
/** /**
* When one of our local users unsubscribes to a remote peopletag, notify the remote * When one of our local users unsubscribes to a remote peopletag, notify the remote
@ -863,7 +866,10 @@ class OStatusPlugin extends Plugin
function onEndUnsubscribePeopletag($peopletag, $user) function onEndUnsubscribePeopletag($peopletag, $user)
{ {
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id); $oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
if ($oprofile) { if (!$oprofile instanceof Ostatus_profile) {
return true;
}
// Drop the PuSH subscription if there are no other subscribers. // Drop the PuSH subscription if there are no other subscribers.
$oprofile->garbageCollect(); $oprofile->garbageCollect();
@ -892,7 +898,6 @@ class OStatusPlugin extends Plugin
$oprofile->notifyActivity($act, $user); $oprofile->notifyActivity($act, $user);
} }
}
/** /**
* Notify remote users when their notices get favorited. * Notify remote users when their notices get favorited.
@ -903,23 +908,23 @@ class OStatusPlugin extends Plugin
*/ */
function onEndFavorNotice(Profile $profile, Notice $notice) function onEndFavorNotice(Profile $profile, Notice $notice)
{ {
$user = User::getKV('id', $profile->id); // Only distribute local users' favor actions, remote users
// will have already distributed theirs.
if (empty($user)) { if (!$profile->isLocal()) {
return true; return true;
} }
$oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id); $oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
$fav = Fave::pkeyGet(array('user_id' => $user->id, $fav = Fave::pkeyGet(array('user_id' => $user->id,
'notice_id' => $notice->id)); 'notice_id' => $notice->id));
if (empty($fav)) { if (!$fav instanceof Fave) {
// That's weird. // That's weird.
// TODO: Make pkeyGet throw exception, since this is a critical failure.
return true; return true;
} }
@ -941,8 +946,7 @@ class OStatusPlugin extends Plugin
function onEndTagProfile($ptag) function onEndTagProfile($ptag)
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged); $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -998,8 +1002,7 @@ class OStatusPlugin extends Plugin
function onEndUntagProfile($ptag) function onEndUntagProfile($ptag)
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged); $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -1049,15 +1052,14 @@ class OStatusPlugin extends Plugin
*/ */
function onEndDisfavorNotice(Profile $profile, Notice $notice) function onEndDisfavorNotice(Profile $profile, Notice $notice)
{ {
$user = User::getKV('id', $profile->id); // Only distribute local users' disfavor actions, remote users
// will have already distributed theirs.
if (empty($user)) { if (!$profile->isLocal()) {
return true; return true;
} }
$oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id); $oprofile = Ostatus_profile::getKV('profile_id', $notice->profile_id);
if (!$oprofile instanceof Ostatus_profile) {
if (empty($oprofile)) {
return true; return true;
} }
@ -1103,7 +1105,7 @@ class OStatusPlugin extends Plugin
function onStartUserGroupPermalink($group, &$url) function onStartUserGroupPermalink($group, &$url)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if ($oprofile) { if ($oprofile instanceof Ostatus_profile) {
// @fixme this should probably be in the user_group table // @fixme this should probably be in the user_group table
// @fixme this uri not guaranteed to be a profile page // @fixme this uri not guaranteed to be a profile page
$url = $oprofile->uri; $url = $oprofile->uri;
@ -1290,7 +1292,7 @@ class OStatusPlugin extends Plugin
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id); $oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
if (empty($oprofile)) { if (!$oprofile instanceof Ostatus_profile) {
return true; return true;
} }