Skip to:
Content

BuddyPress.org

Changeset 11310


Ignore:
Timestamp:
12/19/2016 10:51:10 PM (7 years ago)
Author:
slaffik
Message:

Messages: improvements to thread mark as read/unread.

Added new actions, so developers can now do their jobs when thread was marked as read/unread. Made wrappers like messages_mark_thread_read() meaningful by actually providing a return value.

See #5193.

Location:
trunk/src/bp-messages
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-functions.php

    r11309 r11310  
    326326 *
    327327 * @param int $thread_id ID of the thread.
     328 *
     329 * @return false|int Number of threads marked as read or false on error.
    328330 */
    329331function messages_mark_thread_read( $thread_id ) {
     
    337339 *
    338340 * @param int $thread_id ID of the thread.
     341 *
     342 * @return false|int Number of threads marked as unread or false on error.
    339343 */
    340344function messages_mark_thread_unread( $thread_id ) {
  • trunk/src/bp-messages/classes/class-bp-messages-thread.php

    r11153 r11310  
    609609     *
    610610     * @param int $thread_id The message thread ID.
     611     *
     612     * @return false|int Number of threads marked as read or false on error.
    611613     */
    612614    public static function mark_as_read( $thread_id = 0 ) {
    613615        global $wpdb;
    614616
    615         $bp  = buddypress();
    616         $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
    617         $wpdb->query( $sql );
     617        $bp     = buddypress();
     618        $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 0 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ) );
    618619
    619620        wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    620621        wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     622
     623        /**
     624         * Fires when messages thread was marked as read.
     625         *
     626         * @since 2.8.0
     627         *
     628         * @param int $thread_id The message thread ID.
     629         */
     630        do_action( 'messages_thread_mark_as_read', $thread_id );
     631
     632        return $retval;
    621633    }
    622634
     
    627639     *
    628640     * @param int $thread_id The message thread ID.
     641     *
     642     * @return false|int Number of threads marked as unread or false on error.
    629643     */
    630644    public static function mark_as_unread( $thread_id = 0 ) {
    631645        global $wpdb;
    632646
    633         $bp  = buddypress();
    634         $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id );
    635         $wpdb->query( $sql );
     647        $bp     = buddypress();
     648        $retval = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET unread_count = 1 WHERE user_id = %d AND thread_id = %d", bp_loggedin_user_id(), $thread_id ) );
    636649
    637650        wp_cache_delete( 'thread_recipients_' . $thread_id, 'bp_messages' );
    638651        wp_cache_delete( bp_loggedin_user_id(), 'bp_messages_unread_count' );
     652
     653        /**
     654         * Fires when messages thread was marked as unread.
     655         *
     656         * @since 2.8.0
     657         *
     658         * @param int $thread_id The message thread ID.
     659         */
     660        do_action( 'messages_thread_mark_as_unread', $thread_id );
     661
     662        return $retval;
    639663    }
    640664
Note: See TracChangeset for help on using the changeset viewer.