[buddypress-trac] [BuddyPress Trac] #5389: Mark notifications as read when the item (blog post, private message thread and so on) is visited

buddypress-trac noreply at wordpress.org
Mon Feb 17 00:08:35 UTC 2014


#5389: Mark notifications as read when the item (blog post, private message thread
and so on) is visited
--------------------------+------------------------------
 Reporter:  henry.wright  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Core          |     Version:  1.9.2
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+------------------------------

Comment (by henry.wright):

 I've been trying to clear at-mention notifications when the at-mention is
 in a blog post or a blog post comment and the blog post is visited but
 have hit a stumbling block.

 '''Failed solution:'''

 {{{
 function mark_read_single_at_mention_notification( $post_id ) {
     if ( is_single() ) {
         $user_id = bp_loggedin_user_id();

         $notifications = BP_Notifications_Notification::get( array(
             'user_id' => $user_id,
             'is_new' => true,
         ) );

         if ( $notifications ) {
             foreach( $notifications as $notification ) {

                 // get the activity details
                 $activity = new BP_Activity_Activity(
 $notification->item_id );

                 if ( isset( $activity ) ) {
                     $comment = get_comment( $activity->secondary_item_id
 );

                     if ( $comment ) {
                         $id = $comment->comment_post_ID;

                         if ( $id == $post_id ) {
 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(),
 $notification->item_id, 'activity', 'new_at_mention' );
                         }
                     }
                 }
             }
         }
     }
 }
 add_action( 'init', 'mark_read_single_at_mention_notification' );
 }}}

 '''Reason for failure:'''

 Activity items can be deleted. Therefore, it is useless doing {{{$activity
 = new BP_Activity_Activity( $notification->item_id );}}}. If the activity
 item is deleted I'm not sure there is a way to associate the notification
 with the comment's parent post ID.

 '''Proposal:'''

 Capture the comment's parent post ID when recording the notification.

 This is what is currently captured:

 {{{
 bp_notifications_add_notification( array(
     'user_id'           => $receiver_user_id,
     'item_id'           => $activity->id,
     'secondary_item_id' => $activity->user_id,
     'component_name'    => buddypress()->activity->id,
     'component_action'  => 'new_at_mention',
     'date_notified'     => bp_core_current_time(),
     'is_new'            => 1,
 ) );
 }}}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5389#comment:3>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list