forked from GNUsocial/gnu-social
OStatus: sub/unsub notifications working again. Fixed up autodetection of feed info at profile setup time
This commit is contained in:
parent
d69f6dff6a
commit
557df3d3f7
@ -331,6 +331,8 @@ class OStatusPlugin extends Plugin
|
|||||||
$oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
|
$oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri);
|
||||||
if ($oprofile) {
|
if ($oprofile) {
|
||||||
$oprofile->processFeed($feed);
|
$oprofile->processFeed($feed);
|
||||||
|
} else {
|
||||||
|
common_log(LOG_DEBUG, "No ostatus profile for incoming feed $feedsub->uri");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ class SalmonAction extends Action
|
|||||||
|
|
||||||
function prepare($args)
|
function prepare($args)
|
||||||
{
|
{
|
||||||
|
StatusNet::setApi(true); // Send smaller error pages
|
||||||
|
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||||
@ -63,8 +65,12 @@ class SalmonAction extends Action
|
|||||||
// XXX: check that document element is Atom entry
|
// XXX: check that document element is Atom entry
|
||||||
// XXX: check the signature
|
// XXX: check the signature
|
||||||
|
|
||||||
$this->act = new Activity($dom->documentElement);
|
// We need to run an entry into Activity, so get the first one
|
||||||
|
$entries = $dom->getElementsByTagNameNS(Activity::ATOM, 'entry');
|
||||||
|
if ($entries && $entries->length) {
|
||||||
|
// @fixme is it legit to have multiple entries?
|
||||||
|
$this->act = new Activity($entries->item(0), $dom->documentElement);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +80,9 @@ class SalmonAction extends Action
|
|||||||
|
|
||||||
function handle($args)
|
function handle($args)
|
||||||
{
|
{
|
||||||
|
StatusNet::setApi(true); // Send smaller error pages
|
||||||
common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
|
common_log(LOG_INFO, 'Salmon: incoming post for user '. $this->user->id);
|
||||||
|
common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
|
||||||
|
|
||||||
// TODO : Insert new $xml -> notice code
|
// TODO : Insert new $xml -> notice code
|
||||||
|
|
||||||
@ -254,7 +262,6 @@ class SalmonAction extends Action
|
|||||||
function ensureProfile()
|
function ensureProfile()
|
||||||
{
|
{
|
||||||
$actor = $this->act->actor;
|
$actor = $this->act->actor;
|
||||||
common_log(LOG_DEBUG, "Received salmon bit: " . var_export($this->act, true));
|
|
||||||
if (empty($actor->id)) {
|
if (empty($actor->id)) {
|
||||||
common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
|
common_log(LOG_ERR, "broken actor: " . var_export($actor, true));
|
||||||
throw new Exception("Received a salmon slap from unidentified actor.");
|
throw new Exception("Received a salmon slap from unidentified actor.");
|
||||||
|
@ -56,7 +56,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||||
'profile_id' => DB_DATAOBJECT_INT,
|
'profile_id' => DB_DATAOBJECT_INT,
|
||||||
'group_id' => DB_DATAOBJECT_INT,
|
'group_id' => DB_DATAOBJECT_INT,
|
||||||
'feeduri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
'feeduri' => DB_DATAOBJECT_STR,
|
||||||
'salmonuri' => DB_DATAOBJECT_STR,
|
'salmonuri' => DB_DATAOBJECT_STR,
|
||||||
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
|
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
|
||||||
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
|
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
|
||||||
@ -71,7 +71,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
new ColumnDef('group_id', 'integer',
|
new ColumnDef('group_id', 'integer',
|
||||||
null, true, 'UNI'),
|
null, true, 'UNI'),
|
||||||
new ColumnDef('feeduri', 'varchar',
|
new ColumnDef('feeduri', 'varchar',
|
||||||
255, false, 'UNI'),
|
255, true, 'UNI'),
|
||||||
new ColumnDef('salmonuri', 'text',
|
new ColumnDef('salmonuri', 'text',
|
||||||
null, true),
|
null, true),
|
||||||
new ColumnDef('created', 'datetime',
|
new ColumnDef('created', 'datetime',
|
||||||
@ -272,7 +272,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
* @return bool true on success, false on failure
|
* @return bool true on success, false on failure
|
||||||
* @throws ServerException if feed state is not valid
|
* @throws ServerException if feed state is not valid
|
||||||
*/
|
*/
|
||||||
public function subscribe($mode='subscribe')
|
public function subscribe()
|
||||||
{
|
{
|
||||||
$feedsub = FeedSub::ensureFeed($this->feeduri);
|
$feedsub = FeedSub::ensureFeed($this->feeduri);
|
||||||
if ($feedsub->sub_state == 'active' || $feedsub->sub_state == 'subscribe') {
|
if ($feedsub->sub_state == 'active' || $feedsub->sub_state == 'subscribe') {
|
||||||
@ -506,7 +506,7 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
$discover = new FeedDiscovery();
|
$discover = new FeedDiscovery();
|
||||||
$feeduri = $discover->discoverFromURL($profile_uri);
|
$feeduri = $discover->discoverFromURL($profile_uri);
|
||||||
|
|
||||||
$feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
|
//$feedsub = FeedSub::ensureFeed($feeduri, $discover->feed);
|
||||||
$huburi = $discover->getAtomLink('hub');
|
$huburi = $discover->getAtomLink('hub');
|
||||||
$salmonuri = $discover->getAtomLink('salmon');
|
$salmonuri = $discover->getAtomLink('salmon');
|
||||||
|
|
||||||
@ -665,6 +665,20 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
throw new ServerException("No profile URI");
|
throw new ServerException("No profile URI");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$feeduri || !$salmonuri) {
|
||||||
|
// Get the canonical feed URI and check it
|
||||||
|
$discover = new FeedDiscovery();
|
||||||
|
$feeduri = $discover->discoverFromURL($homeuri);
|
||||||
|
|
||||||
|
$huburi = $discover->getAtomLink('hub');
|
||||||
|
$salmonuri = $discover->getAtomLink('salmon');
|
||||||
|
|
||||||
|
if (!$huburi) {
|
||||||
|
// We can only deal with folks with a PuSH hub
|
||||||
|
throw new FeedSubNoHubException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$profile = new Profile();
|
$profile = new Profile();
|
||||||
$profile->nickname = $nickname;
|
$profile->nickname = $nickname;
|
||||||
$profile->fullname = $actor->displayName;
|
$profile->fullname = $actor->displayName;
|
||||||
@ -686,13 +700,8 @@ class Ostatus_profile extends Memcached_DataObject
|
|||||||
// so we can leave it empty until later.
|
// so we can leave it empty until later.
|
||||||
$oprofile = new Ostatus_profile();
|
$oprofile = new Ostatus_profile();
|
||||||
$oprofile->uri = $homeuri;
|
$oprofile->uri = $homeuri;
|
||||||
if ($feeduri) {
|
$oprofile->feeduri = $feeduri;
|
||||||
// If we don't have these, we can look them up later.
|
$oprofile->salmonuri = $salmonuri;
|
||||||
$oprofile->feeduri = $feeduri;
|
|
||||||
if ($salmonuri) {
|
|
||||||
$oprofile->salmonuri = $salmonuri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$oprofile->profile_id = $profile->id;
|
$oprofile->profile_id = $profile->id;
|
||||||
|
|
||||||
$oprofile->created = common_sql_now();
|
$oprofile->created = common_sql_now();
|
||||||
|
@ -41,9 +41,12 @@ class Salmon
|
|||||||
$client->setBody($xml);
|
$client->setBody($xml);
|
||||||
$response = $client->post($endpoint_uri, $headers);
|
$response = $client->post($endpoint_uri, $headers);
|
||||||
} catch (HTTP_Request2_Exception $e) {
|
} catch (HTTP_Request2_Exception $e) {
|
||||||
|
common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($response->getStatus() != 200) {
|
if ($response->getStatus() != 200) {
|
||||||
|
common_log(LOG_ERR, "Salmon at $endpoint_uri returned status " .
|
||||||
|
$response->getStatus() . ': ' . $response->getBody());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user