BuddyDev

Search

[Resolved] Single message thread per user?

  • Participant
    Level: Initiated
    Posts: 11
    David on #6961

    Hi Brajesh, any plans of designing a plugin to allow only one thread per user? If not, any ideas on how I may go about designing a function myself to do this?

    I would appreciate any advice.

    Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #6969

    Hi David,
    It’s an interesting idea. I am assuming you are looking for one conversation between a pair of users.

    There are 2 things that needs to be done here

    1. Stop users from sending message to more than 1 user at a time
    2. Stop users from sending message to another message(technically, it will be easy to disable the compose screen directly and allow sending message using the profile send message link

    We are not in a position to do something like this at the moment but will be glad to assist you if you plan to develop it.

    Let me know how can we help further.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 11
    David on #6970

    So this first step is an easy thing to accomplish. This should effectively prevent users from sending messages to more than one user, as they will be forced to go to the person’s profile and message the person directly.

    function modify_user_subnav() {

    $bp = buddypress();
    bp_core_remove_subnav_item( $bp->messages->slug, ‘compose’ );
    }

    add_action( ‘bp_setup_nav’, ‘modify_user_subnav’, 100 );

    Next step would be to prevent multiple threads from creating. The server would have to check if a thread is already made, and if so, continue with that thread. Otherwise, it will create a new one but only for the user that does not have the thread.

    Any suggestions on where I may begin?

  • Participant
    Level: Initiated
    Posts: 11
    David on #6973

    Hi Brajesh,

    This is what I have so far. Can you tell me if I am on the right path?

    http://pastebin.com/nKrbmRnH

    I am having trouble figuring out how I would check to see if there are any current threads associated with the recipients, and if so, get that current thread_id

    Another problem I am having is that I use the Buddymessageux plugin, which ajaxifies the messaging so that I don’t have to go to the compose page. Problem is, I tried hooking into one of the actions (wp) of that plugin that creates the message and my code does nothing

    If I disable the plugin, and hook into the current action as showed in the pastebin link (bp-actions), this code then has an effect. Problem is, I no longer have the ajax messaging and now I need to re-enable the compose page in order to send the message.

    Do you have any thoughts on this? Thank you very much for your help. By the way, is there any way I can donate to you for your time?

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #6981

    Hi David,
    I am sorry but I am not getting the changes there.

    1. Do not remove the compose screen. Limit to to send to only one user.
    Here is an example code to find the threads between two users.

    
    
    function buddydev_get_threads_between_users( $user_id, $other_id ) {
    
    	if ( ! function_exists('bp_is_active') || ! bp_is_active( 'messages' ) ) {
    		return array();
    	}
    
    	$bp = buddypress();
    	global $wpdb;
    
    	$table_messages = $bp->messages->table_name_messages;
    	$table_recipients = $bp->messages->table_name_recipients;
    
    	$sql = $wpdb->prepare( "SELECT thread_id FROM {$table_messages} WHERE sender_id = %d", $user_id );
    
    	$sql .= $wpdb->prepare( " AND thread_id IN ( SELECT thread_id FROM {$table_recipients} WHERE user_id = %d )", $other_id );
    	
    
    	$sent_threads = $wpdb->get_col( $sql );
    
    	$sql = $wpdb->prepare( "SELECT thread_id FROM {$table_messages} WHERE sender_id = %d", $other_id );
    
    	$sql .= $wpdb->prepare( " AND thread_id IN ( SELECT thread_id FROM {$table_recipients} WHERE user_id = %d )", $user_id );
    
    	$threads_by_other_user = $wpdb->get_col( $sql );
    
    	$thread_ids = array_unique( array_merge( $sent_threads, $threads_by_other_user ) );
    
    	return $thread_ids;
    
    }
    
    

    Hope that helps.

  • Participant
    Level: Initiated
    Posts: 11
    David on #6982

    When you mean you’re not getting the changes there, you mean in regards to the bp message ajax plugin?

    I appreciate you sending that piece of code above. A few questions, I have so far though. Are the variables $user_id and $other_id already declared or do I have to declare it? Also do I then return the thread_ids into my other function to check to see if a thread exists? I am sorry but I am still relatively amateur(In my opinion) when it comes to programming.

    See my pastebin.
    http://pastebin.com/Tu5Ct75J

    Thank you as always.

  • Participant
    Level: Initiated
    Posts: 11
    David on #7013

    I was able to complete this. Thank you very much for the code you provided.

  • Keymaster
    (BuddyDev Team)
    Posts: 24712
    Brajesh Singh on #7023

    I am sorry I could not help much. Glad that you did it 🙂

You must be logged in to reply to this topic.

This topic is: resolved