Skip to:
Content

BuddyPress.org

Ticket #5259: 5259.01.patch

File 5259.01.patch, 26.4 KB (added by r-a-y, 11 years ago)
  • bp-activity/bp-activity-screens.php

    function bp_activity_screen_mentions() { 
    129129}
    130130
    131131/**
    132  * Remove activity notifications when a user clicks on them.
    133  *
    134  * @since BuddyPress (1.5)
    135  *
    136  * @uses bp_core_mark_all_notifications_by_type()
    137  */
    138 function bp_activity_remove_screen_notifications() {
    139         bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
    140 }
    141 add_action( 'bp_activity_screen_my_activity',               'bp_activity_remove_screen_notifications' );
    142 add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
    143 add_action( 'bp_activity_screen_mentions',                  'bp_activity_remove_screen_notifications' );
    144 
    145 /**
    146132 * Reset the logged-in user's new mentions data when he visits his mentions screen.
    147133 *
    148134 * @since BuddyPress (1.5)
  • bp-friends/bp-friends-cache.php

    function friends_clear_friend_object_cache( $friendship_id ) { 
    2828        wp_cache_delete( 'friends_friend_ids_' .    $friendship->friend_user_id,    'bp' );
    2929}
    3030
    31 /**
    32  * Clear friend-related notifications when ?new=1.
    33  */
    34 function friends_clear_friend_notifications() {
    35         if ( isset( $_GET['new'] ) ) {
    36                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    37         }
    38 }
    39 add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
    40 
    4131// List actions to clear object caches on
    4232add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
    4333add_action( 'friends_friendship_deleted',  'friends_clear_friend_object_cache' );
  • bp-friends/bp-friends-functions.php

    function friends_accept_friendship( $friendship_id ) { 
    118118        if ( !$friendship->is_confirmed && BP_Friends_Friendship::accept( $friendship_id ) ) {
    119119                friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
    120120
    121                 // Remove the friend request notice
    122                 bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
    123 
    124121                // Add a friend accepted notice for the initiating user
    125122                bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' );
    126123
    function friends_reject_friendship( $friendship_id ) { 
    170167
    171168        if ( !$friendship->is_confirmed && BP_Friends_Friendship::reject( $friendship_id ) ) {
    172169
    173                 // Remove the friend request notice
    174                 bp_core_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
    175 
    176170                do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) );
    177171                return true;
    178172        }
    function friends_withdraw_friendship( $initiator_userid, $friend_userid ) { 
    195189        $friendship    = new BP_Friends_Friendship( $friendship_id, true, false );
    196190
    197191        if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
    198                 // Remove the friend request notice
    199                 bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
    200 
    201192                do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
    202193                return true;
    203194        }
    function friends_remove_data( $user_id ) { 
    575566        // Remove usermeta
    576567        bp_delete_user_meta( $user_id, 'total_friend_count' );
    577568
    578         // Remove friendship requests FROM user
    579         bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );
    580 
    581569        do_action( 'friends_remove_data', $user_id );
    582570}
    583571add_action( 'wpmu_delete_user',  'friends_remove_data' );
  • bp-friends/bp-friends-screens.php

    if ( !defined( 'ABSPATH' ) ) exit; 
    1818 * Catch and process the My Friends page.
    1919 */
    2020function friends_screen_my_friends() {
    21 
    22         // Delete any friendship acceptance notifications for the user when viewing a profile
    23         bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    24 
    2521        do_action( 'friends_screen_my_friends' );
    2622
    2723        bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/home' ) );
    function friends_screen_requests() { 
    6763
    6864        do_action( 'friends_screen_requests' );
    6965
    70         if ( isset( $_GET['new'] ) ) {
    71                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
    72         }
    73 
    7466        bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
    7567}
    7668
  • bp-groups/bp-groups-functions.php

    function groups_delete_group( $group_id ) { 
    216216        // Remove all outstanding invites for this group
    217217        groups_delete_all_group_invites( $group_id );
    218218
    219         // Remove all notifications for any user belonging to this group
    220         bp_core_delete_all_notifications_by_type( $group_id, $bp->groups->id );
    221 
    222219        do_action( 'groups_delete_group', $group_id);
    223220
    224221        return true;
    function groups_accept_invite( $user_id, $group_id ) { 
    718715        // Modify group meta
    719716        groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
    720717
    721         bp_core_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
    722 
    723718        do_action( 'groups_accept_invite', $user_id, $group_id );
    724719        return true;
    725720}
    function groups_delete_invite( $user_id, $group_id ) { 
    737732
    738733        $delete = BP_Groups_Member::delete_invite( $user_id, $group_id );
    739734
    740         if ( !empty( $delete ) ) {
    741                 bp_core_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
    742         }
     735        do_action( 'groups_delete_invite', $user_id, $group_id, $delete );
    743736
    744737        return $delete;
    745738}
    function groups_remove_data_for_user( $user_id ) { 
    10781071
    10791072        BP_Groups_Member::delete_all_for_user( $user_id );
    10801073
    1081         bp_core_delete_notifications_from_user( $user_id, $bp->groups->id, 'new_membership_request' );
    1082 
    10831074        do_action( 'groups_remove_data_for_user', $user_id );
    10841075}
    10851076add_action( 'wpmu_delete_user',  'groups_remove_data_for_user' );
  • bp-groups/bp-groups-screens.php

    function groups_directory_groups_setup() { 
    2626add_action( 'bp_screens', 'groups_directory_groups_setup', 2 );
    2727
    2828function groups_screen_my_groups() {
    29 
    30         $bp = buddypress();
    31 
    32         // Delete group request notifications for the user
    33         if ( isset( $_GET['n'] ) ) {
    34                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
    35                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
    36                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
    37                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
    38         }
    39 
    4029        do_action( 'groups_screen_my_groups' );
    4130
    4231        bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) );
    function groups_screen_group_invites() { 
    9382                bp_core_redirect( $redirect_to );
    9483        }
    9584
    96         // Remove notifications
    97         bp_core_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' );
    98 
    9985        do_action( 'groups_screen_group_invites', $group_id );
    10086
    10187        bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) );
    function groups_screen_group_home() { 
    10692        if ( ! bp_is_single_item() )
    10793                return false;
    10894
    109         $bp = buddypress();
    110 
    111         if ( isset( $_GET['n'] ) ) {
    112                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
    113                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
    114                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
    115                 bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
    116         }
    117 
    11895        do_action( 'groups_screen_group_home' );
    11996
    12097        bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    function groups_screen_group_admin_requests() { 
    812789        if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) )
    813790                return false;
    814791
    815         // Remove any screen notifications
    816         bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'new_membership_request' );
    817 
    818792        $request_action = (string)bp_action_variable( 1 );
    819793        $membership_id  = (int)bp_action_variable( 2 );
    820794
  • bp-members/bp-members-notifications.php

    function bp_core_get_notifications_for_user( $user_id, $format = 'simple' ) { 
    105105        return apply_filters( 'bp_core_get_notifications_for_user', $renderable, $user_id, $format );
    106106}
    107107
    108 /** Delete ********************************************************************/
     108/** Mark ****************************************************************/
    109109
    110110/**
    111  * Delete notifications for a user by type
     111 * Mark notifications for a user by type.
     112 *
     113 * Previously, we used to delete notifications by default, but due to changes
     114 * in BuddyPress 1.9, we need to make sure notifications are marked as read
     115 * instead.
     116 *
     117 * Plugin developers new to BuddyPress should use the notification functions
     118 * located in /bp-notifications/bp-notification-functions.php instead.
    112119 *
    113  * Used when clearing out notifications for a specific component when the user
    114  * has visited that component.
     120 * @deprecated BuddyPress (1.9)
    115121 *
    116122 * @since BuddyPress (1.0)
    117123 * @param int $user_id
    function bp_core_delete_notifications_by_type( $user_id, $component_name, $compo 
    126132                return false;
    127133        }
    128134
    129         return bp_notifications_delete_notifications_by_type( $user_id, $component_name, $component_action );
     135        return bp_notifications_mark_notifications_by_type( $user_id, $component_name, $component_action );
    130136}
    131137
    132138/**
    133  * Delete notifications for an item ID
     139 * Mark notifications for an item ID
     140 *
     141 * Previously, we used to delete notifications by default, but due to changes
     142 * in BuddyPress 1.9, we need to make sure notifications are marked as read
     143 * instead.
     144 *
     145 * Plugin developers new to BuddyPress should use the notification functions
     146 * located in /bp-notifications/bp-notification-functions.php instead.
    134147 *
    135  * Used when clearing out notifications for a specific component when the user
    136  * has visited that component.
     148 * @deprecated BuddyPress (1.9)
    137149 *
    138150 * @since BuddyPress (1.0)
    139151 * @param int $user_id
    function bp_core_delete_notifications_by_item_id( $user_id, $item_id, $component 
    148160                return false;
    149161        }
    150162
    151         return bp_notifications_delete_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
     163        return bp_notifications_mark_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
    152164}
    153165
    154166/**
    155  * Delete all notifications for by type
     167 * Mark all notifications by type.
    156168 *
    157  * @since BuddyPress (1.0)
    158  * @param int $user_id
    159  * @param string $component_name
    160  * @param string $component_action
    161  * @return boolean True on success, false on fail
    162  */
    163 function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
    164 
    165         // Bail if notifications is not active
    166         if ( ! bp_is_active( 'notifications' ) ) {
    167                 return false;
    168         }
    169 
    170         bp_notifications_delete_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
    171 }
    172 
    173 /**
    174  * Delete all notifications for a user
     169 * Previously, we used to delete notifications by default, but due to changes
     170 * in BuddyPress 1.9, we need to make sure notifications are marked as read
     171 * instead.
    175172 *
    176  * Used when clearing out all notifications for a user, whene deleted or spammed
     173 * Plugin developers new to BuddyPress should use the notification functions
     174 * located in /bp-notifications/bp-notification-functions.php instead.
     175 *
     176 * @deprecated BuddyPress (1.9)
    177177 *
    178178 * @since BuddyPress (1.0)
    179179 * @param int $user_id
    function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $c 
    181181 * @param string $component_action
    182182 * @return boolean True on success, false on fail
    183183 */
    184 function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
     184function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
    185185
    186186        // Bail if notifications is not active
    187187        if ( ! bp_is_active( 'notifications' ) ) {
    188188                return false;
    189189        }
    190190
    191         return bp_notifications_delete_notifications_from_user( $user_id, $component_name, $component_action );
     191        return bp_notifications_mark_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
    192192}
    193193
    194 /** Mark **********************************************************************/
     194/** Delete ********************************************************************/
    195195
    196196/**
    197  * Delete notifications for a user by type
     197 * To delete notifications, please use the delete functions located in:
    198198 *
    199  * Used when clearing out notifications for a specific component when the user
    200  * has visited that component.
     199 *     /bp-notifications/bp-notifications-functions.php
    201200 *
    202  * @since BuddyPress (1.9.0)
    203  * @param int $user_id
    204  * @param string $component_name
    205  * @param string $component_action
    206  * @param int $is_new
    207  * @return boolean True on success, false on fail
     201 * @see bp_notifications_delete_notifications_by_type()
     202 * @see bp_notifications_delete_notifications_by_item_id()
     203 * @see bp_notifications_delete_all_notifications_by_type()
     204 * @see bp_notifications_delete_notifications_from_user()
    208205 */
    209 function bp_core_mark_notifications_by_type( $user_id, $component_name, $component_action, $is_new = false ) {
    210 
    211         // Bail if notifications is not active
    212         if ( ! bp_is_active( 'notifications' ) ) {
    213                 return false;
    214         }
    215 
    216         return bp_notifications_mark_notifications_by_type( $user_id, $component_name, $component_action, $is_new );
    217 }
    218206
    219207/**
    220  * Delete notifications for an item ID
    221  *
    222  * Used when clearing out notifications for a specific component when the user
    223  * has visited that component.
     208 * Delete all notifications for a user
    224209 *
    225  * @since BuddyPress (1.9.0)
    226  * @param int $user_id
    227  * @param string $component_name
    228  * @param string $component_action
    229  * @param int $is_new
    230  * @return boolean True on success, false on fail
    231  */
    232 function bp_core_mark_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false, $is_new = false ) {
    233 
    234         // Bail if notifications is not active
    235         if ( ! bp_is_active( 'notifications' ) ) {
    236                 return false;
    237         }
    238 
    239         return bp_notifications_mark_notifications_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id, $is_new );
    240 }
    241 
    242 /**
    243  * Mark all notifications read/unread for by type
     210 * Used when clearing out all notifications for a user, whene deleted or spammed
    244211 *
    245  * Used when clearing out notifications for an entire component
     212 * @deprecated BuddyPress (1.9)
    246213 *
    247  * @since BuddyPress (1.9.0)
     214 * @since BuddyPress (1.0)
    248215 * @param int $user_id
    249216 * @param string $component_name
    250217 * @param string $component_action
    251218 * @return boolean True on success, false on fail
    252219 */
    253 function bp_core_mark_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false, $is_new = false ) {
     220function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
    254221
    255222        // Bail if notifications is not active
    256223        if ( ! bp_is_active( 'notifications' ) ) {
    257224                return false;
    258225        }
    259226
    260         bp_notifications_mark_all_notifications_by_type( $item_id, $component_name, $component_action, $secondary_item_id, $is_new );
     227        return bp_notifications_delete_notifications_from_user( $user_id, $component_name, $component_action );
    261228}
    262229
    263 /**
    264  * Mark all notifications read/unread from a user
    265  *
    266  * @since BuddyPress (1.9.0)
    267  * @param int $user_id
    268  * @param string $component_name
    269  * @param string $component_action
    270  * @return boolean True on success, false on fail
    271  */
    272 function bp_core_mark_notifications_from_user( $user_id, $component_name, $component_action, $is_new = false ) {
    273 
    274         // Bail if notifications is not active
    275         if ( ! bp_is_active( 'notifications' ) ) {
    276                 return false;
    277         }
    278 
    279         return bp_notifications_mark_notifications_from_user( $user_id, $component_name, $component_action, $is_new );
    280 }
    281230
    282231/** Helpers *******************************************************************/
    283232
  • bp-messages/bp-messages-template.php

    function bp_has_message_threads( $args = '' ) { 
    184184        if ( bp_is_current_action( 'notices' ) && !bp_current_user_can( 'bp_moderate' ) ) {
    185185                wp_redirect( bp_displayed_user_id() );
    186186        } else {
    187                 if ( bp_is_current_action( 'inbox' ) ) {
    188                         bp_core_mark_notifications_by_type( bp_loggedin_user_id(), $bp->messages->id, 'new_message' );
    189                 }
    190187
    191188                if ( bp_is_current_action( 'sentbox' ) ) {
    192189                        $box = 'sentbox';
  • bp-notifications/bp-notifications-actions.php

    function bp_notifications_action_delete() { 
    121121        bp_core_redirect( bp_displayed_user_domain() . bp_get_notifications_slug() . '/' . bp_current_action() . '/' );
    122122}
    123123add_action( 'bp_actions', 'bp_notifications_action_delete' );
     124
     125
     126/** BP COMPONENTS *******************************************************/
     127
     128/**
     129 * Remove activity notifications when a user clicks on them.
     130 *
     131 * @since BuddyPress (1.5)
     132 *
     133 * @uses bp_notifications_mark_all_notifications_by_type()
     134 */
     135function bp_activity_remove_screen_notifications() {
     136        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' );
     137}
     138add_action( 'bp_activity_screen_my_activity',               'bp_activity_remove_screen_notifications' );
     139add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
     140add_action( 'bp_activity_screen_mentions',                  'bp_activity_remove_screen_notifications' );
     141
     142/**
     143 * Clear friend-related notifications when ?new=1.
     144 *
     145 * @since BuddyPress (1.9.0)
     146 */
     147function friends_clear_friend_notifications() {
     148        if ( isset( $_GET['new'] ) ) {
     149                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
     150        }
     151}
     152add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
     153
     154/**
     155 * Clear any friendship acceptance notifications for the user when viewing a profile.
     156 *
     157 * @since BuddyPress (1.9.0)
     158 */
     159function friends_clear_friendship_accepted_notifications() {
     160        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
     161}
     162add_action( 'friends_screen_my_friends', 'friends_clear_friendship_accepted_notifications' );
     163
     164/**
     165 * Clear any friendship request notifications for the user.
     166 *
     167 * @since BuddyPress (1.9.0)
     168 */
     169function friends_clear_friendship_request_notifications() {
     170        if ( isset( $_GET['new'] ) ) {
     171                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
     172        }
     173}
     174add_action( 'friends_screen_requests', 'friends_clear_friendship_request_notifications' );
     175
     176/**
     177 * Clear any friendship request notifications for the user when friendship is
     178 * accepted.
     179 *
     180 * @since BuddyPress (1.9.0)
     181 */
     182function friends_clear_friendship_request_notifications_on_accept( $friendship_id, $initiator_user_id, $friend_user_id ) {
     183        bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' );
     184}
     185add_action( 'friends_friendship_accepted', 'friends_clear_friendship_request_notifications_on_accept', 10, 3 );
     186
     187/**
     188 * Clear any friendship request notifications for the user when friendship is
     189 * rejected.
     190 *
     191 * @since BuddyPress (1.9.0)
     192 */
     193function friends_clear_friendship_request_notifications_on_reject( $friendship_id, $friendship ) {
     194        bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
     195}
     196add_action( 'friends_friendship_rejected', 'friends_clear_friendship_request_notifications_on_reject', 10, 2 );
     197
     198/**
     199 * Clear any friendship request notifications for the user when friendship is
     200 * rejected.
     201 *
     202 * @since BuddyPress (1.9.0)
     203 */
     204function friends_clear_friendship_request_notifications_on_withdraw( $friendship_id, $friendship ) {
     205        bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
     206}
     207add_action( 'friends_friendship_whithdrawn', 'friends_clear_friendship_request_notifications_on_withdraw', 10, 2 );
     208
     209/**
     210 * Clear any friendship request notifications by a deleted user.
     211 *
     212 * @since BuddyPress (1.9.0)
     213 */
     214function friends_remove_notifications_for_user( $user_id = 0 ) {
     215        bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' );
     216}
     217add_action( 'friends_remove_data', 'friends_remove_notifications_for_user' );
     218
     219/**
     220 * Clear any group-related notifications for the user when viewing their groups.
     221 *
     222 * @since BuddyPress (1.9.0)
     223 */
     224function groups_clear_my_groups_notifications() {
     225        $bp = buddypress();
     226
     227        // Delete group request notifications for the user
     228        if ( isset( $_GET['n'] ) ) {
     229                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
     230                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
     231                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
     232                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
     233        }
     234}
     235add_action( 'groups_screen_my_groups', 'groups_clear_my_groups_notifications' );
     236
     237/**
     238 * Clear any group invite notifications for the user when viewing their group
     239 * invites page.
     240 *
     241 * @since BuddyPress (1.9.0)
     242 */
     243function groups_clear_my_invites_notifications() {
     244        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' );
     245}
     246add_action( 'groups_screen_group_invites', 'groups_clear_invites_notifications' );
     247
     248/**
     249 * Clear single group notifications for the user when viewing a group page.
     250 *
     251 * @since BuddyPress (1.9.0)
     252 */
     253function groups_clear_single_group_notifications() {
     254        $bp = buddypress();
     255
     256        if ( isset( $_GET['n'] ) ) {
     257                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_accepted' );
     258                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'membership_request_rejected' );
     259                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_mod'      );
     260                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), $bp->groups->id, 'member_promoted_to_admin'    );
     261        }
     262}
     263add_action( 'groups_screen_group_home', 'groups_clear_single_group_notifications' );
     264
     265/**
     266 * Clear a group's membership request notifications for the group admin.
     267 *
     268 * @since BuddyPress (1.9.0)
     269 */
     270function groups_clear_request_notifications() {
     271        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'new_membership_request' );
     272}
     273add_action( 'groups_group_request_managed',       'groups_clear_request_notifications' );
     274add_action( 'groups_screen_group_admin_requests', 'groups_clear_request_notifications' );
     275
     276/**
     277 * Clear a user's group invite notifications.
     278 *
     279 * @since BuddyPress (1.9.0)
     280 */
     281function groups_clear_group_invites_notifications( $user_id = 0, $group_id = 0, $delete = true ) {
     282        bp_notifications_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
     283}
     284add_action( 'groups_accept_invite', 'groups_clear_group_invites_notifications', 10, 2 );
     285add_action( 'groups_delete_invite', 'groups_clear_group_invites_notifications', 10, 3 );
     286
     287/**
     288 * Clear all group notifications when a group is deleted.
     289 *
     290 * @since BuddyPress (1.9.0)
     291 */
     292function groups_clear_notifications_for_group( $group_id = 0 ) {
     293        bp_notifications_delete_all_notifications_by_type( $group_id, buddypress()->groups->id );
     294}
     295add_action( 'groups_delete_group', 'groups_clear_notifications_for_group' );
     296
     297/**
     298 * Clear all group notifications when a user is deleted.
     299 *
     300 * @since BuddyPress (1.9.0)
     301 */
     302function groups_clear_notifications_for_user( $user_id = 0 ) {
     303        bp_notifications_delete_notifications_from_user( $user_id, buddypress()->groups->id, 'new_membership_request' );
     304}
     305add_action( 'groups_remove_data_for_user', 'groups_clear_notifications_for_user' );
     306
     307/**
     308 * Clear notifications when user is in the PM inbox.
     309 *
     310 * @todo Perhaps fire this on 'messages_screen_inbox' instead?
     311 */
     312function messages_clear_notifications_on_inbox( $retval ) {
     313        if ( bp_is_current_action( 'inbox' ) ) {
     314                bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->messages->id, 'new_message' );
     315        }
     316
     317        return $retval;
     318}
     319add_filter( 'bp_has_message_threads', 'messages_clear_notifications_on_inbox' );
     320 No newline at end of file