Skip to:
Content

BuddyPress.org

Changeset 8099


Ignore:
Timestamp:
03/09/2014 07:46:01 PM (11 years ago)
Author:
boonebgorges
Message:

When a message is deleted, delete corresponding notifications

Fixes #5289

Props imath, henrywright

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-messages/bp-messages-classes.php

    r8053 r8099  
    213213        $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() ) );
    214214
     215        // Get the message id in order to pass to the action
     216        $message_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) );
     217
    215218        // Check to see if any more recipients remain for this message
    216219        // if not, then delete the message from the database.
     
    224227            $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) );
    225228        }
     229
     230        do_action( 'messages_thread_deleted_thread', $message_id );
    226231
    227232        return true;
  • trunk/bp-messages/bp-messages-notifications.php

    r7650 r8099  
    190190}
    191191add_action( 'messages_screen_conversation', 'bp_messages_screen_inbox_mark_notifications', 10 );
     192
     193/**
     194 * When a message is deleted, delete corresponding notifications.
     195 *
     196 * @since BuddyPress (2.0.0)
     197 *
     198 * @param int $message_id ID of the message.
     199 */
     200function bp_messages_message_delete_notifications( $message_id = 0 ) {
     201    if ( bp_is_active( 'notifications' ) && ! empty( $message_id ) ) {
     202        bp_notifications_delete_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' );
     203    }
     204}
     205add_action( 'messages_thread_deleted_thread', 'bp_messages_message_delete_notifications', 10, 1 );
Note: See TracChangeset for help on using the changeset viewer.