Skip to:
Content

BuddyPress.org

Opened 3 years ago

Last modified 15 months ago

#7540 assigned enhancement

Adding a button and function for a member to leave a multi-recipients conversation

Reported by: Oelita Owned by: imath
Milestone: Awaiting Contributions Priority: normal
Severity: normal Version:
Component: Messages Keywords: ux-feedback has-patch
Cc:

Description

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
$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;

Attachments (3)

patch7540.diff (6.1 KB) - added by Oelita 3 years ago.
Patch for BuddyPress adding functions needed
patch7540bpdefault.diff (852 bytes) - added by Oelita 3 years ago.
Patch for theme bp-default for using functions added
quitconversation.jpg (32.1 KB) - added by Oelita 3 years ago.
UI in bp-default : added button (showed in orange). NB : message showing recipients is wrong, the final "and you" should be removed ? (underlined in blue)

Download all attachments as: .zip

Change History (11)

#1 @DJPaul
3 years ago

  • Milestone changed from Awaiting Review to Future Release

@boonebgorges was it you who did something around this a while ago? I think I recall a Slack conversation, but I can't remember the details.

#2 @boonebgorges
3 years ago

  • Keywords good-first-bug ux-feedback added

I don't recall doing this myself. I do recall talking with @Oelita at WCEU about this feature.

The above could probably be converted to a patch without too much trouble. It would be helpful to see screenshots of what the UI mods look like, especially with respect to Nouveau.

#3 @Oelita
3 years ago

I will try to convert it to a patch and show a screenshot , after my holidays, thanks

@Oelita
3 years ago

Patch for BuddyPress adding functions needed

@Oelita
3 years ago

Patch for theme bp-default for using functions added

@Oelita
3 years ago

UI in bp-default : added button (showed in orange). NB : message showing recipients is wrong, the final "and you" should be removed ? (underlined in blue)

#4 @Oelita
3 years ago

NB : Oups, I forgot to underline the "and you" in blue in my screenshot.

I tried to follow the structure of BP code, this is my first real code for BP, please tell me if I didn't make it in the right way.

#5 @Oelita
3 years ago

  • Keywords has-patch added

#6 @DJPaul
3 years ago

  • Milestone changed from Future Release to Under Consideration

Let's consider if we want this feature, where we are at with it based on the historic patches, and how it might integrate into Nouveau.

#7 @DJPaul
2 years ago

  • Keywords good-first-bug removed
  • Milestone changed from Under Consideration to Awaiting Contributions

Given no-one else has expressed a view, in principle, I think this is a good idea to have.

#8 @imath
15 months ago

  • Owner set to imath
  • Status changed from new to assigned

Hi,

I agree, I'm going to see how to include this into the Nouveau template pack.

Note: See TracTickets for help on using tickets.