Skip to:
Content

BuddyPress.org

Changeset 7832


Ignore:
Timestamp:
02/08/2014 06:26:52 PM (10 years ago)
Author:
boonebgorges
Message:

Improve logic for marking at-mention notifications as read

In previous iterations, at-mention notifications were marked as read in the
following cases:

  • when a user visited his own activity page
  • when a user visited his own mention page
  • when a user visited a single-activity permalink page

When the new notifications component was introduced in BP 1.9, the old
notification functions were swapped out one-for-one with the new correlates.
However, this introduced a bug where a logged-out user visiting one of the
pages listed above would mark at-mention items as read for *all* users (due to
the user_id field being null, and the user_id WHERE clause being excluded from
the UPDATE query).

We take this bug as an opportunity to narrow the circumstances in which
at-mention notifications are marked as read. The new system:

  • When a user visits his own mention page, mark all his at-mention notifications as read
  • When a user visits the permalink page of a single activity item in which he is mentioned, mark that specific at-mention notification as read

Fixes #5384

Props SlothLoveChunk for an initial patch

Location:
branches/1.9
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.9/bp-activity/bp-activity-notifications.php

    r7622 r7832  
    337337
    338338/**
    339  * Remove activity notifications when a user clicks on them.
     339 * Mark at-mention notifications as read when users visit their Mentions page.
    340340 *
    341341 * @since BuddyPress (1.5)
     
    344344 */
    345345function bp_activity_remove_screen_notifications() {
    346     if ( bp_is_active( 'notifications' ) ) {
    347         bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
    348     }
    349 }
    350 add_action( 'bp_activity_screen_my_activity',               'bp_activity_remove_screen_notifications' );
    351 add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
    352 add_action( 'bp_activity_screen_mentions',                  'bp_activity_remove_screen_notifications' );
    353 
     346    if ( ! bp_is_active( 'notifications' ) ) {
     347        return;
     348    }
     349
     350    // Only mark read if you're looking at your own mentions
     351    if ( ! bp_is_my_profile() ) {
     352        return;
     353    }
     354
     355    bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
     356}
     357add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' );
     358
     359/**
     360 * Mark at-mention notification as read when user visits the activity with the mention.
     361 *
     362 * @since BuddyPress (2.0.0)
     363 */
     364function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) {
     365    if ( ! bp_is_active( 'notifications' ) ) {
     366        return;
     367    }
     368
     369    if ( ! is_user_logged_in() ) {
     370        return;
     371    }
     372
     373    // Mark as read any notifications for the current user related to this
     374    // activity item
     375    bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
     376}
     377add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
     378
Note: See TracChangeset for help on using the changeset viewer.