[buddypress-trac] [BuddyPress Trac] #7540: Adding a button and function for a member to leave a multi-recipients conversation

buddypress-trac noreply at wordpress.org
Thu Jun 15 11:10:01 UTC 2017


#7540: Adding a button and function for a member to leave a multi-recipients
conversation
-------------------------+-----------------------------
 Reporter:  Oelita       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Messages     |    Version:
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 I had a client request to add a button and function for members on their
 message page, when they are in a multi recipients conversation, to quit.
 They don't want to receive all the answers of this thread anymore.

 I searched and find nothing to be able to do that. If you delete the
 message, you're still part of the reciepients, and receive further
 answers.

 So I coded to do that, and wonder if this could be an enhancement feature.
 Here is my code so far :

 my theme part :

 {{{
 <?php
 function lg_get_first_message($thread_id) {
         global $wpdb;
         $bp = buddypress();
         $message_id = (int) $wpdb->get_var( "SELECT MIN(id) FROM
 {$bp->messages->table_name_messages} WHERE thread_id = $thread_id" ) ;
         return intval($message_id);
 }
 function lg_get_thread_from($thread_id) {
         $message_id = lg_get_first_message($thread_id);
         $sender_id = messages_get_message_sender($message_id);
         return intval($sender_id);
 }

 function lg_messages_action_quit_message() {
         if ( ! bp_is_messages_component() ||  !bp_is_current_action(
 'quit' ) ) {
                 return false;
         }
         $thread_id = bp_action_variable(0);
         if ( !$thread_id || !is_numeric( $thread_id ) ||
 !messages_check_thread_access( $thread_id ) ) {
                 bp_core_redirect( trailingslashit(
 bp_displayed_user_domain() . bp_get_messages_slug() . '/view' ) );
         } else {
                 global $wpdb, $bp;
                 $thread = new BP_Messages_Thread( $thread_id );
                 if ( count( $thread->recipients ) > 2 and
 lg_get_thread_from($thread_id) != bp_loggedin_user_id() ) {
                         $wpdb->query( $wpdb->prepare( "DELETE FROM
 {$bp->messages->table_name_recipients} WHERE thread_id = %d  AND user_id =
 %d", $thread_id, bp_loggedin_user_id() ) );
                         wp_cache_delete( "thread_recipients_{$thread_id}",
 'bp_messages' );
                 }
                 bp_core_redirect( trailingslashit(
 bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox' ) );
         }
 }
 add_action( 'bp_actions', 'lg_messages_action_quit_message' );

 ?>

 }}}



 template part, in \members\single\messages\single.php, after the Delete
 conversation button :
 {{{#!php
 <?php
 $thread = new BP_Messages_Thread( bp_get_the_thread_id() );
 if ( bp_get_thread_recipients_count() > 2 and bp_loggedin_user_id() !=
 lg_get_thread_from(bp_get_the_thread_id()) ) :
    ?>
    <a class="button confirm" href="<?php
    echo trailingslashit( bp_loggedin_user_domain() .
 bp_get_messages_slug() . '/quit/' . bp_get_the_thread_id() );
    ?>"><?php _e( 'Quit conversation', 'buddypress' ); ?></a>
    <?php
 endif;
 }}}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7540>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list