Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/29/2014 01:00:36 AM (10 years ago)
Author:
r-a-y
Message:

Messages: Reformat new message notifications.

This commit changes the single message notification link to go
directly to the message thread in question and not the message inbox.

When the message thread is viewed, new messages are marked as read.

Fixes #5479

File:
1 edited

Legend:

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

    r8099 r8202  
    121121            $filter = 'bp_messages_multiple_new_message_notification';
    122122        } else {
    123             if ( !empty( $secondary_item_id ) ) {
    124                 $text = sprintf( __('You have %d new message from %s', 'buddypress' ), (int) $total_items, bp_core_get_user_displayname( $secondary_item_id ) );
     123            // get message thread ID
     124            $message   = new BP_Messages_Message( $item_id );
     125            $thread_id = $message->thread_id;
     126
     127            $link = bp_get_message_thread_view_link( $thread_id );
     128
     129            if ( ! empty( $secondary_item_id ) ) {
     130                $text = sprintf( __( '%2$s sent you a new private message', 'buddypress' ), bp_core_get_user_displayname( $secondary_item_id ) );
    125131            } else {
    126                 $text = sprintf( __('You have %d new message',        'buddypress' ), (int) $total_items );
     132                $text = sprintf( __( 'You have %d new private messages', 'buddypress' ), (int) $total_items );
    127133            }
    128134            $filter = 'bp_messages_single_new_message_notification';
     
    168174
    169175/**
    170  * Mark new message notifications when member views their inbox.
    171  *
    172  * @since BuddyPress (1.9.0)
    173  */
    174 function bp_messages_screen_inbox_mark_notifications() {
    175     if ( bp_is_active( 'notifications' ) ) {
    176         bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->messages->id, 'new_message' );
    177     }
    178 }
    179 add_action( 'messages_screen_inbox', 'bp_messages_screen_inbox_mark_notifications', 10 );
    180 
    181 /**
    182176 * Mark new message notification when member reads a message thread directly.
    183177 *
     
    186180function bp_messages_screen_conversation_mark_notifications() {
    187181    if ( bp_is_active( 'notifications' ) ) {
    188         bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) bp_action_variable( 0 ), buddypress()->messages->id, 'new_message' );
    189     }
    190 }
    191 add_action( 'messages_screen_conversation', 'bp_messages_screen_inbox_mark_notifications', 10 );
     182        global $thread_template;
     183
     184        // get unread PM notifications for the user
     185        $new_pm_notifications = BP_Notifications_Notification::get( array(
     186            'user_id'           => bp_loggedin_user_id(),
     187            'component_name'    => buddypress()->messages->id,
     188            'component_action'  => 'new_message',
     189            'is_new'            => 1,
     190        ) );
     191        $unread_message_ids = wp_list_pluck( $new_pm_notifications, 'item_id' );
     192
     193        // no unread PMs, so stop!
     194        if ( empty( $unread_message_ids ) ) {
     195            return;
     196        }
     197
     198        // get the unread message ids for this thread only
     199        $message_ids = array_intersect( $unread_message_ids, wp_list_pluck( $thread_template->thread->messages, 'id' ) );
     200
     201        // mark each notification for each PM message as read
     202        foreach ( $message_ids as $message_id ) {
     203            bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' );
     204        }
     205    }
     206}
     207add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notifications', 10 );
    192208
    193209/**
Note: See TracChangeset for help on using the changeset viewer.