Skip to:
Content

BuddyPress.org

Changeset 8100


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

Disable duplicate notification creation by default, and introduce 'allow_duplicate' param for override

Generally, it's undesirable to have duplicate notifications for a given
user-item-secondary_item-component-action combination (as when, say, someone
mentions you many times in a single message thread). This changeset introduces
duplicate protection, which can be overridden by passing the 'allow_duplicate'
param to bp_notifications_add_notification().

Fixes #5297

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-notifications/bp-notifications-functions.php

    r7813 r8100  
    4343        'date_notified'     => bp_core_current_time(),
    4444        'is_new'            => 1,
     45        'allow_duplicate'   => false,
    4546    ) );
     47
     48    // Check for existing duplicate notifications
     49    if ( ! $r['allow_duplicate'] ) {
     50        // date_notified, allow_duplicate don't count toward
     51        // duplicate status
     52        $existing = BP_Notifications_Notification::get( array(
     53            'user_id'           => $r['user_id'],
     54            'item_id'           => $r['item_id'],
     55            'secondary_item_id' => $r['secondary_item_id'],
     56            'component_name'    => $r['component_name'],
     57            'component_action'  => $r['component_action'],
     58            'is_new'            => $r['is_new'],
     59        ) );
     60
     61        if ( ! empty( $existing ) ) {
     62            return false;
     63        }
     64    }
    4665
    4766    // Setup the new notification
  • trunk/tests/testcases/notifications/functions.php

    r7813 r8100  
    5353        $this->assertFalse( wp_cache_get( 'all_for_user_' . $u, 'bp_notifications' ) );
    5454    }
     55
     56    /**
     57     * @group bp_notifications_add_notification
     58     */
     59    public function test_bp_notifications_add_notification_no_dupes() {
     60        $args = array(
     61            'user_id' => 5,
     62            'item_id' => 10,
     63            'secondary_item_id' => 25,
     64            'component_name' => 'messages',
     65            'component_action' => 'new_message',
     66        );
     67
     68        $n = $this->factory->notification->create( $args );
     69
     70        $this->assertFalse( bp_notifications_add_notification( $args ) );
     71    }
     72
     73    /**
     74     * @group bp_notifications_add_notification
     75     */
     76    public function test_bp_notifications_add_notification_allow_duplicate() {
     77        $args = array(
     78            'user_id' => 5,
     79            'item_id' => 10,
     80            'secondary_item_id' => 25,
     81            'component_name' => 'messages',
     82            'component_action' => 'new_message',
     83        );
     84
     85        $n = $this->factory->notification->create( $args );
     86
     87        $args['allow_duplicate'] = true;
     88
     89        $this->assertNotEmpty( bp_notifications_add_notification( $args ) );
     90    }
    5591}
Note: See TracChangeset for help on using the changeset viewer.