Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/21/2014 09:07:47 PM (11 years ago)
Author:
boonebgorges
Message:

Improvements to the messages thread interface.

  • Introduce noscript support for bulk actions.
  • Revise structure and markup to better match the Notifications table.
  • Add "Read/Unread" and "Delete" links for each message thread.
  • Remove unnecessary "Select Read/Unread" dropdown.
  • Introduce a number of new template functions in support of the new interface.

Props lakrisgubben.
See #6005.

File:
1 edited

Legend:

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

    r8621 r9161  
    9393
    9494/**
     95 * Handle marking a single message thread as read.
     96 *
     97 * @since BuddyPress (2.2.0)
     98 *
     99 * @return bool|null Returns false on failure. Otherwise redirects back to the
     100 *         message box URL.
     101 */
     102function bp_messages_action_mark_read() {
     103
     104    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'read', 0 ) ) {
     105        return false;
     106    }
     107
     108    $action = ! empty( $_GET['action'] ) ? $_GET['action'] : '';
     109    $nonce  = ! empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
     110    $id     = ! empty( $_GET['message_id'] ) ? intval( $_GET['message_id'] ) : '';
     111
     112    // Bail if no action or no ID.
     113    if ( 'read' !== $action || empty( $id ) || empty( $nonce ) ) {
     114        return false;
     115    }
     116
     117    // Check the nonce.
     118    if ( ! bp_verify_nonce_request( 'bp_message_thread_mark_read_' . $id ) ) {
     119        return false;
     120    }
     121
     122    // Check access to the message and mark as read.
     123    if ( messages_check_thread_access( $id ) ) {
     124        messages_mark_thread_read( $id );
     125        bp_core_add_message( __( 'Message marked as read.', 'buddypress' ) );
     126    } else {
     127        bp_core_add_message( __( 'There was a problem marking that message.', 'buddypress' ), 'error' );
     128    }
     129
     130    // Redirect back to the message box.
     131    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() );
     132}
     133add_action( 'bp_actions', 'bp_messages_action_mark_read' );
     134
     135/**
     136 * Handle marking a single message thread as unread.
     137 *
     138 * @since BuddyPress (2.2.0)
     139 *
     140 * @return bool|null Returns false on failure. Otherwise redirects back to the
     141 *         message box URL.
     142 */
     143function bp_messages_action_mark_unread() {
     144
     145    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'unread', 0 ) ) {
     146        return false;
     147    }
     148
     149    $action = ! empty( $_GET['action'] ) ? $_GET['action'] : '';
     150    $nonce  = ! empty( $_GET['_wpnonce'] ) ? $_GET['_wpnonce'] : '';
     151    $id     = ! empty( $_GET['message_id'] ) ? intval( $_GET['message_id'] ) : '';
     152
     153    // Bail if no action or no ID.
     154    if ( 'unread' !== $action || empty( $id ) || empty( $nonce ) ) {
     155        return false;
     156    }
     157
     158    // Check the nonce.
     159    if ( ! bp_verify_nonce_request( 'bp_message_thread_mark_unread_' . $id ) ) {
     160        return false;
     161    }
     162
     163    // Check access to the message and mark unread.
     164    if ( messages_check_thread_access( $id ) ) {
     165        messages_mark_thread_unread( $id );
     166        bp_core_add_message( __( 'Message marked unread.', 'buddypress' ) );
     167    } else {
     168        bp_core_add_message( __( 'There was a problem marking that message.', 'buddypress' ), 'error' );
     169    }
     170
     171    // Redirect back to the message box URL.
     172    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() );
     173}
     174add_action( 'bp_actions', 'bp_messages_action_mark_unread' );
     175
     176/**
     177 * Handle bulk management (mark as read/unread, delete) of message threads.
     178 *
     179 * @since BuddyPress (2.2.0)
     180 *
     181 * @return bool Returns false on failure. Otherwise redirects back to the
     182 *         message box URL.
     183 */
     184function bp_messages_action_bulk_manage() {
     185
     186    if ( ! bp_is_messages_component() || bp_is_current_action( 'notices' ) || ! bp_is_action_variable( 'bulk-manage', 0 ) ) {
     187        return false;
     188    }
     189
     190    $action   = ! empty( $_POST['messages_bulk_action'] ) ? $_POST['messages_bulk_action'] : '';
     191    $nonce    = ! empty( $_POST['messages_bulk_nonce'] ) ? $_POST['messages_bulk_nonce'] : '';
     192    $messages = ! empty( $_POST['message_ids'] ) ? $_POST['message_ids'] : '';
     193
     194    $messages = wp_parse_id_list( $messages );
     195
     196    // Bail if no action or no IDs.
     197    if ( ( ! in_array( $action, array( 'delete', 'read', 'unread' ) ) ) || empty( $messages ) || empty( $nonce ) ) {
     198        bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     199    }
     200
     201    // Check the nonce.
     202    if ( ! wp_verify_nonce( $nonce, 'messages_bulk_nonce' ) ) {
     203        return false;
     204    }
     205
     206    // Make sure the user has access to all notifications before managing them.
     207    foreach ( $messages as $message ) {
     208        if ( ! messages_check_thread_access( $message ) ) {
     209            bp_core_add_message( __( 'There was a problem managing your messages.', 'buddypress' ), 'error' );
     210            bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     211        }
     212    }
     213
     214    // Delete, mark as read or unread depending on the user 'action'.
     215    switch ( $action ) {
     216        case 'delete' :
     217            foreach ( $messages as $message ) {
     218                messages_delete_thread( $message );
     219            }
     220            bp_core_add_message( __( 'Messages deleted.', 'buddypress' ) );
     221        break;
     222
     223        case 'read' :
     224            foreach ( $messages as $message ) {
     225                messages_mark_thread_read( $message );
     226            }
     227            bp_core_add_message( __( 'Messages marked as read', 'buddypress' ) );
     228        break;
     229
     230        case 'unread' :
     231            foreach ( $messages as $message ) {
     232                messages_mark_thread_unread( $message );
     233            }
     234            bp_core_add_message( __( 'Messages marked as unread.', 'buddypress' ) );
     235        break;
     236    }
     237
     238    // Redirect back to message box.
     239    bp_core_redirect( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' );
     240}
     241add_action( 'bp_actions', 'bp_messages_action_bulk_manage' );
     242
     243/**
    95244 * Process a request to bulk delete messages.
    96245 *
Note: See TracChangeset for help on using the changeset viewer.