forked from GNUsocial/gnu-social
OStatus: renamed feedinfo table to ostatus_profile -- will cover remote ostatus people and groups whether a subscription's active or not (maintains identity over unsub/resub, and between subscribers and subscribees)
This commit is contained in:
parent
e08657d56c
commit
8e6b52e899
@ -251,14 +251,14 @@ class OStatusPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
function onEndUnsubscribe($user, $other)
|
function onEndUnsubscribe($user, $other)
|
||||||
{
|
{
|
||||||
$feed = Feedinfo::staticGet('profile_id', $other->id);
|
$profile = Ostatus_profile::staticGet('profile_id', $other->id);
|
||||||
if ($feed) {
|
if ($feed) {
|
||||||
$sub = new Subscription();
|
$sub = new Subscription();
|
||||||
$sub->subscribed = $other->id;
|
$sub->subscribed = $other->id;
|
||||||
$sub->limit(1);
|
$sub->limit(1);
|
||||||
if (!$sub->find(true)) {
|
if (!$sub->find(true)) {
|
||||||
common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi");
|
common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi");
|
||||||
$feed->unsubscribe();
|
$profile->unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -269,7 +269,7 @@ class OStatusPlugin extends Plugin
|
|||||||
*/
|
*/
|
||||||
function onCheckSchema() {
|
function onCheckSchema() {
|
||||||
$schema = Schema::get();
|
$schema = Schema::get();
|
||||||
$schema->ensureTable('feedinfo', Feedinfo::schemaDef());
|
$schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
|
||||||
$schema->ensureTable('hubsub', HubSub::schemaDef());
|
$schema->ensureTable('hubsub', HubSub::schemaDef());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -182,9 +182,9 @@ class FeedSubSettingsAction extends ConnectSettingsAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->munger = $discover->feedMunger();
|
$this->munger = $discover->feedMunger();
|
||||||
$this->feedinfo = $this->munger->feedInfo();
|
$this->profile = $this->munger->ostatusProfile();
|
||||||
|
|
||||||
if ($this->feedinfo->huburi == '' && !common_config('feedsub', 'nohub')) {
|
if ($this->profile->huburi == '' && !common_config('feedsub', 'nohub')) {
|
||||||
$this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
|
$this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -196,13 +196,13 @@ class FeedSubSettingsAction extends ConnectSettingsAction
|
|||||||
{
|
{
|
||||||
if ($this->validateFeed()) {
|
if ($this->validateFeed()) {
|
||||||
$this->preview = true;
|
$this->preview = true;
|
||||||
$this->feedinfo = Feedinfo::ensureProfile($this->munger);
|
$this->profile = Ostatus_profile::ensureProfile($this->munger);
|
||||||
|
|
||||||
// If not already in use, subscribe to updates via the hub
|
// If not already in use, subscribe to updates via the hub
|
||||||
if ($this->feedinfo->sub_start) {
|
if ($this->profile->sub_start) {
|
||||||
common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->feedinfo->feeduri} last subbed {$this->feedinfo->sub_start}");
|
common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}");
|
||||||
} else {
|
} else {
|
||||||
$ok = $this->feedinfo->subscribe();
|
$ok = $this->profile->subscribe();
|
||||||
common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
|
common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
$this->showForm(_m('Feed subscription failed! Bad response from hub.'));
|
$this->showForm(_m('Feed subscription failed! Bad response from hub.'));
|
||||||
@ -212,15 +212,15 @@ class FeedSubSettingsAction extends ConnectSettingsAction
|
|||||||
|
|
||||||
// And subscribe the current user to the local profile
|
// And subscribe the current user to the local profile
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
$profile = $this->feedinfo->getProfile();
|
$profile = $this->profile->getLocalProfile();
|
||||||
if (!$profile) {
|
if (!$profile) {
|
||||||
throw new ServerException("Feed profile was not saved properly.");
|
throw new ServerException("Feed profile was not saved properly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->feedinfo->isGroup()) {
|
if ($this->profile->isGroup()) {
|
||||||
if ($user->isMember($profile)) {
|
if ($user->isMember($profile)) {
|
||||||
$this->showForm(_m('Already a member!'));
|
$this->showForm(_m('Already a member!'));
|
||||||
} elseif (Group_member::join($this->feedinfo->group_id, $user->id)) {
|
} elseif (Group_member::join($this->profile->group_id, $user->id)) {
|
||||||
$this->showForm(_m('Joined remote group!'));
|
$this->showForm(_m('Joined remote group!'));
|
||||||
} else {
|
} else {
|
||||||
$this->showForm(_m('Remote group join failed!'));
|
$this->showForm(_m('Remote group join failed!'));
|
||||||
@ -247,7 +247,7 @@ class FeedSubSettingsAction extends ConnectSettingsAction
|
|||||||
|
|
||||||
function previewFeed()
|
function previewFeed()
|
||||||
{
|
{
|
||||||
$feedinfo = $this->munger->feedinfo();
|
$profile = $this->munger->ostatusProfile();
|
||||||
$notice = $this->munger->notice(0, true); // preview
|
$notice = $this->munger->notice(0, true); // preview
|
||||||
|
|
||||||
if ($notice) {
|
if ($notice) {
|
||||||
|
@ -164,9 +164,9 @@ class OStatusSubAction extends Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->munger = $discover->feedMunger();
|
$this->munger = $discover->feedMunger();
|
||||||
$this->feedinfo = $this->munger->feedInfo();
|
$this->profile = $this->munger->ostatusProfile();
|
||||||
|
|
||||||
if ($this->feedinfo->huburi == '') {
|
if ($this->profile->huburi == '') {
|
||||||
$this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
|
$this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -178,13 +178,13 @@ class OStatusSubAction extends Action
|
|||||||
{
|
{
|
||||||
if ($this->validateFeed()) {
|
if ($this->validateFeed()) {
|
||||||
$this->preview = true;
|
$this->preview = true;
|
||||||
$this->feedinfo = Feedinfo::ensureProfile($this->munger);
|
$this->profile = Ostatus_profile::ensureProfile($this->munger);
|
||||||
|
|
||||||
// If not already in use, subscribe to updates via the hub
|
// If not already in use, subscribe to updates via the hub
|
||||||
if ($this->feedinfo->sub_start) {
|
if ($this->profile->sub_start) {
|
||||||
common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->feedinfo->feeduri} last subbed {$this->feedinfo->sub_start}");
|
common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}");
|
||||||
} else {
|
} else {
|
||||||
$ok = $this->feedinfo->subscribe();
|
$ok = $this->profile->subscribe();
|
||||||
common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
|
common_log(LOG_INFO, __METHOD__ . ": sub was $ok");
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
$this->showForm(_m('Feed subscription failed! Bad response from hub.'));
|
$this->showForm(_m('Feed subscription failed! Bad response from hub.'));
|
||||||
@ -194,7 +194,7 @@ class OStatusSubAction extends Action
|
|||||||
|
|
||||||
// And subscribe the current user to the local profile
|
// And subscribe the current user to the local profile
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
$profile = $this->feedinfo->getProfile();
|
$profile = $this->profile->getProfile();
|
||||||
|
|
||||||
if ($user->isSubscribed($profile)) {
|
if ($user->isSubscribed($profile)) {
|
||||||
$this->showForm(_m('Already subscribed!'));
|
$this->showForm(_m('Already subscribed!'));
|
||||||
@ -209,7 +209,7 @@ class OStatusSubAction extends Action
|
|||||||
|
|
||||||
function previewFeed()
|
function previewFeed()
|
||||||
{
|
{
|
||||||
$feedinfo = $this->munger->feedinfo();
|
$profile = $this->munger->ostatusProfile();
|
||||||
$notice = $this->munger->notice(0, true); // preview
|
$notice = $this->munger->notice(0, true); // preview
|
||||||
|
|
||||||
if ($notice) {
|
if ($notice) {
|
||||||
|
@ -48,9 +48,9 @@ class PushCallbackAction extends Action
|
|||||||
throw new ServerException('Empty or invalid feed id', 400);
|
throw new ServerException('Empty or invalid feed id', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo = Feedinfo::staticGet('id', $feedid);
|
$profile = Ostatus_profile::staticGet('id', $feedid);
|
||||||
if (!$feedinfo) {
|
if (!$profile) {
|
||||||
throw new ServerException('Unknown feed id ' . $feedid, 400);
|
throw new ServerException('Unknown OStatus/PuSH feed id ' . $feedid, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hmac = '';
|
$hmac = '';
|
||||||
@ -59,7 +59,7 @@ class PushCallbackAction extends Action
|
|||||||
}
|
}
|
||||||
|
|
||||||
$post = file_get_contents('php://input');
|
$post = file_get_contents('php://input');
|
||||||
$feedinfo->postUpdates($post, $hmac);
|
$profile->postUpdates($post, $hmac);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,8 +78,8 @@ class PushCallbackAction extends Action
|
|||||||
throw new ServerException("Bogus hub callback: bad mode", 404);
|
throw new ServerException("Bogus hub callback: bad mode", 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo = Feedinfo::staticGet('feeduri', $topic);
|
$profile = Ostatus_profile::staticGet('feeduri', $topic);
|
||||||
if (!$feedinfo) {
|
if (!$profile) {
|
||||||
common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic");
|
common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic");
|
||||||
throw new ServerException("Bogus hub callback: unknown feed", 404);
|
throw new ServerException("Bogus hub callback: unknown feed", 404);
|
||||||
}
|
}
|
||||||
@ -93,16 +93,16 @@ class PushCallbackAction extends Action
|
|||||||
// OK!
|
// OK!
|
||||||
if ($mode == 'subscribe') {
|
if ($mode == 'subscribe') {
|
||||||
common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
|
common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
|
||||||
$feedinfo->sub_start = common_sql_date(time());
|
$profile->sub_start = common_sql_date(time());
|
||||||
if ($lease_seconds > 0) {
|
if ($lease_seconds > 0) {
|
||||||
$feedinfo->sub_end = common_sql_date(time() + $lease_seconds);
|
$profile->sub_end = common_sql_date(time() + $lease_seconds);
|
||||||
} else {
|
} else {
|
||||||
$feedinfo->sub_end = null;
|
$profile->sub_end = null;
|
||||||
}
|
}
|
||||||
$feedinfo->update();
|
$profile->update();
|
||||||
} else {
|
} else {
|
||||||
common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic");
|
common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic");
|
||||||
$feedinfo->delete();
|
$profile->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
print $challenge;
|
print $challenge;
|
||||||
|
@ -25,17 +25,17 @@
|
|||||||
/*
|
/*
|
||||||
PuSH subscription flow:
|
PuSH subscription flow:
|
||||||
|
|
||||||
$feedinfo->subscribe()
|
$profile->subscribe()
|
||||||
generate random verification token
|
generate random verification token
|
||||||
save to verify_token
|
save to verify_token
|
||||||
sends a sub request to the hub...
|
sends a sub request to the hub...
|
||||||
|
|
||||||
feedsub/callback
|
main/push/callback
|
||||||
hub sends confirmation back to us via GET
|
hub sends confirmation back to us via GET
|
||||||
We verify the request, then echo back the challenge.
|
We verify the request, then echo back the challenge.
|
||||||
On our end, we save the time we subscribed and the lease expiration
|
On our end, we save the time we subscribed and the lease expiration
|
||||||
|
|
||||||
feedsub/callback
|
main/push/callback
|
||||||
hub sends us updates via POST
|
hub sends us updates via POST
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -51,23 +51,27 @@ class FeedDBException extends FeedSubException
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Feedinfo extends Memcached_DataObject
|
class Ostatus_profile extends Memcached_DataObject
|
||||||
{
|
{
|
||||||
public $__table = 'feedinfo';
|
public $__table = 'ostatus_profile';
|
||||||
|
|
||||||
public $id;
|
public $id;
|
||||||
public $profile_id;
|
public $profile_id;
|
||||||
|
public $group_id;
|
||||||
|
|
||||||
public $feeduri;
|
public $feeduri;
|
||||||
public $homeuri;
|
public $homeuri;
|
||||||
public $huburi;
|
|
||||||
|
|
||||||
// PuSH subscription data
|
// PuSH subscription data
|
||||||
|
public $huburi;
|
||||||
public $secret;
|
public $secret;
|
||||||
public $verify_token;
|
public $verify_token;
|
||||||
|
public $sub_state; // subscribe, active, unsubscribe
|
||||||
public $sub_start;
|
public $sub_start;
|
||||||
public $sub_end;
|
public $sub_end;
|
||||||
|
|
||||||
|
public $salmonuri;
|
||||||
|
|
||||||
public $created;
|
public $created;
|
||||||
public $lastupdate;
|
public $lastupdate;
|
||||||
|
|
||||||
@ -96,6 +100,7 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
'huburi' => DB_DATAOBJECT_STR,
|
'huburi' => DB_DATAOBJECT_STR,
|
||||||
'secret' => DB_DATAOBJECT_STR,
|
'secret' => DB_DATAOBJECT_STR,
|
||||||
'verify_token' => DB_DATAOBJECT_STR,
|
'verify_token' => DB_DATAOBJECT_STR,
|
||||||
|
'sub_state' => DB_DATAOBJECT_STR,
|
||||||
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
|
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
|
||||||
'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
|
'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME,
|
||||||
'salmonuri' => DB_DATAOBJECT_STR,
|
'salmonuri' => DB_DATAOBJECT_STR,
|
||||||
@ -126,6 +131,8 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
32, true),
|
32, true),
|
||||||
new ColumnDef('secret', 'varchar',
|
new ColumnDef('secret', 'varchar',
|
||||||
64, true),
|
64, true),
|
||||||
|
new ColumnDef('sub_state', "enum('subscribe','active','unsubscribe')",
|
||||||
|
null, true),
|
||||||
new ColumnDef('sub_start', 'datetime',
|
new ColumnDef('sub_start', 'datetime',
|
||||||
null, true),
|
null, true),
|
||||||
new ColumnDef('sub_end', 'datetime',
|
new ColumnDef('sub_end', 'datetime',
|
||||||
@ -175,7 +182,7 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
* Fetch the StatusNet-side profile for this feed
|
* Fetch the StatusNet-side profile for this feed
|
||||||
* @return Profile
|
* @return Profile
|
||||||
*/
|
*/
|
||||||
public function getProfile()
|
public function getLocalProfile()
|
||||||
{
|
{
|
||||||
return Profile::staticGet('id', $this->profile_id);
|
return Profile::staticGet('id', $this->profile_id);
|
||||||
}
|
}
|
||||||
@ -183,23 +190,23 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
/**
|
/**
|
||||||
* @param FeedMunger $munger
|
* @param FeedMunger $munger
|
||||||
* @param boolean $isGroup is this a group record?
|
* @param boolean $isGroup is this a group record?
|
||||||
* @return Feedinfo
|
* @return Ostatus_profile
|
||||||
*/
|
*/
|
||||||
public static function ensureProfile($munger)
|
public static function ensureProfile($munger)
|
||||||
{
|
{
|
||||||
$feedinfo = $munger->feedinfo();
|
$entity = $munger->ostatusProfile();
|
||||||
|
|
||||||
$current = self::staticGet('feeduri', $feedinfo->feeduri);
|
$current = self::staticGet('feeduri', $entity->feeduri);
|
||||||
if ($current) {
|
if ($current) {
|
||||||
// @fixme we should probably update info as necessary
|
// @fixme we should probably update info as necessary
|
||||||
return $current;
|
return $current;
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo->query('BEGIN');
|
$entity->query('BEGIN');
|
||||||
|
|
||||||
// Awful hack! Awful hack!
|
// Awful hack! Awful hack!
|
||||||
$feedinfo->verify = common_good_rand(16);
|
$entity->verify = common_good_rand(16);
|
||||||
$feedinfo->secret = common_good_rand(32);
|
$entity->secret = common_good_rand(32);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$profile = $munger->profile();
|
$profile = $munger->profile();
|
||||||
@ -223,8 +230,8 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
$profile->setOriginal($filename);
|
$profile->setOriginal($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo->profile_id = $profile->id;
|
$entity->profile_id = $profile->id;
|
||||||
if ($feedinfo->isGroup()) {
|
if ($entity->isGroup()) {
|
||||||
$group = new User_group();
|
$group = new User_group();
|
||||||
$group->nickname = $profile->nickname . '@remote'; // @fixme
|
$group->nickname = $profile->nickname . '@remote'; // @fixme
|
||||||
$group->fullname = $profile->fullname;
|
$group->fullname = $profile->fullname;
|
||||||
@ -237,21 +244,21 @@ class Feedinfo extends Memcached_DataObject
|
|||||||
$group->setOriginal($filename);
|
$group->setOriginal($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo->group_id = $group->id;
|
$entity->group_id = $group->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $feedinfo->insert();
|
$result = $entity->insert();
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
throw new FeedDBException($feedinfo);
|
throw new FeedDBException($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
$feedinfo->query('COMMIT');
|
$entity->query('COMMIT');
|
||||||
} catch (FeedDBException $e) {
|
} catch (FeedDBException $e) {
|
||||||
common_log_db_error($e->obj, 'INSERT', __FILE__);
|
common_log_db_error($e->obj, 'INSERT', __FILE__);
|
||||||
$feedinfo->query('ROLLBACK');
|
$entity->query('ROLLBACK');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $feedinfo;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -83,17 +83,17 @@ class FeedMunger
|
|||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function feedinfo()
|
function ostatusProfile()
|
||||||
{
|
{
|
||||||
$feedinfo = new Feedinfo();
|
$profile = new Ostatus_profile();
|
||||||
$feedinfo->feeduri = $this->url;
|
$profile->feeduri = $this->url;
|
||||||
$feedinfo->homeuri = $this->feed->link;
|
$profile->homeuri = $this->feed->link;
|
||||||
$feedinfo->huburi = $this->getHubLink();
|
$profile->huburi = $this->getHubLink();
|
||||||
$salmon = $this->getSalmonLink();
|
$salmon = $this->getSalmonLink();
|
||||||
if ($salmon) {
|
if ($salmon) {
|
||||||
$feedinfo->salmonuri = $salmon;
|
$profile->salmonuri = $salmon;
|
||||||
}
|
}
|
||||||
return $feedinfo;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAtomLink($item, $attribs=array())
|
function getAtomLink($item, $attribs=array())
|
||||||
@ -258,9 +258,7 @@ class FeedMunger
|
|||||||
{
|
{
|
||||||
// hack hack hack
|
// hack hack hack
|
||||||
// should get profile for this entry's author...
|
// should get profile for this entry's author...
|
||||||
$feed = new Feedinfo();
|
$remote = Ostatus_profile::staticGet('feeduri', $this->getSelfLink());
|
||||||
$feed->feeduri = $self;
|
|
||||||
$feed = Feedinfo::staticGet('feeduri', $this->getSelfLink());
|
|
||||||
if ($feed) {
|
if ($feed) {
|
||||||
return $feed->profile_id;
|
return $feed->profile_id;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user