Skip to:
Content

BuddyPress.org

Ticket #5289: 5289.03.diff

File 5289.03.diff, 4.2 KB (added by imath, 10 years ago)
  • bp-activity/bp-activity-notifications.php

     
    351351add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
    352352add_action( 'bp_activity_screen_mentions',                  'bp_activity_remove_screen_notifications' );
    353353
     354
     355function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) {
     356        // Let's delete all without checking if content contains any mentions
     357        // to avoid a query to get the activity
     358        if ( bp_is_active( 'notifications' ) && !empty( $activity_ids_deleted ) ) {
     359                foreach( $activity_ids_deleted as $activity_id ) {
     360                        bp_notifications_delete_all_notifications_by_type( $activity_id, buddypress()->activity->id );
     361                }
     362        }
     363}
     364add_action( 'bp_activity_deleted_activities', 'bp_activity_at_mention_delete_notification', 10, 1 );
  • bp-groups/bp-groups-notifications.php

     
    554554add_action( 'groups_delete_group', 'bp_groups_delete_group_delete_all_notifications', 10 );
    555555
    556556/**
     557 * Remove promoted notifications for any demoted member
     558 *
     559 * @since BuddyPress (?)
     560 */
     561function bp_groups_delete_group_delete_promoted_notifications( $user_id = 0, $group_id = 0 ) {
     562        if ( bp_is_active( 'notifications' ) && !empty( $group_id ) && !empty( $user_id ) ) {
     563                bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'member_promoted_to_admin' );
     564                bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'member_promoted_to_mod' );
     565        }
     566}
     567
     568add_action( 'groups_demoted_member', 'bp_groups_delete_group_delete_promoted_notifications', 10, 2 );
     569
     570/**
    557571 * Mark notifications read when a member accepts a group invitation
    558572 *
    559573 * @since BuddyPress (1.9.0)
  • bp-messages/bp-messages-classes.php

     
    121121
    122122                // Mark messages as deleted
    123123                $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, bp_loggedin_user_id() ) );
     124               
     125                // Get the massage id in order to delete notification
     126                $message_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    124127
    125128                // Check to see if any more recipients remain for this message
    126129                // if not, then delete the message from the database.
    127130                $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) );
    128131
    129132                if ( empty( $recipients ) ) {
     133                       
    130134                        // Delete all the messages
    131135                        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
    132136
    133137                        // Delete all the recipients
    134138                        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) );
     139
    135140                }
    136141
     142                do_action_ref_array( 'messages_thread_deleted_thread', array( $message_id ) );
     143
    137144                return true;
    138145        }
    139146
  • bp-messages/bp-messages-notifications.php

     
    189189        }
    190190}
    191191add_action( 'messages_screen_conversation', 'bp_messages_screen_inbox_mark_notifications', 10 );
     192
     193
     194function bp_messages_message_delete_notification( $message_id = 0 ) {
     195        if ( bp_is_active( 'notifications' ) && !empty( $message_id ) ) {
     196                bp_notifications_delete_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' );
     197        }
     198}
     199
     200add_action( 'messages_thread_deleted_thread', 'bp_messages_message_delete_notification', 10, 1 );
     201