Community

Connecting WordPress People

many threads with one user

AAlfred 14 replies 0 views 3 readers

  1. New
    #1

    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

    More reactions: press the Down arrow
    views
  2. New
    Admin
    #2

    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!

    More reactions: press the Down arrow
  3. New
    #3

    Andrij,

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

    It is quite urgent 😉

    Cheers,
    Alfred

    More reactions: press the Down arrow
  4. New
    Admin
    #4

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

    More reactions: press the Down arrow
  5. New
    #5

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

    More reactions: press the Down arrow
  6. New
    Admin
    #6

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

    More reactions: press the Down arrow
  7. New
    #7

    Andrij,

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

    Cheers,
    Alfred

    More reactions: press the Down arrow
  8. New
    Admin
    #8

    Did you tried fast threads?

    More reactions: press the Down arrow
  9. New
    #9

    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

    More reactions: press the Down arrow
  10. New
    #10

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

    More reactions: press the Down arrow
  11. New
    Admin
    #11

    Hi there peoples!

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

    Thanks!

    More reactions: press the Down arrow
  12. New
    #12

    Andrij,

    That is great. When you will post it?

    Cheers,
    Alfred

    More reactions: press the Down arrow
  13. New
    Admin
    #13

    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

    More reactions: press the Down arrow
  14. New
    #14

    Hi Andrij,

    Any update?

    Cheers,
    Alfred

    More reactions: press the Down arrow
  15. New
    Admin
    #15

    Hi there!

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

    Thanks

    More reactions: press the Down arrow
0