implementation of #157 and no notifications from blocked profiles

This commit is contained in:
Hannes Mannerheim 2015-05-19 16:51:42 +02:00
parent e49c8fd654
commit c3e2a0d19a

View File

@ -591,8 +591,17 @@ class QvitterPlugin extends Plugin {
function insertNotification($to_profile_id, $from_profile_id, $ntype, $notice_id=false) function insertNotification($to_profile_id, $from_profile_id, $ntype, $notice_id=false)
{ {
// no notifications from blocked profiles
$to_user = User::getKV('id', $to_profile_id);
$from_user = Profile::getKV($from_profile_id);
if ($to_user instanceof User && $to_user->hasBlocked($from_user)) {
return false;
}
// never notify myself // never notify myself
if($to_profile_id != $from_profile_id) { if($to_profile_id == $from_profile_id) {
return false;
}
// insert // insert
$notif = new QvitterNotification(); $notif = new QvitterNotification();
@ -605,7 +614,7 @@ class QvitterPlugin extends Plugin {
common_log_db_error($notif, 'INSERT', __FILE__); common_log_db_error($notif, 'INSERT', __FILE__);
return false; return false;
} }
}
return true; return true;
} }
@ -650,6 +659,21 @@ class QvitterPlugin extends Plugin {
return true; return true;
} }
// mark reply/mention-notifications as read if we're replying to a notice we're notified about
if($notice->reply_to) {
$user = common_current_user();
$notification_to_mark_as_seen = QvitterNotification::pkeyGet(array('is_seen' => 0,
'notice_id' => $notice->reply_to,
'to_profile_id' => $user->id));
if($notification_to_mark_as_seen instanceof QvitterNotification
&& ($notification_to_mark_as_seen->ntype == 'mention' || $notification_to_mark_as_seen->ntype == 'reply')) {
$orig = clone($notification_to_mark_as_seen);
$notification_to_mark_as_seen->is_seen = 1;
$notification_to_mark_as_seen->update($orig);
}
}
// repeats // repeats
if ($notice->isRepeat()) { if ($notice->isRepeat()) {
$repeated_notice = Notice::getKV('id', $notice->repeat_of); $repeated_notice = Notice::getKV('id', $notice->repeat_of);
@ -684,12 +708,6 @@ class QvitterPlugin extends Plugin {
} }
$all_mentioned_user_ids[] = $mentioned->id; $all_mentioned_user_ids[] = $mentioned->id;
// Not from blocked profile
$mentioned_user = User::getKV('id', $mentioned->id);
if ($mentioned_user instanceof User && $mentioned_user->hasBlocked($sender)) {
continue;
}
// only notify if mentioned user is not already notified for reply // only notify if mentioned user is not already notified for reply
if($reply_notification_to != $mentioned->id && !empty($notice->id)) { if($reply_notification_to != $mentioned->id && !empty($notice->id)) {
$this->insertNotification($mentioned->id, $notice->profile_id, 'mention', $notice->id); $this->insertNotification($mentioned->id, $notice->profile_id, 'mention', $notice->id);