diff --git a/QvitterPlugin.php b/QvitterPlugin.php index d3cfe08..7b2278a 100644 --- a/QvitterPlugin.php +++ b/QvitterPlugin.php @@ -678,9 +678,33 @@ class QvitterPlugin extends Plugin { if($notice->profile_id != $profile->id) { $this->insertNotification($notice->profile_id, $profile->id, 'like', $notice->id); } + + // mark reply and mention notifications as seen if i'm liking a notice i'm notified about + self::markNotificationAsSeen($notice->id,$profile->id,'mention'); + self::markNotificationAsSeen($notice->id,$profile->id,'reply'); } + /** + * Mark single notification as seen + */ + public function markNotificationAsSeen($notice_id, $to_profile_id, $ntype) + { + $notification_to_mark_as_seen = QvitterNotification::pkeyGet(array( + 'is_seen' => 0, + 'notice_id' => $notice_id, + 'to_profile_id' => $to_profile_id, + 'ntype' => $ntype + )); + if($notification_to_mark_as_seen instanceof QvitterNotification) { + $orig = clone($notification_to_mark_as_seen); + $notification_to_mark_as_seen->is_seen = 1; + $notification_to_mark_as_seen->update($orig); + } + } + + + /** * Remove likes in notification table on dislike */ @@ -712,16 +736,8 @@ class QvitterPlugin extends Plugin { // mark reply/mention-notifications as read if we're replying to a notice we're notified about if($notice->reply_to) { - - $notification_to_mark_as_seen = QvitterNotification::pkeyGet(array('is_seen' => 0, - 'notice_id' => $notice->reply_to, - 'to_profile_id' => $notice->profile_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); - } + self::markNotificationAsSeen($notice->reply_to,$notice->profile_id,'mention'); + self::markNotificationAsSeen($notice->reply_to,$notice->profile_id,'reply'); } // repeats @@ -729,7 +745,11 @@ class QvitterPlugin extends Plugin { $repeated_notice = Notice::getKV('id', $notice->repeat_of); if ($repeated_notice instanceof Notice) { $this->insertNotification($repeated_notice->profile_id, $notice->profile_id, 'repeat', $repeated_notice->id); - } + + // mark reply/mention-notifications as read if we're repeating to a notice we're notified about + self::markNotificationAsSeen($repeated_notice->id,$notice->profile_id,'mention'); + self::markNotificationAsSeen($repeated_notice->id,$notice->profile_id,'reply'); + } } // replies and mentions (no notifications for these if this is a repeat) diff --git a/actions/apifavsandrepeats.php b/actions/apifavsandrepeats.php index d3487ea..c7a2139 100644 --- a/actions/apifavsandrepeats.php +++ b/actions/apifavsandrepeats.php @@ -46,7 +46,7 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction { parent::prepare($args); - $this->notice_id = $this->trimmed('notice_id'); + $this->notice_id = $this->trimmed('notice_id'); $this->original = Notice::getKV('id', $this->notice_id); @@ -80,20 +80,30 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction protected function handle() { parent::handle(); - - + + + // since this api method is in practice only used when expanding a + // notice, we can assume the user has seen the notice in question, + // an no longer need a notification about it. mark reply/mention- + // notifications tied to this notice and the current profile as read + if($this->auth_user) { + QvitterPlugin::markNotificationAsSeen($this->notice_id,$this->auth_user->id,'mention'); + QvitterPlugin::markNotificationAsSeen($this->notice_id,$this->auth_user->id,'reply'); + } + + // favs $fave = new Fave(); - $fave->selectAdd(); + $fave->selectAdd(); $fave->selectAdd('user_id'); - $fave->selectAdd('modified'); + $fave->selectAdd('modified'); $fave->notice_id = $this->original->id; $fave->orderBy('modified'); if (!is_null($this->cnt)) { $fave->limit(0, $this->cnt); } $fav_ids = $fave->fetchAll('user_id', 'modified'); - + // get nickname and profile image $fav_ids_with_profile_data = array(); $i=0; @@ -101,29 +111,29 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction $profile = Profile::getKV('id', $id); $fav_ids_with_profile_data[$i]['user_id'] = $id; $fav_ids_with_profile_data[$i]['nickname'] = $profile->nickname; - $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname; + $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname; $fav_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; - $fav_ids_with_profile_data[$i]['time'] = strtotime($time); + $fav_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); - $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; + $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; - } - - + } + + // repeats $notice = new Notice(); $notice->selectAdd(); // clears it - $notice->selectAdd('profile_id'); - $notice->selectAdd('created'); + $notice->selectAdd('profile_id'); + $notice->selectAdd('created'); $notice->repeat_of = $this->original->id; $notice->orderBy('created, id'); // NB: asc! if (!is_null($this->cnt)) { $notice->limit(0, $this->cnt); } $repeat_ids = $notice->fetchAll('profile_id','created'); - + // get nickname and profile image $repeat_ids_with_profile_data = array(); $i=0; @@ -131,18 +141,18 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction $profile = Profile::getKV('id', $id); $repeat_ids_with_profile_data[$i]['user_id'] = $id; $repeat_ids_with_profile_data[$i]['nickname'] = $profile->nickname; - $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname; - $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; - $repeat_ids_with_profile_data[$i]['time'] = strtotime($time); + $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname; + $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; + $repeat_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); - $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; + $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; - } - + } + $favs_and_repeats = array('favs'=>$fav_ids_with_profile_data,'repeats'=>$repeat_ids_with_profile_data); - + $this->initDocument('json'); $this->showJsonObjects($favs_and_repeats); $this->endDocument('json'); @@ -162,6 +172,6 @@ class ApiFavsAndRepeatsAction extends ApiPrivateAuthAction return true; } - - + + }