/**
 * Add a notification for a specific user, from a specific component.
 *
 * @since BuddyPress (1.9.0)
 *
 * @param array $args {
 *     Array of arguments describing the notification. All are optional.
 *     @type int $user_id ID of the user to associate the notification with.
 *     @type int $item_id ID of the item to associate the notification with.
 *     @type int $secondary_item_id ID of the secondary item to associate the
 *           notification with.
 *     @type string $component_name Name of the component to associate the
 *           notification with.
 *     @type string $component_action Name of the action to associate the
 *           notification with.
 *     @type string $date_notified Timestamp for the notification.
 * }
 * @return int|bool ID of the newly created notification on success, false
 *         on failure.
 */
function bp_notifications_add_notification($args = array())
{
    $r = wp_parse_args($args, array('user_id' => 0, 'item_id' => 0, 'secondary_item_id' => 0, 'component_name' => '', 'component_action' => '', 'date_notified' => bp_core_current_time(), 'is_new' => 1, 'allow_duplicate' => false));
    // Check for existing duplicate notifications
    if (!$r['allow_duplicate']) {
        // date_notified, allow_duplicate don't count toward
        // duplicate status
        $existing = BP_Notifications_Notification::get(array('user_id' => $r['user_id'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'component_name' => $r['component_name'], 'component_action' => $r['component_action'], 'is_new' => $r['is_new']));
        if (!empty($existing)) {
            return false;
        }
    }
    // Setup the new notification
    $notification = new BP_Notifications_Notification();
    $notification->user_id = $r['user_id'];
    $notification->item_id = $r['item_id'];
    $notification->secondary_item_id = $r['secondary_item_id'];
    $notification->component_name = $r['component_name'];
    $notification->component_action = $r['component_action'];
    $notification->date_notified = $r['date_notified'];
    $notification->is_new = $r['is_new'];
    // Save the new notification
    return $notification->save();
}