BuddyDev

Search

Put a limit on message notifications?

  • Participant
    Level: Initiated
    Posts: 11
    David on #7044

    Hi Brajesh,

    I require your assistance with one more issue. I use your private message rate limiter plugin and it works great. However, I am trying to design that if you have an unread message notification from one user, you will not receive anymore message notifications from that user until the notification is marked read. This is to prevent spamming. As it can be pretty annoying if you receive a message for every reply to a thread.

    This is what I have so far but it doesn’t work. What can you suggest?

    function limit_message_notifications ( $message ){
    if ( bp_is_active( ‘notifications’ ) ) {
    global $thread_template;

    // Get unread PM notifications for the user.
    $new_pm_notifications = BP_Notifications_Notification::get( array(
    ‘user_id’ => bp_loggedin_user_id(),
    ‘component_name’ => buddypress()->messages->id,
    ‘component_action’ => ‘new_message’,
    ‘secondary_item_id’ => $message->sender_id,
    ‘is_new’ => 1,
    ) );
    if (!$new_pm_notifications){

    foreach ( (array) $message->recipients as $recipient ) {
    bp_notifications_add_notification( array(
    ‘user_id’ => $recipient->user_id,
    ‘item_id’ => $message->id,
    ‘secondary_item_id’ => $message->sender_id,
    ‘component_name’ => buddypress()->messages->id,
    ‘component_action’ => ‘new_message’,
    ‘date_notified’ => bp_core_current_time(),
    ‘is_new’ => 1,
    ) );
    }
    }
    else{
    return false;
    }

    }
    }
    add_action( ‘messages_message_sent’, ‘limit_message_notifications’, 99 );

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #7067

    Hi David,
    My apologies for the delayed reply.

    Please let me know if I am understanding it correctly:-

    1. User A has sent User B a Message first time. There gets a new notification created
    2. User A sends another message(or reply) to User B. Now, if there is a previous unread message from user A, There should not be a new notification added? Is that you want?

    Also, do you want to prevent local notification or the email notification too?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    David on #7094

    Hi Brajesh. That is exactly correct. And the limit should be on both notifications and email, with a maximum of 1 of each until the message is read.

You must be logged in to reply to this topic.

This topic is: not resolved