Add support for favor and disfavor notification
Added support for favoring and disfavoring in OStatusPlugin. Needed to represent the Notice as an activity:object, so added some code for that in lib/activity.php. Also, made some small changes to OStatusPlugin so it handled having a non-default argument $object correctly.
This commit is contained in:
parent
f3b08461bd
commit
96c6019638
|
@ -255,7 +255,7 @@ class OStatusPlugin extends Plugin
|
||||||
{
|
{
|
||||||
if ($user instanceof Profile) {
|
if ($user instanceof Profile) {
|
||||||
$profile = $user;
|
$profile = $user;
|
||||||
} else if ($user instanceof Profile) {
|
} else if ($user instanceof User) {
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
}
|
}
|
||||||
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
|
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
|
||||||
|
@ -353,30 +353,64 @@ class OStatusPlugin extends Plugin
|
||||||
// We have a local user subscribing to a remote profile; make the
|
// We have a local user subscribing to a remote profile; make the
|
||||||
// magic happen!
|
// magic happen!
|
||||||
|
|
||||||
$oprofile->notify($subscriber, ActivityVerb::FOLLOW);
|
$oprofile->notify($subscriber, ActivityVerb::FOLLOW, $oprofile);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEndUnsubscribe($subscriber, $other)
|
function onEndFavor($profile, $notice)
|
||||||
{
|
{
|
||||||
$user = User::staticGet('id', $subscriber->id);
|
// is the favorer a local user?
|
||||||
|
|
||||||
|
$user = User::staticGet('id', $profile->id);
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
|
// is the author an OStatus remote user?
|
||||||
|
|
||||||
|
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
|
||||||
|
|
||||||
if (empty($oprofile)) {
|
if (empty($oprofile)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have a local user subscribing to a remote profile; make the
|
// Local user faved an Ostatus profile's notice; notify them!
|
||||||
// magic happen!
|
|
||||||
|
|
||||||
$oprofile->notify($subscriber, ActivityVerb::UNFOLLOW);
|
$obj = ActivityObject::fromNotice($notice);
|
||||||
|
|
||||||
|
$oprofile->notify($profile,
|
||||||
|
ActivityVerb::FAVORITE,
|
||||||
|
$obj->asString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onEndDisfavor($profile, $notice)
|
||||||
|
{
|
||||||
|
// is the favorer a local user?
|
||||||
|
|
||||||
|
$user = User::staticGet('id', $profile->id);
|
||||||
|
|
||||||
|
if (empty($user)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// is the author an OStatus remote user?
|
||||||
|
|
||||||
|
$oprofile = Ostatus_profile::staticGet('profile_id', $notice->profile_id);
|
||||||
|
|
||||||
|
if (empty($oprofile)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local user faved an Ostatus profile's notice; notify them!
|
||||||
|
|
||||||
|
$obj = ActivityObject::fromNotice($notice);
|
||||||
|
|
||||||
|
$oprofile->notify($profile,
|
||||||
|
ActivityVerb::UNFAVORITE,
|
||||||
|
$obj->asString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,7 +307,7 @@ class Ostatus_profile extends Memcached_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $actor
|
* @param Profile $actor
|
||||||
* @param $verb eg Activity::SUBSCRIBE or Activity::JOIN
|
* @param $verb eg Activity::SUBSCRIBE or Activity::JOIN
|
||||||
* @param $object object of the action; if null, the remote entity itself is assumed
|
* @param string $object object of the action; if null, the remote entity itself is assumed
|
||||||
*/
|
*/
|
||||||
public function notify($actor, $verb, $object=null)
|
public function notify($actor, $verb, $object=null)
|
||||||
{
|
{
|
||||||
|
@ -319,7 +319,7 @@ class Ostatus_profile extends Memcached_DataObject
|
||||||
throw new ServerException("Invalid actor passed to " . __METHOD__ . ": " . $type);
|
throw new ServerException("Invalid actor passed to " . __METHOD__ . ": " . $type);
|
||||||
}
|
}
|
||||||
if ($object == null) {
|
if ($object == null) {
|
||||||
$object = $this;
|
$object = $this->asActivityNoun('object');
|
||||||
}
|
}
|
||||||
if ($this->salmonuri) {
|
if ($this->salmonuri) {
|
||||||
$text = 'update'; // @fixme
|
$text = 'update'; // @fixme
|
||||||
|
@ -345,7 +345,7 @@ class Ostatus_profile extends Memcached_DataObject
|
||||||
$entry->element('activity:verb', null, $verb);
|
$entry->element('activity:verb', null, $verb);
|
||||||
$entry->raw($actor->asAtomAuthor());
|
$entry->raw($actor->asAtomAuthor());
|
||||||
$entry->raw($actor->asActivityActor());
|
$entry->raw($actor->asActivityActor());
|
||||||
$entry->raw($object->asActivityNoun('object'));
|
$entry->raw($object);
|
||||||
$entry->elementEnd('entry');
|
$entry->elementEnd('entry');
|
||||||
|
|
||||||
$xml = $entry->getString();
|
$xml = $entry->getString();
|
||||||
|
|
|
@ -199,7 +199,7 @@ class ActivityObject
|
||||||
public $link;
|
public $link;
|
||||||
public $source;
|
public $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* This probably needs to be refactored
|
* This probably needs to be refactored
|
||||||
|
@ -209,8 +209,12 @@ class ActivityObject
|
||||||
* @param DOMElement $element DOM thing to turn into an Activity thing
|
* @param DOMElement $element DOM thing to turn into an Activity thing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function __construct($element)
|
function __construct($element = null)
|
||||||
{
|
{
|
||||||
|
if (empty($element)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->element = $element;
|
$this->element = $element;
|
||||||
|
|
||||||
if ($element->tagName == 'author') {
|
if ($element->tagName == 'author') {
|
||||||
|
@ -279,6 +283,53 @@ class ActivityObject
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromNotice($notice)
|
||||||
|
{
|
||||||
|
$object = new ActivityObject();
|
||||||
|
|
||||||
|
$object->type = ActivityObject::NOTE;
|
||||||
|
|
||||||
|
$object->id = $notice->uri;
|
||||||
|
$object->title = $notice->content;
|
||||||
|
$object->content = $notice->rendered;
|
||||||
|
$object->link = $notice->bestUrl();
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asString($tag='activity:object')
|
||||||
|
{
|
||||||
|
$xs = new XMLStringer(true);
|
||||||
|
|
||||||
|
$xs->elementStart($tag);
|
||||||
|
|
||||||
|
$xs->element('activity:object-type', null, $this->type);
|
||||||
|
|
||||||
|
$xs->element(self::ID, null, $this->id);
|
||||||
|
|
||||||
|
if (!empty($this->title)) {
|
||||||
|
$xs->element(self::TITLE, null, $this->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->summary)) {
|
||||||
|
$xs->element(self::SUMMARY, null, $this->summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->content)) {
|
||||||
|
// XXX: assuming HTML content here
|
||||||
|
$xs->element(self::CONTENT, array('type' => 'html'), $this->content);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($this->link)) {
|
||||||
|
$xs->element('link', array('rel' => 'alternate', 'type' => 'text/html'),
|
||||||
|
$this->content);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xs->elementEnd($tag);
|
||||||
|
|
||||||
|
return $xs->getString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user