Do proper Activity-plugin based mention notification

This commit is contained in:
Mikael Nordfeldth 2014-07-06 16:37:26 +02:00
parent eda0e25147
commit 2eea7a2d4b
6 changed files with 67 additions and 36 deletions

View File

@ -1437,3 +1437,11 @@ EndShowAttachmentRepresentation: Executed after Attachment representation, despi
ShowUnsupportedAttachmentRepresentation: Attachment representation, full file (or in rare cases thumbnails/previews).
- $out: HTMLOutputter class to use for outputting HTML.
- $file: 'File' object which we're going to show representation for.
StartNotifyMentioned: During notice distribution, we send notifications (email, im...) to the profiles who were somehow mentioned.
- $stored: Notice object that is being distributed.
- &$mentioned_ids: Array of profile IDs (not just for local users) who got mentioned by the notice.
EndNotifyMentioned: During notice distribution, we send notifications (email, im...) to the profiles who were somehow mentioned.
- $stored: Notice object that is being distributed.
- $mentioned_ids: Array of profile IDs (not just for local users) who got mentioned by the notice.

View File

@ -577,7 +577,7 @@ class Notice extends Managed_DataObject
}
// If it's a repeat, the reply_to should be to the original
if (!empty($reply->repeat_of)) {
if ($reply->isRepeat()) {
$notice->reply_to = $reply->repeat_of;
} else {
$notice->reply_to = $reply->id;
@ -619,7 +619,7 @@ class Notice extends Managed_DataObject
}
if (empty($verb)) {
if (!empty($notice->repeat_of)) {
if ($notice->isRepeat()) {
$notice->verb = ActivityVerb::SHARE;
$notice->object_type = ActivityObject::ACTIVITY;
} else {
@ -957,7 +957,7 @@ class Notice extends Managed_DataObject
self::blow('notice:list-ids:conversation:%s', $this->conversation);
self::blow('conversation:notice_count:%d', $this->conversation);
if (!empty($this->repeat_of)) {
if ($this->isRepeat()) {
// XXX: we should probably only use one of these
$this->blowStream('notice:repeats:%d', $this->repeat_of);
self::blow('notice:list-ids:repeat_of:%d', $this->repeat_of);
@ -1333,7 +1333,7 @@ class Notice extends Managed_DataObject
// Exclude any deleted, non-local, or blocking recipients.
$profile = $this->getProfile();
$originalProfile = null;
if ($this->repeat_of) {
if ($this->isRepeat()) {
// Check blocks against the original notice's poster as well.
$original = Notice::getKV('id', $this->repeat_of);
if ($original instanceof Notice) {
@ -1547,7 +1547,7 @@ class Notice extends Managed_DataObject
{
// Don't save reply data for repeats
if (!empty($this->repeat_of)) {
if ($this->isRepeat()) {
return array();
}
@ -1670,17 +1670,19 @@ class Notice extends Managed_DataObject
{
// Don't send reply notifications for repeats
if (!empty($this->repeat_of)) {
if ($this->isRepeat()) {
return array();
}
$recipientIds = $this->getReplies();
foreach ($recipientIds as $recipientId) {
$user = User::getKV('id', $recipientId);
if ($user instanceof User) {
mail_notify_attn($user, $this);
if (Event::handle('StartNotifyMentioned', array($this, &$recipientIds))) {
foreach ($recipientIds as $recipientId) {
$user = User::getKV('id', $recipientId);
if ($user instanceof User) {
mail_notify_attn($user, $this);
}
}
Event::handle('EndNotifyMentioned', array($this, $recipientIds));
}
}
@ -2424,6 +2426,11 @@ class Notice extends Managed_DataObject
$this->is_local == Notice::LOCAL_NONPUBLIC);
}
public function isRepeat()
{
return !empty($this->repeat_of);
}
/**
* Get the list of hash tags saved with this notice.
*

View File

@ -223,6 +223,11 @@ abstract class ActivityHandlerPlugin extends Plugin
*/
abstract function deleteRelated(Notice $notice);
protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{
// pass through silently by default
}
/**
* Called when generating Atom XML ActivityStreams output from an
* ActivityObject belonging to this plugin. Gives the plugin
@ -271,11 +276,28 @@ abstract class ActivityHandlerPlugin extends Plugin
*/
function onNoticeDeleteRelated(Notice $notice)
{
if (!$this->isMyNotice($notice)) {
if ($this->isMyNotice($notice)) {
$this->deleteRelated($notice);
}
// Always continue this event in our activity handling plugins.
return true;
}
/**
* @param Notice $stored The notice being distributed
* @param array &$mentioned_ids List of profiles (from $stored->getReplies())
*/
public function onStartNotifyMentioned(Notice $stored, array &$mentioned_ids)
{
if (!$this->isMyNotice($stored)) {
return true;
}
$this->deleteRelated($notice);
$this->notifyMentioned($stored, $mentioned_ids);
// If it was _our_ notice, only we should do anything with the mentions.
return false;
}
/**

View File

@ -191,6 +191,18 @@ class FavoritePlugin extends ActivityHandlerPlugin
}
}
protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{
require_once INSTALLDIR.'/lib/mail.php';
foreach ($mentioned_ids as $id) {
$mentioned = User::getKV('id', $id);
if ($mentioned instanceof User && $mentioned->id != $stored->profile_id) {
mail_notify_fave($mentioned, $stored->getProfile(), $stored->getParent());
}
}
}
// API stuff
/**

View File

@ -31,8 +31,6 @@
if (!defined('GNUSOCIAL')) { exit(1); }
require_once INSTALLDIR.'/lib/mail.php';
/**
* FavorAction class.
*
@ -91,7 +89,6 @@ class FavorAction extends FormAction
$stored = Notice::saveActivity($act, $this->scoped,
array('uri'=>$act->id));
$this->notify($stored, $this->scoped->getUser());
Fave::blowCacheForProfileId($this->scoped->id);
return _('Favorited the notice');
@ -104,24 +101,4 @@ class FavorAction extends FormAction
$disfavor->show();
}
}
/**
* Notifies a user when their notice is favorited.
*
* @param class $notice favorited notice
* @param class $user user declaring a favorite
*
* @return void
*/
function notify($notice, $user)
{
$other = User::getKV('id', $notice->profile_id);
if ($other && $other->id != $user->id) {
if ($other->email && $other->emailnotifyfav) {
mail_notify_fave($other, $user, $notice);
}
// XXX: notify by IM
// XXX: notify by SMS
}
}
}

View File

@ -324,6 +324,11 @@ class Fave extends Managed_DataObject
return $object;
}
public function getAttentionArray() {
// not all objects can/should carry attentions, so we don't require extending this
// the format should be an array with URIs to mentioned profiles
return array();
}
public function getTarget()
{