Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/23/2021 08:07:07 PM (4 years ago)
Author:
imath
Message:

BP Messages: introduce a functionality to exit a messages thread

Exiting a messages thread is removing the user from the list of the recipients of the thread. The thread can carry on between the other recipients.

Props Oelita, vapvarun

Fixes #7540

File:
1 edited

Legend:

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

    r13108 r13196  
    800800    return $retval;
    801801}
     802
     803/**
     804 * Exit one or more message thread(s) for a given user.
     805 *
     806 * @since 10.0.0
     807 *
     808 * @param int|array $thread_ids Thread ID or array of thread IDs.
     809 * @param int       $user_id    ID of the user to delete the threads for. Defaults
     810 *                              to the current logged-in user.
     811 * @return bool True on success, false on failure.
     812 */
     813function bp_messages_exit_thread( $thread_ids, $user_id = 0 ) {
     814
     815    if ( empty( $user_id ) ) {
     816        $user_id = bp_loggedin_user_id();
     817
     818        if ( bp_displayed_user_id() ) {
     819            $user_id = bp_displayed_user_id();
     820        }
     821    }
     822
     823    /**
     824     * Fires before a user exits specified thread IDs.
     825     *
     826     * @since 10.0.0
     827     *
     828     * @param int|array $thread_ids Thread ID or array of thread IDs to be deleted.
     829     * @param int       $user_id    ID of the user the threads are being deleted for.
     830     */
     831    do_action( 'bp_messages_before_exit_thread', $thread_ids, $user_id );
     832
     833    if ( is_array( $thread_ids ) ) {
     834        $error = 0;
     835        for ( $i = 0, $count = count( $thread_ids ); $i < $count; ++$i ) {
     836            if ( ! BP_Messages_Thread::exit_thread( $thread_ids[ $i ], $user_id ) ) {
     837                $error = 1;
     838            }
     839        }
     840
     841        if ( ! empty( $error ) ) {
     842            return false;
     843        }
     844
     845        /**
     846         * Fires after a user exited the specified thread IDs.
     847         *
     848         * @since 10.0.0
     849         *
     850         * @param int|array Thread ID or array of thread IDs that were deleted.
     851         * @param int       ID of the user that the threads were deleted for.
     852         */
     853        do_action( 'bp_messages_exit_thread', $thread_ids, $user_id );
     854
     855        return true;
     856    } else {
     857        if ( ! BP_Messages_Thread::exit_thread( $thread_ids, $user_id ) ) {
     858            return false;
     859        }
     860
     861        /** This action is documented in bp-messages/bp-messages-functions.php */
     862        do_action( 'bp_messages_exit_thread', $thread_ids, $user_id );
     863
     864        return true;
     865    }
     866}
Note: See TracChangeset for help on using the changeset viewer.