Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/12/2015 07:42:38 PM (10 years ago)
Author:
boonebgorges
Message:

Ensure that corresponding notifications are deleted when a message thread is deleted.

This means deleting the notifications for each message in the thread, for each
recipient on the thread. Previously, only a subset of these were being deleted.

This changeset removes a test that used a dummy thread_id, a testing
technique that doesn't work with the new looping technique used for
notification deletion. The new unit test is a proper replacement.

Props pareshradadiya for an initial patch.
Fixes #6329.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-notifications.php

    r9351 r9744  
    298298 * @since BuddyPress (2.0.0)
    299299 *
    300  * @param int $message_id ID of the message.
    301  */
    302 function bp_messages_message_delete_notifications( $message_id = 0 ) {
    303     if ( bp_is_active( 'notifications' ) && ! empty( $message_id ) ) {
    304         bp_notifications_delete_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' );
    305     }
    306 }
    307 add_action( 'messages_thread_deleted_thread', 'bp_messages_message_delete_notifications', 10, 1 );
     300 * @param int   $message_id  ID of the thread.
     301 * @param array $message_ids IDs of the messages.
     302 */
     303function bp_messages_message_delete_notifications( $thread_id, $message_ids ) {
     304    if ( ! bp_is_active( 'notifications' ) ) {
     305        return;
     306    }
     307
     308    // For each recipient, delete notifications corresponding to each message.
     309    $thread = new BP_Messages_Thread( $thread_id );
     310    foreach ( $thread->get_recipients() as $recipient ) {
     311        foreach ( $message_ids as $message_id ) {
     312            bp_notifications_delete_notifications_by_item_id( $recipient->user_id, (int) $message_id, buddypress()->messages->id, 'new_message' );
     313        }
     314    }
     315}
     316add_action( 'bp_messages_thread_after_delete', 'bp_messages_message_delete_notifications', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.