Skip to:
Content

BuddyPress.org

Changeset 7529


Ignore:
Timestamp:
11/08/2013 05:09:31 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Introduce bp_core_mark_all_notifications_by_type() and replace bp_core_delete_all_notifications_by_type() usages. Ensures notifications are toggled as acknowledged rather than deleted. See #5148.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-screens.php

    r7402 r7529  
    134134 * @since BuddyPress (1.5)
    135135 *
    136  * @global object $bp BuddyPress global settings
    137  * @uses bp_core_delete_notifications_by_type()
     136 * @uses bp_core_mark_all_notifications_by_type()
    138137 */
    139138function bp_activity_remove_screen_notifications() {
    140     global $bp;
    141 
    142     bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->activity->id, 'new_at_mention' );
     139    bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
    143140}
    144141add_action( 'bp_activity_screen_my_activity',               'bp_activity_remove_screen_notifications' );
  • trunk/bp-friends/bp-friends-cache.php

    r6342 r7529  
    2424
    2525function friends_clear_friend_notifications() {
    26     global $bp;
    27 
    28     if ( isset( $_GET['new'] ) )
    29         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->friends->id, 'friendship_accepted' );
     26    if ( isset( $_GET['new'] ) ) {
     27        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
     28    }
    3029}
    3130add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
  • trunk/bp-friends/bp-friends-screens.php

    r6342 r7529  
    1616
    1717function friends_screen_my_friends() {
    18     global $bp;
    1918
    2019    // Delete any friendship acceptance notifications for the user when viewing a profile
    21     bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->friends->id, 'friendship_accepted' );
     20    bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    2221
    2322    do_action( 'friends_screen_my_friends' );
     
    6362    do_action( 'friends_screen_requests' );
    6463
    65     if ( isset( $_GET['new'] ) )
    66         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), 'friends', 'friendship_request' );
     64    if ( isset( $_GET['new'] ) ) {
     65        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
     66    }
    6767
    6868    bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
  • trunk/bp-groups/bp-groups-screens.php

    r7442 r7529  
    3232    // Delete group request notifications for the user
    3333    if ( isset( $_GET['n'] ) ) {
    34         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
    35         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
    36         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
    37         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
     34        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
     35        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
     36        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
     37        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
    3838    }
    3939
     
    9595
    9696    // Remove notifications
    97     bp_core_delete_notifications_by_type( bp_loggedin_user_id(), 'groups', 'group_invite' );
     97    bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' );
    9898
    9999    do_action( 'groups_screen_group_invites', $group_id );
     
    110110
    111111    if ( isset( $_GET['n'] ) ) {
    112         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
    113         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
    114         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
    115         bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
     112        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
     113        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
     114        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
     115        bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
    116116    }
    117117
     
    814814
    815815    // Remove any screen notifications
    816     bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'new_membership_request' );
     816    bp_core_mark_all_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'new_membership_request' );
    817817
    818818    $request_action = (string)bp_action_variable( 1 );
  • trunk/bp-members/bp-members-notifications.php

    r7522 r7529  
    147147 * Delete all notifications for by type
    148148 *
     149 * @since BuddyPress (1.0)
     150 * @param int $user_id
     151 * @param string $component_name
     152 * @param string $component_action
     153 * @return boolean True on success, false on fail
     154 */
     155function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
     156
     157    // Bail if notifications is not active
     158    if ( ! bp_is_active( 'notifications' ) ) {
     159        return false;
     160    }
     161
     162    bp_notifications_delete_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
     163}
     164
     165/**
     166 * Mark all notifications read/unread for by type
     167 *
    149168 * Used when clearing out notifications for an entire component
    150169 *
    151  * @since BuddyPress (1.0)
    152  * @param int $user_id
    153  * @param string $component_name
    154  * @param string $component_action
    155  * @return boolean True on success, false on fail
    156  */
    157 function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
    158 
    159     // Bail if notifications is not active
    160     if ( ! bp_is_active( 'notifications' ) ) {
    161         return false;
    162     }
    163 
    164     bp_notifications_delete_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
     170 * @since BuddyPress (1.9)
     171 * @param int $user_id
     172 * @param string $component_name
     173 * @param string $component_action
     174 * @return boolean True on success, false on fail
     175 */
     176function bp_core_mark_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false, $is_new = false ) {
     177
     178    // Bail if notifications is not active
     179    if ( ! bp_is_active( 'notifications' ) ) {
     180        return false;
     181    }
     182
     183    bp_notifications_mark_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id, $is_new );
    165184}
    166185
  • trunk/bp-notifications/bp-notifications-functions.php

    r7528 r7529  
    300300 *
    301301 * @param int $user_id ID of the user whose notifications are being deleted.
    302  * @param int $is_new 0 for read, 1 for unread
    303  * @param string $component_name Name of the associated component.
    304  * @param string $component_action Name of the associated action.
    305  * @return bool True on success, false on failure.
    306  */
    307 function bp_notifications_mark_notifications_by_type( $user_id, $is_new, $component_name, $component_action ) {
     302 * @param string $component_name Name of the associated component.
     303 * @param string $component_action Name of the associated action.
     304 * @param int $is_new 0 for read, 1 for unread
     305 * @return bool True on success, false on failure.
     306 */
     307function bp_notifications_mark_notifications_by_type( $user_id, $component_name, $component_action, $is_new = false ) {
    308308    return BP_Notifications_Notification::delete( array(
    309309        'user_id'          => $user_id,
     
    324324 * @param int $user_id ID of the user whose notifications are being deleted.
    325325 * @param int $item_id ID of the associated item.
    326  * @param int $is_new 0 for read, 1 for unread
    327326 * @param string $component_name Name of the associated component.
    328327 * @param string $component_action Name of the associated action.
    329328 * @param int $secondary_item_id ID of the secondary associated item.
    330  * @return bool True on success, false on failure.
    331  */
    332 function bp_notifications_mark_notifications_by_item_id( $user_id, $item_id, $is_new, $component_name, $component_action, $secondary_item_id = false ) {
     329 * @param int $is_new 0 for read, 1 for unread
     330 * @return bool True on success, false on failure.
     331 */
     332function bp_notifications_mark_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false, $is_new = false ) {
    333333    return BP_Notifications_Notification::delete( array(
    334334        'user_id'           => $user_id,
     
    353353 * @param string $component_action Optional. Name of the associated action.
    354354 * @param int $secondary_item_id Optional. ID of the secondary associated item.
    355  * @return bool True on success, false on failure.
    356  */
    357 function bp_notifications_mark_all_notifications_by_type( $item_id, $is_new, $component_name, $component_action = false, $secondary_item_id = false ) {
     355 * @param int $is_new 0 for read, 1 for unread
     356 * @return bool True on success, false on failure.
     357 */
     358function bp_notifications_mark_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false, $is_new = false ) {
    358359    return BP_Notifications_Notification::delete( array(
    359360        'item_id'           => $item_id,
     
    380381 * @param string $component_name Name of the associated component.
    381382 * @param string $component_action Name of the associated action.
    382  * @return bool True on success, false on failure.
    383  */
    384 function bp_notifications_mark_notifications_from_user( $user_id, $is_new, $component_name, $component_action ) {
     383 * @param int $is_new 0 for read, 1 for unread
     384 * @return bool True on success, false on failure.
     385 */
     386function bp_notifications_mark_notifications_from_user( $user_id, $component_name, $component_action, $is_new = false ) {
    385387    return BP_Notifications_Notification::delete( array(
    386388        'item_id'          => $user_id,
Note: See TracChangeset for help on using the changeset viewer.