Home Forums BP Better Messages many threads with one user

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #6126
    Alfred
    Participant

    Hi,

    I am using web socket version of your plugin. I find out that I can create many threads with the same user. Is it possible to limit to have only one thread with specific user just like on messenger?

    Cheers,
    Alfred

    #6127
    Support
    Keymaster

    Hi there!

    Yes it’s possible by adding some filters and hooks.

    Or just wait and I will add this option in next version 🙂

    Thanks!

    #6128
    Alfred
    Participant

    Andrij,

    Thank you for such a quick answer. Can you provide me with those filters and hooks?

    It is quite urgent 😉

    Cheers,
    Alfred

    #6129
    Support
    Keymaster

    I haven’t the code ready at the moment. I will send when I have!

    #6130
    Alfred
    Participant

    That’s great. I really appreciate it! When would it be ready?

    #6131
    Support
    Keymaster
    add_action( 'bp_better_messages_before_new_thread', 'disable_start_thread_if_thread_exist', 10, 2 );
    
    function disable_start_thread_if_thread_exist(&$args, &$errors){
                global $wpdb;
    
                $recipients = $args['recipients'];
    
                $threadExists = array();
                foreach($recipients as $recipient){
                    $user = get_user_by('login', $recipient);
    
                    $from = get_current_user_id();
                    $to   = $user->ID;
    
                    $query = $wpdb->prepare("SELECT
                      {$wpdb->base_prefix}bp_messages_recipients.thread_id
                    FROM {$wpdb->base_prefix}bp_messages_recipients
                      INNER JOIN {$wpdb->base_prefix}bp_messages_recipients {$wpdb->base_prefix}bp_messages_recipients_1
                        ON {$wpdb->base_prefix}bp_messages_recipients.thread_id = {$wpdb->base_prefix}bp_messages_recipients_1.thread_id
                    WHERE {$wpdb->base_prefix}bp_messages_recipients.user_id = %d
                    AND {$wpdb->base_prefix}bp_messages_recipients.is_deleted = 0
                    AND {$wpdb->base_prefix}bp_messages_recipients_1.user_id = %d", $from, $to);
    
                    $threads = $wpdb->get_col($query);
    
                    if( count($threads) > 0) {
                        $threadExists[] = $recipient;
                    }
                }
    
                if(count($threadExists) > 0){
                    $message = sprintf(__('You already have threads with %s', 'bp-better-messages'), implode(', ', $threadExists));
                    $errors[] = $message;
                }
    }
    
    #6136
    Alfred
    Participant

    Andrij,

    That worked perfectly. Thanks!
    Is it possible to open this particular existing thread automatically?

    Cheers,
    Alfred

    #6137
    Support
    Keymaster

    Did you tried fast threads?

    #6140
    Alfred
    Participant

    Hi Andrij,

    After few days of using your solution I figured out that it is still possible to have many threads with one user. It can be done by using “Private message” button from profile header. After hitting this button user is redirected to new thread without ‘You already have threads with %s’ message.
    Can you help me with figuring out how to fix this?

    Cheers,
    Alfred

    #6141
    Petr
    Participant

    What is fast threads, please? I’m also looking for solution how to automatically open existing thread.

    #6142
    Support
    Keymaster

    Hi there peoples!

    I will made better solution including all your notices and place it here.

    Thanks!

    #6145
    Alfred
    Participant

    Andrij,

    That is great. When you will post it?

    Cheers,
    Alfred

    #6146
    Support
    Keymaster

    I was need to change some code in core to make this functionality.
    It will be included as option in plugin configuration in next update.
    I just need to finish some other things before release.

    ETA is 3 to 5 days I think

    • This reply was modified 6 years, 8 months ago by Support.
    #6149
    Alfred
    Participant

    Hi Andrij,

    Any update?

    Cheers,
    Alfred

    #6151
    Support
    Keymaster

    Hi there!

    Im testing new version, need some more time to publish.

    Thanks

    • This reply was modified 6 years, 8 months ago by Support.
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.