Ticket #8426: 8426.7.patch
File 8426.7.patch, 8.1 KB (added by , 3 years ago) |
---|
-
src/bp-messages/bp-messages-notifications.php
diff --git a/src/bp-messages/bp-messages-notifications.php b/src/bp-messages/bp-messages-notifications.php index 176a950d6..3a9e1cdd2 100644
a b add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notificat 261 261 * @since 3.0.0 262 262 * 263 263 * @param int $thread_id ID of the thread being marked as read. 264 * @param int $user_id ID of the user thread will be marked as unread. 265 * @param int $num_rows The number of affected rows by the "mark read" update query. 264 266 */ 265 function bp_messages_mark_notification_on_mark_thread( $thread_id ) { 267 function bp_messages_mark_notification_on_mark_thread( $thread_id, $user_id, $num_rows = 0 ) { 268 if ( ! $num_rows ) { 269 return; 270 } 271 266 272 $thread_messages = BP_Messages_Thread::get_messages( $thread_id ); 273 $message_ids = wp_list_pluck( $thread_messages, 'id' ); 267 274 268 foreach ( $thread_messages as $thread_message ) { 269 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $thread_message->id, buddypress()->messages->id, 'new_message' ); 270 } 275 bp_notifications_mark_notifications_by_item_ids( $user_id, $message_ids, 'messages', 'new_message', false ); 271 276 } 272 add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread' );277 add_action( 'messages_thread_mark_as_read', 'bp_messages_mark_notification_on_mark_thread', 10, 3 ); 273 278 274 279 /** 275 280 * When a message is deleted, delete corresponding notifications. -
src/bp-messages/classes/class-bp-messages-thread.php
diff --git a/src/bp-messages/classes/class-bp-messages-thread.php b/src/bp-messages/classes/class-bp-messages-thread.php index 8a2845d21..212239c84 100644
a b class BP_Messages_Thread { 763 763 bp_loggedin_user_id(); 764 764 } 765 765 766 $bp = buddypress();767 $ retval= $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) );766 $bp = buddypress(); 767 $num_rows = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); 768 768 769 769 wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' ); 770 770 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); … … class BP_Messages_Thread { 774 774 * 775 775 * @since 2.8.0 776 776 * @since 9.0.0 Added the `user_id` parameter. 777 * @since 10.0.0 Added the `$num_rows` parameter. 777 778 * 778 779 * @param int $thread_id The message thread ID. 779 780 * @param int $user_id The user the thread will be marked as read. 781 * @param bool|int $num_rows Number of threads marked as unread or false on error. 780 782 */ 781 do_action( 'messages_thread_mark_as_read', $thread_id, $user_id );783 do_action( 'messages_thread_mark_as_read', $thread_id, $user_id, $num_rows ); 782 784 783 return $ retval;785 return $num_rows; 784 786 } 785 787 786 788 /** … … class BP_Messages_Thread { 807 809 bp_loggedin_user_id(); 808 810 } 809 811 810 $bp = buddypress();811 $ retval= $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) );812 $bp = buddypress(); 813 $num_rows = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", $user_id, $thread_id ) ); 812 814 813 815 wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' ); 814 816 wp_cache_delete( $user_id, 'bp_messages_unread_count' ); … … class BP_Messages_Thread { 818 820 * 819 821 * @since 2.8.0 820 822 * @since 9.0.0 Added the `$user_id` parameter. 821 * @since 10.0.0 Added the `$ retval` parameter.823 * @since 10.0.0 Added the `$num_rows` parameter. 822 824 * 823 825 * @param int $thread_id The message thread ID. 824 826 * @param int $user_id The user the thread will be marked as unread. 825 * @param bool|int $ retval =Number of threads marked as unread or false on error.827 * @param bool|int $num_rows Number of threads marked as unread or false on error. 826 828 */ 827 do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $ retval);829 do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id, $num_rows ); 828 830 829 return $ retval;831 return $num_rows; 830 832 } 831 833 832 834 /** -
src/bp-notifications/bp-notifications-functions.php
diff --git a/src/bp-notifications/bp-notifications-functions.php b/src/bp-notifications/bp-notifications-functions.php index b33afb52b..7877a79bd 100644
a b function bp_notifications_mark_notifications_from_user( $user_id, $component_nam 580 580 ); 581 581 } 582 582 583 /** 584 * Mark notifications read/unread by item ids and user. 585 * 586 * @param int $user_id ID of the user whose notifications are being deleted. 587 * @param array $item_ids ID of the associated item. 588 * @param string $component_name Name of the associated component. 589 * @param string $component_action Name of the associated action. 590 * @param int|bool $is_new 0 for read, 1 for unread. 591 * 592 * @return int|false True on success, false on failure. 593 */ 594 function bp_notifications_mark_notifications_by_item_ids( $user_id, $item_ids, $component_name, $component_action, $is_new = false ) { 595 return BP_Notifications_Notification::update_many( 596 'item_id', 597 $item_ids, 598 array( 599 'is_new' => $is_new, 600 ), 601 array( 602 'user_id' => $user_id, 603 'component_name' => $component_name, 604 'component_action' => $component_action 605 ) 606 ); 607 } 608 583 609 /** Helpers *******************************************************************/ 584 610 585 611 /** -
src/bp-notifications/classes/class-bp-notifications-notification.php
diff --git a/src/bp-notifications/classes/class-bp-notifications-notification.php b/src/bp-notifications/classes/class-bp-notifications-notification.php index 9e2bee2f9..74bbd72c7 100644
a b class BP_Notifications_Notification { 907 907 ); 908 908 } 909 909 910 /** 911 * Update notifications. 912 * 913 * @since 10.0.0 914 * 915 * @param string $field 916 * @param array $items 917 * @param array $data Array of notification data to update, passed to 918 * {@link wpdb::update()}. Accepts any property of a 919 * BP_Notification_Notification object. 920 * @param array $where The WHERE params as passed to wpdb::update(). 921 * Typically consists of array( 'ID' => $id ) to specify the ID 922 * of the item being updated. See {@link wpdb::update()}. 923 * 924 * @return int|false The number of rows updated, or false on error. 925 */ 926 public static function update_many( $field, $items = array(), $data = array(), $where = array() ) { 927 global $wpdb; 928 $bp = buddypress(); 929 930 $supported_fields = array( 'id', 'item_id' ); 931 932 if ( false === in_array( $field, $supported_fields, true ) ) { 933 return false; 934 } 935 936 if ( ! is_array( $items ) || ! is_array( $data ) || ! is_array( $where ) ) { 937 return false; 938 } 939 940 $data = self::get_query_clauses( $data ); 941 $where = self::get_query_clauses( $where ); 942 943 $fields = array(); 944 $conditions = array(); 945 $values = array(); 946 947 $_items = implode( ',', wp_parse_id_list( $items ) ); 948 $conditions[] = " `$field` IN ($_items)"; 949 950 foreach ( $data['data'] as $field => $value ) { 951 $index = array_search( $field, array_keys( $data['data'] ) ); 952 $format = $data['format'][ $index ]; 953 954 $fields[] = "`$field`=" . $format; 955 $values[] = $value; 956 } 957 958 foreach ( $where['data'] as $field => $value ) { 959 $index = array_search( $field, array_keys( $where['data'] ) ); 960 $format = $where['format'][ $index ]; 961 962 $conditions[] = "`$field`=$format"; 963 $values[] = $value; 964 } 965 966 $fields = implode( ', ', $fields ); 967 $conditions = implode( ' AND ', $conditions ); 968 969 $sql = "UPDATE `{$bp->notifications->table_name}` SET {$fields} WHERE {$conditions}"; 970 971 return $wpdb->query( $wpdb->prepare( $sql, $values ) ); 972 } 973 910 974 /** 911 975 * Delete notifications. 912 976 *